问题
How can I clear a terminal screen after my user has selected an option from my application's menu?
回答1:
:! run the shell command
:! cls under windows
:! clear under linux and OS X
回答2:
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 usingcabal 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
回答3:
On a terminal that understands ANSI escape sequences (I believe every term in Unix/Linux systems) you can do it simply with:
clear = putStr "\ESC[2J"
The 2
clears the entire screen. You can use 0
or 1
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.
回答4:
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.
回答5:
Just press Ctrl+L (works on Windows)
回答6:
A quick way on Windows would be to
import System.Process
clear :: IO ()
clear = system "cls"
回答7:
On Windows, use Ctrl + L for Haskell command prompt terminal. And, for GUI use Ctrl + S.
回答8:
Under Linux (Ubuntu at least), that's the code I use for clearing the terminal:
import qualified System.Process as SP
clearScreen :: IO ()
clearScreen = do
_ <- SP.system "reset"
return ()
来源:https://stackoverflow.com/questions/2472391/how-do-i-clear-the-terminal-screen-in-haskell