How do I clear the terminal screen in Haskell?

空扰寡人 提交于 2019-12-18 10:15:01

问题


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 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




回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!