09-21-06 12:52 AM
schulz@sunbroy2.informatik.tu-muenchen.de (Stephan Schulz) writes:
> In article <44FD523F.5080307@gmail.com>, Renato Golin wrote:
>
> As others have mentioned, ncurses is the way to go for any complex
> screen handling.
[...]
Yes, but clearing three lines isn't necessarily what I'd call complex.
The problem with ncurses is that it takes control of the entire screen
-- and, where possible, it preserves the prevous contents of the
screen and restores them when it's finished. That's great for a
full-screen text editor, but it's not necessarily a good thing if you
want to erase some information.
For example, if I happen to accidentally display sensitive information
on my screen (say, a password), I'd like to erase just a few lines
without affecting the entire screen. I have a PERL script called
"erase" that I use for this. It assumes a VT100-compatible terminal
or emulator, which happens to be good enough for my purposes, but it's
not a universal solution.
Here's the script (it would be easy to implement in another language
such as C or /bin/sh). If you don't know Perl, "\r" is CR (ASCII 13)
and \e is escape (ASCII 27).
========================================
================================
#!/usr/bin/perl -w
sub Usage(@);
my $lines;
if (scalar @ARGV == 0) {
$lines = 10;
}
elsif (scalar @ARGV == 1) {
$lines = $ARGV[0];
Usage if $lines !~ /^\d+$/;
}
else {
Usage;
}
$| = 1;
print "\r\e[${lines}A\e[J";
sub Usage(@) {
print @_ if @_;
print "Usage: $0 n\n";
print "Clears n lines (default 10)\n";
exit 1;
} # Usage
========================================
================================
For a more general solution that would work on non-VT100-compatible
terminals, you'd want to use termcap or terminfo.
tcsh has a builtin command "echotc" that prints specified termcap
sequences.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
[ Post a follow-up to this message ]
|