John Maclean said:
Hi Chaps,
MATLAB uses cls, in a bash shell I'd use clear. Is there a way to clear the contents of a terminal -safely-?
--------------------------------------------------------------------------------
CLEAR_TERMINAL_CMD = `/usr/bin/clear`
def clear_screen
print CLEAR_TERMINAL_CMD
end
clear_screen
--------------------------------------------------------------------------------
The above is the simplest, most portable solution. Sadly, most
portable here extends only to within unix system. There is no single
solution that works with both win32 and unix.
Other solutions (for unix):
1. Print \n a number of times. You can't tell how many \n you need to
print. Some environments gives you the LINES env. variable, but not
all.
2. Hard code some terminal escape sequence. Definitely not portable
between different terminal types. /usr/bin/clear uses curses which
in turn consults the terminfo database for the correct escape
sequence on the current terminal.
3. Link to curses itself. Not simple.
4. Consult terminfo database yourself. Location is not standard and
most probably not as simple as the /usr/bin/clear solution.
YS.