How do I clear the terminal screen in Haskell?

2019-01-30 17:05发布

How can I clear a terminal screen after my user has selected an option from my application's menu?

8条回答
相关推荐>>
2楼-- · 2019-01-30 17:48

Just press Ctrl+L (works on Windows)

查看更多
一夜七次
3楼-- · 2019-01-30 17:50

On Windows, use Ctrl + L for Haskell command prompt terminal. And, for GUI use Ctrl + S.

查看更多
乱世女痞
4楼-- · 2019-01-30 17:56

A quick way on Windows would be to

import System.Process

clear :: IO ()
clear = system "cls"
查看更多
该账号已被封号
5楼-- · 2019-01-30 17:57

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.

查看更多
老娘就宠你
6楼-- · 2019-01-30 18:02

:! run the shell command
:! cls under windows
:! clear under linux and OS X

查看更多
做自己的国王
7楼-- · 2019-01-30 18:03

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

查看更多
登录 后发表回答