I want to clear a portion of a screen - How??
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > I want to clear a portion of a screen - How??




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    I want to clear a portion of a screen - How??  
Rajendran


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-02-06 12:39 PM

I just want to clear the above three lines from the current position,
so that I can start printing my results from that point. In short I
want to clear a portion of my screen.

Note: I work in the UNIX environment using gcc compiler. And I'm not a
super user.

I want a "simple solution".

I tried the combination of "\r\b" escape sequences. But \b is not
taking me back to the above line?
I urgently need the key for this.
Please help me achieving this.

I asked this question in comp.lang.c group. I got a reply to ask this
question here!
I daily visit my topic to see whether I got the answer or not!
Thank you.






[ Post a follow-up to this message ]



    Re: I want to clear a portion of a screen - How??  
comp.lang.c


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-02-06 12:39 PM

Rajendran wrote:

> I just want to clear the above three lines from the current position,
> so that I can start printing my results from that point. In short I
> want to clear a portion of my screen.
>
> Note: I work in the UNIX environment using gcc compiler. And I'm not a
> super user.
>
> I want a "simple solution".
>
> I tried the combination of "\r\b" escape sequences. But \b is not
> taking me back to the above line?
>   I urgently need the key for this.
>   Please help me achieving this.
>
> I asked this question in comp.lang.c group. I got a reply to ask this
> question here!

Indeed here is the right place to ask this question.

The cleanest and fairly simple solution is to
use the curses (ncurses on Linux) library. You
can read about it at
http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/

You might also try "console codes" but they
may be less portable. Have a look at
http://homepages.cwi.nl/~aeb/linux/...le_codes.4.html






[ Post a follow-up to this message ]



    Re: I want to clear a portion of a screen - How??  
Renato Golin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-05-06 12:26 PM

Rajendran wrote:
> I just want to clear the above three lines from the current position,
> so that I can start printing my results from that point. In short I
> want to clear a portion of my screen.
>
> Note: I work in the UNIX environment using gcc compiler. And I'm not a
> super user.
>
> I want a "simple solution".
>
> I tried the combination of "\r\b" escape sequences. But \b is not
> taking me back to the above line?
>   I urgently need the key for this.
>   Please help me achieving this.

Are you just trying to give some ENTERs to continue writing to screen or
you really wanted to erase the content of the three lines above ?

If a few ENTERs would do you might try "\n" instead of "\r\b". \r means
"return" (to the initial position on the same line), \b means
"backspace" (erase char before cursor, even if it's a line-break) and \n
means line-break.

On DOS you need the \r\n because \n only go to the next line and does
not return the cursor to position zero. On Unix it's implicit, so just a
\n would do the job.

cheers,
--renato





[ Post a follow-up to this message ]



    Re: I want to clear a portion of a screen - How??  
Stephan Schulz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-20-06 06:29 PM

In article <44FD523F.5080307@gmail.com>, Renato Golin wrote:
>Rajendran wrote: 

As others have mentioned, ncurses is the way to go for any complex
screen handling.
[vbcol=seagreen] 
>
>Are you just trying to give some ENTERs to continue writing to screen or
>you really wanted to erase the content of the three lines above ?
>
>If a few ENTERs would do you might try "\n" instead of "\r\b". \r means
>"return" (to the initial position on the same line), \b means
>"backspace" (erase char before cursor, even if it's a line-break) and \n
>means line-break.
>
>On DOS you need the \r\n because \n only go to the next line and does
>not return the cursor to position zero. On Unix it's implicit, so just a
>\n would do the job.

Assuming you use C, any conformant implementation will translate "\n"
to whatever linebreak convention is used at the system level. There
is almost never a reason to use \r in a C program.

Bye,

Stephan

--
-------------------------- It can be done! ---------------------------------
Please email me as schulz@eprover.org (Stephan Schulz)
----------------------------------------------------------------------------





[ Post a follow-up to this message ]



    Re: I want to clear a portion of a screen - How??  
Keith Thompson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Re: I want to clear a portion of a screen - How??  
Michael Wojcik


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-06 12:28 AM


In article <lnirji5hrr.fsf@nuthaus.mib.org>, Keith Thompson <kst-u@mib.org> writes:
>
> 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.

The tput command writes terminal control sequences to stdout and
is standardized (by SUSv3), though only three commands (clear,
init, and reset) are standard.  But typical implementations support
writing many or all of the terminfo (or in some cases termcap)
sequences.

For example, to erase the first two lines of the screen, something
like:

tput sc; tput home; tput el; tput cud1; tput el; tput rc

would probably work for a fair number of implementation / terminal
type combinations.  ("man terminfo" should have the capability
names.)

--
Michael Wojcik                  michael.wojcik@microfocus.com

Poe said that poetry was exact.
But pleasures are mechanical
and know beforehand what they want
and know exactly what they want.        -- Elizabeth Bishop





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:18 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register