Skip to content
Snippets Groups Projects
Commit a72494e2 authored by deuce's avatar deuce
Browse files

Used new ciowrap window() function. Allows removal of term.ypos and term.xpos

as well as simplifying output.
Fixed terrible tab bug (This one prevented CVS messages from working right)
parent 1e6159ce
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,8 @@
struct terminal term;
const int tabs[11]={1,8,16,24,32,40,48,56,64,72,80};
/* const int tabs[11]={1,8,16,24,32,40,48,56,64,72,80}; */
const int tabs[11]={9,17,25,33,41,49,57,65,73,80,80.1};
int backlines=2000;
......@@ -64,13 +65,13 @@ void clear2bol(void)
char *buf;
int i,j;
buf=(char *)malloc((term.xpos+1)*2);
buf=(char *)malloc((wherex()+1)*2);
j=0;
for(i=1;i<=term.xpos;i++) {
for(i=1;i<=wherex();i++) {
buf[j++]=' ';
buf[j++]=term.attr;
}
puttext(term.x+1,term.y+term.ypos,term.x+term.xpos,term.y+term.ypos,buf);
puttext(term.x+1,term.y+wherey(),term.x+wherex(),term.y+wherey(),buf);
free(buf);
}
......@@ -79,13 +80,13 @@ void clear2eol(void)
char *buf;
int i,j;
buf=(char *)malloc((term.width-term.xpos+1)*2);
buf=(char *)malloc((term.width-wherex()+1)*2);
j=0;
for(i=term.xpos;i<=term.width;i++) {
for(i=wherex();i<=term.width;i++) {
buf[j++]=' ';
buf[j++]=term.attr;
}
puttext(term.x+term.xpos,term.y+term.ypos,term.x+term.width,term.y+term.ypos,buf);
puttext(term.x+wherex(),term.y+wherey(),term.x+term.width,term.y+wherey(),buf);
free(buf);
}
......@@ -112,11 +113,6 @@ void clearscreen(char attr)
free(buf);
}
void set_cursor(void)
{
gotoxy(term.x+term.xpos,term.y+term.ypos);
}
void do_ansi(void)
{
char *p;
......@@ -131,57 +127,56 @@ void do_ansi(void)
p=term.escbuf+strlen(term.escbuf)-1;
switch(*p) {
case '@': /* Insert Char */
gettext(term.x+term.xpos,term.y+term.ypos,term.x+term.width-1,term.y+term.ypos,tmp);
i=wherex();
j=wherey();
gettext(term.x+wherex(),term.y+wherey(),term.x+term.width-1,term.y+wherey(),tmp);
putch(' ');
puttext(term.x+term.xpos+1,term.y+term.ypos,term.x+term.width,term.y+term.ypos,tmp);
set_cursor();
puttext(term.x+wherex()+1,term.y+wherey(),term.x+term.width,term.y+wherey(),tmp);
gotoxy(i,j);
break;
case 'A': /* Cursor Up */
i=atoi(term.escbuf+1);
if(i==0)
i=1;
term.ypos-=i;
if(term.ypos<1)
term.ypos=1;
set_cursor();
i=wherey()-i;
if(i<1)
i=1;
gotoxy(wherex(),i);
break;
case 'B': /* Cursor Down */
i=atoi(term.escbuf+1);
if(i==0)
i=1;
term.ypos+=i;
if(term.ypos>term.height)
term.ypos=term.height;
set_cursor();
i=wherey()+i;
if(i>term.height)
i=term.height;
gotoxy(wherex(),i);
break;
case 'C': /* Cursor Right */
i=atoi(term.escbuf+1);
if(i==0)
i=1;
term.xpos+=i;
if(term.xpos>term.width)
term.xpos=term.width;
set_cursor();
i=wherex()+i;
if(i>term.width)
i=term.width;
gotoxy(i,wherey());
break;
case 'D': /* Cursor Left */
i=atoi(term.escbuf+1);
if(i==0)
i=1;
term.xpos-=i;
if(term.xpos<1)
term.xpos=1;
set_cursor();
i=wherex()-i;
if(i<1)
i=1;
gotoxy(i,wherey());
break;
case 'E':
i=atoi(term.escbuf+1);
if(i==0)
i=1;
term.ypos+=i;
for(j=term.height;j<term.ypos;j++)
scrollup();
if(term.ypos>term.height)
term.ypos=term.height;
set_cursor();
i=wherey()+i;
for(j=0;j<i;j++)
putch('\n');
break;
case 'f':
case 'H':
......@@ -204,9 +199,7 @@ void do_ansi(void)
row=term.height;
if(col>term.width)
col=term.width;
term.ypos=row;
term.xpos=col;
set_cursor();
gotoxy(col,row);
break;
case 'J':
i=atoi(term.escbuf+1);
......@@ -219,7 +212,7 @@ void do_ansi(void)
p2[j++]=' ';
p2[j++]=term.attr;
}
for(i=term.ypos+1;i<=term.height;i++) {
for(i=wherey()+1;i<=term.height;i++) {
puttext(term.x+1,term.y+i,term.x+term.width,term.y+i,p2);
}
free(p2);
......@@ -232,16 +225,14 @@ void do_ansi(void)
p2[j++]=' ';
p2[j++]=term.attr;
}
for(i=term.ypos-1;i>=1;i--) {
for(i=wherey()-1;i>=1;i--) {
puttext(term.x+1,term.y+i,term.x+term.width,term.y+i,p2);
}
free(p2);
break;
case 2:
clearscreen(term.attr);
term.ypos=1;
term.xpos=1;
set_cursor();
gotoxy(1,1);
break;
}
break;
......@@ -261,7 +252,7 @@ void do_ansi(void)
p2[j++]=' ';
p2[j++]=term.attr;
}
puttext(term.x+1,term.y+term.ypos,term.x+term.width,term.y+term.ypos,p2);
puttext(term.x+1,term.y+wherey(),term.x+term.width,term.y+wherey(),p2);
free(p2);
break;
}
......@@ -270,12 +261,12 @@ void do_ansi(void)
i=atoi(term.escbuf+1);
if(i==0)
i=1;
if(i>term.height-term.ypos)
i=term.height-term.ypos;
if(i<term.height-term.ypos) {
p2=(char *)malloc((term.height-term.ypos-i)*term.width*2);
gettext(term.x+1,term.y+term.ypos,term.x+term.width,term.ypos+(term.height-term.ypos-i),p2);
puttext(term.x+1,term.y+term.ypos+i,term.x+term.width,term.ypos+(term.height-term.ypos),p2);
if(i>term.height-wherey())
i=term.height-wherey();
if(i<term.height-wherey()) {
p2=(char *)malloc((term.height-wherey()-i)*term.width*2);
gettext(term.x+1,term.y+wherey(),term.x+term.width,wherey()+(term.height-wherey()-i),p2);
puttext(term.x+1,term.y+wherey()+i,term.x+term.width,wherey()+(term.height-wherey()),p2);
j=0;
free(p2);
}
......@@ -298,14 +289,14 @@ void do_ansi(void)
i=atoi(term.escbuf+1);
if(i==0)
i=1;
if(i>term.width-term.xpos)
i=term.width-term.xpos;
p2=(char *)malloc((term.width-term.xpos)*2);
gettext(term.x+term.xpos,term.y+term.ypos,term.x+term.width,term.y+term.ypos,p2);
memmove(p2,p2+(i*2),(term.width-term.xpos-i)*2);
for(i=(term.width-term.xpos)*2-2;i>=term.xpos;i-=2)
if(i>term.width-wherex())
i=term.width-wherex();
p2=(char *)malloc((term.width-wherex())*2);
gettext(term.x+wherex(),term.y+wherey(),term.x+term.width,term.y+wherey(),p2);
memmove(p2,p2+(i*2),(term.width-wherex()-i)*2);
for(i=(term.width-wherex())*2-2;i>=wherex();i-=2)
p2[i]=' ';
puttext(term.x+term.xpos,term.y+term.ypos,term.x+term.width,term.y+term.ypos,p2);
puttext(term.x+wherex(),term.y+wherey(),term.x+term.width,term.y+wherey(),p2);
break;
case 'S':
scrollup();
......@@ -315,20 +306,17 @@ void do_ansi(void)
break;
case 'U':
clearscreen(7);
term.ypos=1;
term.xpos=1;
set_cursor();
gotoxy(1,1);
break;
case 'Y': /* ToDo? BananaCom Clear Line */
break;
case 'Z':
for(j=10;j>=0;j--) {
if(tabs[j]<term.xpos) {
term.xpos=tabs[j];
if(tabs[j]<wherex()) {
gotoxy(tabs[j],wherey());
break;
}
}
set_cursor();
break;
case 'b': /* ToDo? Banana ANSI */
break;
......@@ -447,7 +435,7 @@ void do_ansi(void)
i=atoi(term.escbuf+1);
switch(i) {
case 6:
sprintf(tmp,"%c[%d;%dR",27,term.ypos,term.xpos);
sprintf(tmp,"%c[%d;%dR",27,wherey(),wherex());
rlogin_send(tmp,strlen(tmp),1000);
break;
case 255:
......@@ -463,15 +451,13 @@ void do_ansi(void)
case 'r': /* ToDo? Scrolling reigon */
break;
case 's':
term.save_xpos=term.xpos;
term.save_ypos=term.ypos;
term.save_xpos=wherex();
term.save_ypos=wherey();
break;
case 'u':
if(term.save_ypos>0 && term.save_ypos<=term.height
&& term.save_xpos>0 && term.save_xpos<=term.width) {
term.xpos=term.save_xpos;
term.ypos=term.save_ypos;
set_cursor();
gotoxy(term.save_xpos,term.save_ypos);
}
break;
case 'y': /* ToDo? VT100 Tests */
......@@ -500,10 +486,8 @@ void doterm(void)
unsigned char buf[BUFSIZE];
unsigned char prn[BUFSIZE];
int key;
int i,j;
int i,j,k;
term.xpos=1;
term.ypos=1;
term.attr=7;
term.save_xpos=0;
term.save_ypos=0;
......@@ -514,9 +498,10 @@ void doterm(void)
term.scrollback=malloc(term.width*2*backlines);
memset(term.scrollback,0,term.width*2*backlines);
ch[1]=0;
gotoxy(term.xpos,term.ypos);
textattr(term.attr);
_setcursortype(_NORMALCURSOR);
window(term.x+1,term.y+1,term.x+term.width,term.y+term.height);
gotoxy(1,1);
/* Main input loop */
for(;;) {
/* Get remote input */
......@@ -560,65 +545,25 @@ void doterm(void)
cprintf(prn);
prn[0]=0;
clearscreen(term.attr);
term.ypos=1;
term.xpos=1;
set_cursor();
gotoxy(1,1);
break;
case 27: /* ESC */
cprintf(prn);
prn[0]=0;
term.sequence=1;
break;
case '\n':
cprintf(prn);
prn[0]=0;
term.ypos++;
if(term.ypos>term.height) {
term.ypos=term.height;
scrollup();
}
set_cursor();
break;
case '\t':
cprintf(prn);
prn[0]=0;
for(i=0;i<11;i++) {
if(tabs[i]>term.xpos) {
term.xpos=tabs[i];
for(k=0;k<11;k++) {
if(tabs[k]>wherex()) {
gotoxy(tabs[k],wherey());
break;
}
}
set_cursor();
break;
case '\r':
cprintf(prn);
prn[0]=0;
term.xpos=1;
set_cursor();
break;
case '\b':
cprintf(prn);
prn[0]=0;
term.xpos--;
if(term.xpos<1)
term.xpos=1;
putch(' ');
set_cursor();
break;
default:
strcat(prn,ch);
term.xpos++;
if(term.xpos>term.width) {
cprintf(prn);
prn[0]=0;
term.xpos=1;
term.ypos++;
if(term.ypos>term.height) {
term.ypos=term.height;
scrollup();
}
set_cursor();
}
}
}
}
......@@ -635,12 +580,14 @@ void doterm(void)
free(term.scrollback);
return;
case 19: /* CTRL-S */
i=wherex();
j=wherey();
switch(syncmenu()) {
case -1:
free(term.scrollback);
return;
}
set_cursor();
gotoxy(i,j);
break;
case KEY_LEFT:
rlogin_send("\033[D",3,100);
......
......@@ -7,8 +7,6 @@ struct terminal {
int x;
int y;
char *buffer;
int xpos;
int ypos;
int attr;
int save_xpos;
int save_ypos;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment