linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* clear the screen
@ 2005-02-21  7:08 kaushal
  2005-02-21  7:59 ` J.
  2005-02-23  0:16 ` Glynn Clements
  0 siblings, 2 replies; 9+ messages in thread
From: kaushal @ 2005-02-21  7:08 UTC (permalink / raw)
  To: linux-c

hello all,
	Sorry for a very basic question.I would like to know how to clear the
screen from within a c program without using system("clear") or any of
the ncurses functions.Can we do this using printf?My program is in raw
mode so is there any feature available by which I can use the termios
structure for clearing the screen if it is not possible with printf.Long
ago when I used work in the dos platform I used conio.h and clrscr()
rourine.I guess I have to write that clrscr() routine's code itself.Im
working on a linux machine now.

Thanks in advance.
-kaushal.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: clear the screen
  2005-02-21  7:08 clear the screen kaushal
@ 2005-02-21  7:59 ` J.
  2005-02-21  9:56   ` Vinodkumar Nair
  2005-02-23  0:16 ` Glynn Clements
  1 sibling, 1 reply; 9+ messages in thread
From: J. @ 2005-02-21  7:59 UTC (permalink / raw)
  To: linux-c

On Mon, 21 Feb 2005, kaushal wrote:

> hello all,
> 	Sorry for a very basic question.I would like to know how to clear the
> screen from within a c program without using system("clear") or any of
> the ncurses functions.Can we do this using printf?My program is in raw
> mode so is there any feature available by which I can use the termios
> structure for clearing the screen if it is not possible with printf.Long
> ago when I used work in the dos platform I used conio.h and clrscr()
> rourine.I guess I have to write that clrscr() routine's code itself.Im
> working on a linux machine now.
> 
> Thanks in advance.
> -kaushal.

Don't know if this is of any help to you:
 
#include <stdio.h>

int main(void) {

 printf("\e[0m\e[2J\e[1;1H");

 return 0;
}

When the compiler is called with some warning flags it might complain
about a non-standard escape sequence, but it compiles fine and it works.
 
Goodluck & Regards,

J.

--
http://www.rdrs.net


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: clear the screen
  2005-02-21  7:59 ` J.
@ 2005-02-21  9:56   ` Vinodkumar Nair
  2005-02-21 10:12     ` YYW
  0 siblings, 1 reply; 9+ messages in thread
From: Vinodkumar Nair @ 2005-02-21  9:56 UTC (permalink / raw)
  To: linux-c

>> printf("\e[0m\e[2J\e[1;1H");

How does this printf work to clear the screen?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: clear the screen
  2005-02-21  9:56   ` Vinodkumar Nair
@ 2005-02-21 10:12     ` YYW
  2005-02-21 13:50       ` Darren Sessions
  0 siblings, 1 reply; 9+ messages in thread
From: YYW @ 2005-02-21 10:12 UTC (permalink / raw)
  To: linux-c-programming

On Mon, 21 Feb 2005 15:26:51 +0530
"Vinodkumar Nair" <vinodkumar.nair@patni.com> wrote:

> >> printf("\e[0m\e[2J\e[1;1H");
> 
> How does this printf work to clear the screen?
It's ascii control character. 2J means clear the screen and
1;1H set the cursor position.

> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


-- 

Best regards,
yyw@smth


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: clear the screen
  2005-02-21 10:12     ` YYW
@ 2005-02-21 13:50       ` Darren Sessions
  2005-02-21 14:15         ` Ron Michael Khu
  0 siblings, 1 reply; 9+ messages in thread
From: Darren Sessions @ 2005-02-21 13:50 UTC (permalink / raw)
  To: linux-c-programming


system("clear");

On 2/21/05 5:12 AM, "YYW" <wu_jian@263.net> wrote:

> On Mon, 21 Feb 2005 15:26:51 +0530
> "Vinodkumar Nair" <vinodkumar.nair@patni.com> wrote:
> 
>>>> printf("\e[0m\e[2J\e[1;1H");
>> 
>> How does this printf work to clear the screen?
> It's ascii control character. 2J means clear the screen and
> 1;1H set the cursor position.
> 
>> 
>> -
>> To unsubscribe from this list: send the line "unsubscribe
>> linux-c-programming" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: clear the screen
  2005-02-21 13:50       ` Darren Sessions
@ 2005-02-21 14:15         ` Ron Michael Khu
  0 siblings, 0 replies; 9+ messages in thread
From: Ron Michael Khu @ 2005-02-21 14:15 UTC (permalink / raw)
  To: Darren Sessions; +Cc: linux-c-programming

=)
u misunderstood the original post/question by kaushal

Darren Sessions wrote:

