How can I clear a terminal screen after my user has selected an option from my application's menu?
+2
A:
Assuming you meant a terminal and not some sort of window,
- Don't do that.
- If you have to do that, the easy way is to just print enough newlines to guarantee that the old text has scrolled off the top.
- It would probably be better to use the system "clear" command in Unix or "cls" in Windows.
- Don't do that.
kwatford
2010-03-18 18:34:23
2. How would he know how many newlines to print? Haskell doesn't have a built-in function to find out the height of the terminal, does it?
sepp2k
2010-03-18 18:39:23
It might not, but he could just print a predetermined amount that will work on most terminals. Plus, there are commandline libraries he can get from Hackage.
ZachS
2010-03-18 18:44:38
Why "don't do that"?
Chuck
2010-03-18 20:21:54
It's annoying when terminal apps clear the screen without a very good reason, though there are some reasonable times to do so. It's somewhat similar to making a windowed app steal focus from the current app. Sometimes useful, but usually just annoying.
kwatford
2010-03-18 21:27:52
Indeed. If I want a clear screen before your app runs, I will just type `clear`!Similarly, if I want your window to be focused, I will focus it. Amazing.
jrockway
2010-03-19 01:18:04
+1
A:
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.
sepp2k
2010-03-18 18:35:36
@Pradeep: No need to shout. (See http://en.wikipedia.org/wiki/All_caps#Internet )
Jared Updike
2010-03-18 18:57:17