tags:

views:

264

answers:

3

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,

  1. Don't do that.
  2. 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.
  3. It would probably be better to use the system "clear" command in Unix or "cls" in Windows.
  4. Don't do that.
kwatford
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
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
Why "don't do that"?
Chuck
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
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
+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
IM ASKING IN HASKELL.
Nubkadiya
@Pradeep: Yes, and I answered in haskell.
sepp2k
@Pradeep: No need to shout. (See http://en.wikipedia.org/wiki/All_caps#Internet )
Jared Updike
* *Wishes there was a way to downvote comments* :)
Fry
+7  A: 
ZachS