>system("clear");
>
>On 2/21/05 5:12 AM, "YYW" <wu_jian@263.net> wrote:
>
>  
>
>>On Mon, 21 Feb 2005 15:26:51 +0530
>>"Vinodkumar Nair" <vinodkumar.nair@patni.com> wrote:
>>
>>    
>>
>>>>>printf("\e[0m\e[2J\e[1;1H");
>>>>>          
>>>>>
>>>How does this printf work to clear the screen?
>>>      
>>>
>>It's ascii control character. 2J means clear the screen and
>>1;1H set the cursor position.
>>
>>    
>>
>>>-
>>>To unsubscribe from this list: send the line "unsubscribe
>>>linux-c-programming" in
>>>the body of a message to majordomo@vger.kernel.org
>>>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>>      
>>>
>
>
>-
>To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
>  
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: clear the screen
  2005-02-21  7:08 clear the screen kaushal
  2005-02-21  7:59 ` J.
@ 2005-02-23  0:16 ` Glynn Clements
  2005-02-23 12:54   ` Progga
  1 sibling, 1 reply; 9+ messages in thread
From: Glynn Clements @ 2005-02-23  0:16 UTC (permalink / raw)
  To: kaushal; +Cc: linux-c


kaushal wrote:

> 	Sorry for a very basic question.I would like to know how to clear the
> screen from within a c program without using system("clear") or any of
> the ncurses functions.Can we do this using printf?My program is in raw
> mode so is there any feature available by which I can use the termios
> structure for clearing the screen if it is not possible with printf.Long
> ago when I used work in the dos platform I used conio.h and clrscr()
> rourine.I guess I have to write that clrscr() routine's code itself.Im
> working on a linux machine now.

Unix systems don't have a "screen", they have terminals. Historically,
these would be physical terminals (e.g. vt220s) connected via serial
ports. The Linux kernel uses the keyboard and the graphics card's text
mode to emulate a number of terminals, as well as supporting physical
terminals connected to a serial port (either directly or via modems)
and pseudo-terminals (used by programs which emulate terminals, e.g. 
telnetd, xterm, screen etc).

To clear the terminal's screen (assuming that it's a video terminal;
hardcopy terminals don't have a screen), you have to send the
appropriate control sequence. The exact sequence depends upon the type
of terminal (which can be determined from the value of the TERM
environment variable).

To obtain the correct control sequence, use the terminfo library to
obtain the sequence for the "clear" capability, then send that
sequence to the terminal (i.e. stdout).

See the manpage for setupterm() and tigetstr() for more information.

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: clear the screen
  2005-02-23  0:16 ` Glynn Clements
@ 2005-02-23 12:54   ` Progga
  2005-02-28  6:36     ` Glynn Clements
  0 siblings, 1 reply; 9+ messages in thread
From: Progga @ 2005-02-23 12:54 UTC (permalink / raw)
  To: linux-c-programming

On Wed, Feb 23, 2005 at 12:16:52AM +0000, Glynn Clements wrote:
> 
> See the manpage for setupterm() and tigetstr() for more information.

 Should it be like this ? 


<code>
    char *area[100], bp[2048] ;

    tgetent( bp, getenv( "TERM" )) ;
    puts( tgetstr( "cl", area )) ;
</code>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: clear the screen
  2005-02-23 12:54   ` Progga
@ 2005-02-28  6:36     ` Glynn Clements
  0 siblings, 0 replies; 9+ messages in thread
From: Glynn Clements @ 2005-02-28  6:36 UTC (permalink / raw)
  To: Progga; +Cc: linux-c-programming


Progga wrote:

> > See the manpage for setupterm() and tigetstr() for more information.
> 
>  Should it be like this ? 
> 
> 
> <code>
>     char *area[100], bp[2048] ;
> 
>     tgetent( bp, getenv( "TERM" )) ;
>     puts( tgetstr( "cl", area )) ;
> </code>

First, that's the old termcap interface; new programs should use the
terminfo interface.

Second, the use of the "area" variable is wrong. It should be
something like:

	char buf[100];
	char *area = buf;
	
	puts(tgetstr("cl", &area));

Repeated calls to tgetstr() will advance the "area" pointer, so that
"buf" will contain, in order, all of the strings retrieved by
tgetstr().

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-02-28  6:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-21  7:08 clear the screen kaushal
2005-02-21  7:59 ` J.
2005-02-21  9:56   ` Vinodkumar Nair
2005-02-21 10:12     ` YYW
2005-02-21 13:50       ` Darren Sessions
2005-02-21 14:15         ` Ron Michael Khu
2005-02-23  0:16 ` Glynn Clements
2005-02-23 12:54   ` Progga
2005-02-28  6:36     ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).