[comp.unix.questions] clearing the terminal screen

lynch@batcomputer.tn.cornell.edu (Tim Lynch) (12/15/88)

I'm having a problem setting an environmental variable to speed up
screen clearing. If I'm working from a hp terminal the following works:

  % setenv CLEAR `clear`
  % echo $CLEAR            # (and the screen is cleared)

But, if I'm working from a vt100, issuing echo $CLEAR does nothing.
Furthermore, echo $CLEAR | wc shows that CLEAR is of length zero.
The terminfo for the vt100 appears ok because I can issue:

  % clear

and the vt100 screen clears!  Actually, I don't have to change terminals;
if I have TERM set to hp, then CLEAR is set to the correct escape sequence
to clear the screen, whereas if TERM is set to vt100, CLEAR is not set
to anything.  I've tried this on two different Unix machines.

Anybody have a clue as to why I can't set CLEAR when TERM is equal to
vt100?

schaefer@ogccse.ogc.edu (Barton E. Schaefer) (12/16/88)

In article <7007@batcomputer.tn.cornell.edu> lynch@batcomputer.tn.cornell.edu
(Tim Lynch) writes:
} 
} I'm having a problem setting an environmental variable to speed up
} screen clearing. If I'm working from a hp terminal the following works:
} 
}   % setenv CLEAR `clear`
}   % echo $CLEAR            # (and the screen is cleared)
} 
} But, if I'm working from a vt100, issuing echo $CLEAR does nothing.

Just a suspicion, but I bet the vt100 is slow enough that the TERMCAP
entry claims it needs padding (extra ascii NUL chars) in the escape
sequences.  "setenv CLEAR `clear`" inserts a NUL into $CLEAR.  But guess
what NUL is?  Yep, the string terminator.  So $CLEAR gets truncated.

Try using

    setenv CLEAR `clear | tr -d '\0'`

I'm not positive that will work, but it has a fighting chance. :-)

You might also try

    setenv CLEAR "`clear`"

I have discovered that for certain termcap entries, some collision
between the csh backquote mechanism and the termcap library causes
pieces of the termcap to be lost.  I have no idea why this happens.
Anybody out there have a clue?

-- 
Bart Schaefer		"You've heard of Load/Store architectures?  Well, the
			 80286 is a L-l-l-load/S-s-s-store architecture."
CSNET   (Has not changed)	schaefer@cse.ogc.edu
UUCP    (Should work now)	...{sun,tektronix,verdix}!ogccse!schaefer

maart@cs.vu.nl (Maarten Litmaath) (12/16/88)

lynch@batcomputer.tn.cornell.edu (Tim Lynch) writes:


\I'm having a problem setting an environmental variable to speed up
\screen clearing. If I'm working from a hp terminal the following works:

\  % setenv CLEAR `clear`
\  % echo $CLEAR            # (and the screen is cleared)

\But, if I'm working from a vt100, issuing echo $CLEAR does nothing.
\Furthermore, echo $CLEAR | wc shows that CLEAR is of length zero.
\The terminfo for the vt100 appears ok because I can issue:

\  % clear

The escape code clearing a VT100 screen, contains some magic characters:

	^[[;H^[[2J	(^[ = escape)

The magic characters are `[', `;' and another `['. The `[' character is used
to match filenames, like:

	% echo *.[ch]	# echo all C source + include files

The escape code above doesn't contain a corresponding ']', so csh should have
said:
	Missing ].

(Of course if csh's syntax/parser were right, it wouldn't have parsed the
output of the backquote command at all.)
It's a bug indeed; there's no standard output, because the backquote command
ultimately fails, and csh simply forgets to issue an error message (on stderr).
Solution:

	% setenv	CLEAR	"`clear`"
	% echo "$CLEAR"		# you'll want to put this in an alias
-- 
fcntl(fd, F_SETFL, FNDELAY):          |Maarten Litmaath @ VU Amsterdam:
      let's go weepin' in the corner! |maart@cs.vu.nl, mcvax!botter!maart

leo@philmds.UUCP (Leo de Wit) (12/16/88)

In article <7007@batcomputer.tn.cornell.edu> lynch@batcomputer.tn.cornell.edu (Tim Lynch) writes:
|
|I'm having a problem setting an environmental variable to speed up
|screen clearing. If I'm working from a hp terminal the following works:
|
|  % setenv CLEAR `clear`
|  % echo $CLEAR            # (and the screen is cleared)
|
|But, if I'm working from a vt100, issuing echo $CLEAR does nothing.
Neither does it in my environment; CLEAR appears to be an empty string.
This has possibly something to do with the special treatment of the
escape character (which is part of the sequence output by clear) by the
Cshell; the following worked fine in the Bourne shell:

$ CLEAR=`clear`
$ echo $CLEAR

|Furthermore, echo $CLEAR | wc shows that CLEAR is of length zero.
|The terminfo for the vt100 appears ok because I can issue:
|
|  % clear
|
|and the vt100 screen clears!  Actually, I don't have to change terminals;
|if I have TERM set to hp, then CLEAR is set to the correct escape sequence
|to clear the screen, whereas if TERM is set to vt100, CLEAR is not set
|to anything.  I've tried this on two different Unix machines.
|
|Anybody have a clue as to why I can't set CLEAR when TERM is equal to
|vt100?

The following works in the Cshell:

% set CLEAR="`clear`"
% alias cls 'echo "$CLEAR"'

and now you can do

% cls

to clear your terminal screen (only from the inside 8-).  The double
quotes prevent the Cshell from interpreting characters within the
string. Hope this clears things a bit 8-).

          Leo.

merlyn@intelob.biin.com (Randal L. Schwartz @ Stonehenge) (12/22/88)

In article <1908@ogccse.ogc.edu>, schaefer@ogccse (Barton E. Schaefer) writes:
| Try using
| 
|     setenv CLEAR `clear | tr -d '\0'`
| 
| I'm not positive that will work, but it has a fighting chance. :-)

It's simpler than that: tr(1) deletes ALL nulls, regardless of your
command line arguments.  So, to use this undocumented feature:

    setenv CLEAR "`clear | tr`"

Simple, eh?

Disclaimer: I've given up my csh(1) guru card about six months ago
(about the same time I gave up my vi(1) guru card and went to GNU
Emacs).  'setenv' syntax should thus be checked carefully; use at your
own risk. :-) (However, the trick about tr should allow me to renew my
UN*X Guru Card, eh guys?)
-- 
Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095
on contract to BiiN Technical Information Services (for now :-),
in a former Intel building in Hillsboro, Oregon, USA.
<merlyn@intelob.biin.com> or ...!tektronix!inteloa[!intelob]!merlyn
SOME MAILERS REQUIRE <merlyn@intelob.intel.com> GRRRRR!
Standard disclaimer: I *am* my employer!