如何清除 Haskell 中的终端屏幕?
用户从应用程序菜单中选择选项后,如何清除终端屏幕?
How can I clear a terminal screen after my user has selected an option from my application's menu?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
:! 运行 shell 命令
<强>:! windows下的cls
<强>:! Linux 和 OS X 下清晰
:! run the shell command
:! cls under windows
:! clear under linux and OS X
这就是您可能正在寻找的内容:
ansi-terminal: 简单的 ANSI 终端支持,与 Windows 兼容
You can find it in Hackage and install using
cabal install ansi-terminal
. It specifically has functions for clearing the screen, displaying colors, moving the cursor, etc.使用它来清除屏幕很容易:(这是使用 GHCI)
import System.Console。 ANSI
clearScreen
This is what you may be looking for:
ansi-terminal: Simple ANSI terminal support, with Windows compatibility
You can find it in Hackage and install using
cabal install ansi-terminal
. It specifically has functions for clearing the screen, displaying colors, moving the cursor, etc.Using it to clear the screen is easy: (this is with GHCI)
import System.Console.ANSI
clearScreen
只需按 Ctrl+L(适用于 Windows)
Just press Ctrl+L (works on Windows)
在理解 ANSI 转义序列(我相信 Unix/Linux 系统中的每个术语)的终端上,您可以简单地执行以下操作:
2
清除整个屏幕。如果要清除从光标到屏幕末尾或从光标到屏幕开头,可以分别使用0
或1
。但我认为这在 Windows shell 中不起作用。
On a terminal that understands ANSI escape sequences (I believe every term in Unix/Linux systems) you can do it simply with:
The
2
clears the entire screen. You can use0
or1
respectively if you want to clear from the cursor to end of screen or from cursor to the beginning of the screen.However I don't think this works in the Windows shell.
在 Windows 上,使用 Ctrl + L 作为 Haskell 命令提示符终端。并且,对于 GUI,请使用 Ctrl + S。
On Windows, use Ctrl + L for Haskell command prompt terminal. And, for GUI use Ctrl + S.
在 Unix 系统上,您可以执行 System.system "clear" ,它只会调用命令行实用程序clear。对于不依赖于外部工具的解决方案,您需要一个抽象不同终端类型的库,例如 ansi 终端。
On Unix systems you can do
System.system "clear"
which just invokes the command-line utility clear. For a solution that does not depend on external tools, you'd need a library that abstracts over different terminal-types like for example ansi-terminal.Windows 上的一种快速方法是
A quick way on Windows would be to
在 Linux 下(至少 Ubuntu),这是我用来清除终端的代码:
Under Linux (Ubuntu at least), that's the code I use for clearing the terminal: