Is there a way to clear the contents of a terminal?

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

John M. wrote:

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


John M.
MSc (DIC)
07739 171 531

Control-L

I should’ve made myself clearer. Is there a way to do this via a ruby
command?

On Wed, 4 Jan 2006 17:07:58 +0900

On Wed, 04 Jan 2006 06:49:14 -0000, John M. [email protected]
wrote:

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

Safe, sure, reliable, probably not. But on most ‘modern’ systems I guess
this should work:

puts "\e[2J"

On Wed, 04 Jan 2006 10:01:56 -0000, Ross B.
[email protected] wrote:

this should work:

puts “\e[2J”

or “\e[2J\e[0;0H” to home the cursor too.

On Wednesday 04 January 2006 01:49 am, John M. wrote:

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

In the UMENU program, I do this:

puts “\n” * 24

Crude, but effective, and has the advantage of being totally portable –
even
on an ancient teletype terminal. If you use different terminal
resolutions,
then it would be

print “\n” * lines_per_screen

SteveT

Steve L.

[email protected]

On Wednesday 04 January 2006 09:10 am, Steve L. wrote:

On Wednesday 04 January 2006 04:07 am, John M. wrote:

I should’ve made myself clearer. Is there a way to do this via a ruby
command?

print 12.to_s

Dooohhhhh. This would have printed “12”. What I needed some sort of
equivalent
of Pascal chr().

SteveT

Steve L.

[email protected]

On Wednesday 04 January 2006 04:07 am, John M. wrote:

I should’ve made myself clearer. Is there a way to do this via a ruby
command?

print 12.to_s

I still like 25 newlines better.

SteveT

On Jan 4, 2006, at 9:00 AM, Steve L. wrote:

of Pascal chr().
12.chr ?

James Edward G. II

Steve L. wrote:

Dooohhhhh. This would have printed “12”. What I needed some sort of equivalent
of Pascal chr().

Something like this?

rb$ ri Integer.chr
------------------------------------------------------------ Integer#chr
int.chr => string

  Returns a string containing the ASCII character represented by the
  receiver's value.

     65.chr    #=> "A"
     ?a.chr    #=> "a"
     230.chr   #=> "\346"

On Wed, 04 Jan 2006 15:00:45 -0000, Steve L. [email protected]
wrote:

IIRC ASCII 0x0C is form-feed, right. Doesn’t Ruby support “\f”? (seems
to).
But I don’t think it’ll clear the terminal, will it?

On Jan 4, 2006, at 11:47 AM, Ross B. wrote:

Dooohhhhh. This would have printed “12”. What I needed some sort
of equivalent
of Pascal chr().

IIRC ASCII 0x0C is form-feed, right. Doesn’t Ruby support “\f”?
(seems to).
But I don’t think it’ll clear the terminal, will it?

Correct on all accounts. :slight_smile:

James Edward G. II

On Wed, 04 Jan 2006 17:51:22 -0000, James Edward G. II
[email protected] wrote:

Correct on all accounts. :slight_smile:

Wow, can’t believe I remembered that… Now if only I could retain the
useful stuff :smiley:

John M. [email protected] writes:

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


John M.
MSc (DIC)
07739 171 531


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.

On Jan 3, 2006, at 10:49 PM, John M. wrote:

MATLAB uses cls, in a bash shell I’d use clear. Is there a way to
clear the contents of a terminal -safely-?

require ‘curses’

Curses.init_screen
Curses.clear


Eric H. - [email protected] - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com