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 Maclean
MSc (DIC)
07739 171 531

John Maclean 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 Maclean
MSc (DIC)
07739 171 531

Control-L

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

  puts "\e[2J"

···

On Wed, 04 Jan 2006 06:49:14 -0000, John Maclean <info@jayeola.org> 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-?

--
Ross Bamford - rosco@roscopeco.remove.co.uk

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 Litt

slitt@troubleshooters.com

···

On Wednesday 04 January 2006 01:49 am, John Maclean 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 Maclean <info@jayeola.org> 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 Maclean
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.

require 'curses'

Curses.init_screen
Curses.clear

···

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

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

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

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 "Gene Tani" <gene.tani@gmail.com> wrote:

John Maclean 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 Maclean
> MSc (DIC)
> 07739 171 531

Control-L

--
John Maclean
MSc (DIC)
07739 171 531

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

···

On Wed, 04 Jan 2006 10:01:56 -0000, Ross Bamford <rosco@roscopeco.remove.co.uk> wrote:

On Wed, 04 Jan 2006 06:49:14 -0000, John Maclean <info@jayeola.org> > 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"

--
Ross Bamford - rosco@roscopeco.remove.co.uk

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 Wednesday 04 January 2006 04:07 am, John Maclean wrote:

On Wed, 4 Jan 2006 17:07:58 +0900 > > "Gene Tani" <gene.tani@gmail.com> wrote:
> John Maclean 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 Maclean
> > MSc (DIC)
> > 07739 171 531
>
> Control-L

--
Steve Litt
http://www.troubleshooters.com
slitt@troubleshooters.com

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

SteveT

Steve Litt

slitt@troubleshooters.com

···

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

On Wednesday 04 January 2006 04:07 am, John Maclean wrote:
> I should've made myself clearer. Is there a way to do this via a ruby
> command?

print 12.to_s

12.chr ?

James Edward Gray II

···

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

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

On Wednesday 04 January 2006 04:07 am, John Maclean 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().

Steve Litt 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"

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 Wed, 04 Jan 2006 15:00:45 -0000, Steve Litt <slitt@earthlink.net> wrote:

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

On Wednesday 04 January 2006 04:07 am, John Maclean 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().

--
Ross Bamford - rosco@roscopeco.remove.co.uk

Correct on all accounts. :slight_smile:

James Edward Gray II

···

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

On Wed, 04 Jan 2006 15:00:45 -0000, Steve Litt > <slitt@earthlink.net> wrote:

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

On Wednesday 04 January 2006 04:07 am, John Maclean 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().

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?

Wow, can't believe I remembered that... Now if only I could retain the _useful_ stuff :smiley:

···

On Wed, 04 Jan 2006 17:51:22 -0000, James Edward Gray II <james@grayproductions.net> wrote:

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

On Wed, 04 Jan 2006 15:00:45 -0000, Steve Litt <slitt@earthlink.net> >> wrote:

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

On Wednesday 04 January 2006 04:07 am, John Maclean 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().

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:

--
Ross Bamford - rosco@roscopeco.remove.co.uk