How do I clear the terminal screen in Haskell?
HaskellTerminalGhciHaskell Problem Overview
How can I clear a terminal screen after my user has selected an option from my application's menu?
Haskell Solutions
Solution 1 - Haskell
:!
:! cls under windows
:! clear under linux and OS X
Solution 2 - Haskell
This is what you may be looking for:
http://hackage.haskell.org/packages/archive/ansi-terminal/0.5.0/doc/html/System-Console-ANSI.html">ansi-terminal:</a></b> 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
Solution 3 - Haskell
Just press Ctrl+L (works on Windows)
Solution 4 - Haskell
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.
Solution 5 - Haskell
On Windows, use Ctrl + L for Haskell command prompt terminal. And, for GUI use Ctrl + S.
Solution 6 - Haskell
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.
Solution 7 - Haskell
A quick way on Windows would be to
import System.Process
clear :: IO ()
clear = system "cls"
Solution 8 - Haskell
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 ()