davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

clear a LXTerminal window

Sun May 15, 2016 7:50 pm

hello,
is it possible to clear a LXTerminal window before starting to write anew?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

jahboater
Posts: 4778
Joined: Wed Feb 04, 2015 6:38 pm

Re: clear a LXTerminal window

Sun May 15, 2016 8:14 pm

From the shell, the command "clear" clears the screen (see man clear).

From curses in a C program, use clear() or erase().

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: clear a LXTerminal window

Sun May 15, 2016 8:23 pm

hmm, I'm not using curses, just the normal LXterminal window opened as stdout for printf(), but perhaps
system("clear");
would work then in a C program...

Already a little late now, my Pi robot is off, but I'll try it tomorrow then ASAP :)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: clear a LXTerminal window

Sun May 15, 2016 8:24 pm

The escape sequence "\033[2J" clears the whole visible window without moving the cursor, and "\033[H" homes the cursor to the top left.

Again I recommend http://rtfm.etla.org/xterm/ctlseq.html as a guide to the sequences understood by xterm. Let us know if there is terminology there that you do not understand. In a C string, "\033" is the ASCII ESC character, and note that CSI is often used to mean "\033[".

The exact repertoire of escape sequences will vary between terminal emulators. Libraries such as ncurses can make your program terminal-independent, but that is not as important these days. xterm is something of a standard.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: clear a LXTerminal window

Sun May 15, 2016 8:27 pm

yes, thank you, but that is faaaar toooo muchhhh to read!
( actually I do not even know where to start to read over there!) O.o

But this is fine:
"\033[2J" clears the whole visible window without moving the cursor
and the other one
and "\033[H" homes the cursor to the top left.
I am already using 8-)

thank you very much for your help! :)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: clear a LXTerminal window

Mon May 16, 2016 8:16 am

update:
"\033[2J" clears the whole visible window without moving the cursor
I tested it and everything works like a charm! 8-)

thanks again very much! :)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Return to “C/C++”