aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien Aptel <aurelien.aptel@gmail.com>2009-06-17 02:58:40 +0200
committerAurélien Aptel <aurelien.aptel@gmail.com>2009-06-17 02:58:40 +0200
commitb8ffa1d7e9cffda8bd8cc7f4ccf612201a617b34 (patch)
treef14b7c1a189687dbad04116044d49dfcefe93307
parentd5f4554431f82424af40600ed6835672ab8e44ae (diff)
downloadst-b8ffa1d7e9cffda8bd8cc7f4ccf612201a617b34.tar.gz
st-b8ffa1d7e9cffda8bd8cc7f4ccf612201a617b34.zip
fixed the scrolling bug and cleaned some stuff.
-rw-r--r--st.c129
1 files changed, 68 insertions, 61 deletions
diff --git a/st.c b/st.c
index 3940bbd..661f4fb 100644
--- a/st.c
+++ b/st.c
@@ -37,7 +37,7 @@
37enum { ATnone=0 , ATreverse=1 , ATunderline=2, ATbold=4 }; 37enum { ATnone=0 , ATreverse=1 , ATunderline=2, ATbold=4 };
38enum { CSup, CSdown, CSright, CSleft, CShide, CSdraw, CSwrap, CSsave, CSload }; 38enum { CSup, CSdown, CSright, CSleft, CShide, CSdraw, CSwrap, CSsave, CSload };
39enum { CRset=1, CRupdate=2 }; 39enum { CRset=1, CRupdate=2 };
40enum { TMwrap=1, TMinsert=2, TMaltcharset }; 40enum { TMwrap=1, TMinsert=2 };
41enum { SCupdate, SCredraw }; 41enum { SCupdate, SCredraw };
42 42
43typedef int Color; 43typedef int Color;
@@ -154,6 +154,7 @@ void xdrawc(int, int, Glyph);
154void xinit(void); 154void xinit(void);
155void xscroll(void); 155void xscroll(void);
156 156
157void cursor(int);
157 158
158/* Globals */ 159/* Globals */
159DC dc; 160DC dc;
@@ -201,7 +202,6 @@ sigchld(int a) {
201 exit(EXIT_FAILURE); 202 exit(EXIT_FAILURE);
202} 203}
203 204
204
205void 205void
206ttynew(void) { 206ttynew(void) {
207 int m, s; 207 int m, s;
@@ -328,21 +328,19 @@ void
328tscroll(void) { 328tscroll(void) {
329 Line temp = term.line[term.top]; 329 Line temp = term.line[term.top];
330 int i; 330 int i;
331 331 /* X stuff _before_ the line swapping (results in wrong line index) */
332 xscroll();
332 for(i = term.top; i < term.bot; i++) 333 for(i = term.top; i < term.bot; i++)
333 term.line[i] = term.line[i+1]; 334 term.line[i] = term.line[i+1];
334 memset(temp, 0, sizeof(Glyph) * term.col); 335 memset(temp, 0, sizeof(Glyph) * term.col);
335 term.line[term.bot] = temp; 336 term.line[term.bot] = temp;
336 xscroll();
337} 337}
338 338
339void 339void
340tnewline(void) { 340tnewline(void) {
341 int y = term.c.y + 1; 341 int y = term.c.y + 1;
342 342 if(y > term.bot)
343 if(y > term.bot) {
344 tscroll(), y = term.bot; 343 tscroll(), y = term.bot;
345 }
346 tmoveto(0, y); 344 tmoveto(0, y);
347} 345}
348 346
@@ -477,6 +475,13 @@ tinsertblank(int n) {
477} 475}
478 476
479void 477void
478tsetlinestate(int n, int state) {
479 int i;
480 for(i = 0; i < term.col; i++)
481 term.line[n][i].state |= state;
482}
483
484void
480tinsertblankline (int n) { 485tinsertblankline (int n) {
481 int i; 486 int i;
482 Line blank; 487 Line blank;
@@ -497,10 +502,11 @@ tinsertblankline (int n) {
497 term.line[i-n] = blank; 502 term.line[i-n] = blank;
498 /* blank it */ 503 /* blank it */
499 memset(blank, 0, term.col * sizeof(Glyph)); 504 memset(blank, 0, term.col * sizeof(Glyph));
505 tsetlinestate(i, CRupdate);
506 tsetlinestate(i-n, CRupdate);
500 } 507 }
501} 508}
502 509
503
504void 510void
505tdeleteline(int n) { 511tdeleteline(int n) {
506 int i; 512 int i;
@@ -522,6 +528,8 @@ tdeleteline(int n) {
522 term.line[i+n] = blank; 528 term.line[i+n] = blank;
523 /* blank it */ 529 /* blank it */
524 memset(blank, 0, term.col * sizeof(Glyph)); 530 memset(blank, 0, term.col * sizeof(Glyph));
531 tsetlinestate(i, CRupdate);
532 tsetlinestate(i-n, CRupdate);
525 } 533 }
526} 534}
527 535
@@ -529,48 +537,48 @@ void
529tsetattr(int *attr, int l) { 537tsetattr(int *attr, int l) {
530 int i; 538 int i;
531 539
532 for(i = 0; i < l; i++) { 540 for(i = 0; i < l; i++) {
533 switch(attr[i]) { 541 switch(attr[i]) {
534 case 0: 542 case 0:
535 memset(&term.c.attr, 0, sizeof(term.c.attr)); 543 memset(&term.c.attr, 0, sizeof(term.c.attr));
536 term.c.attr.fg = DefaultFG; 544 term.c.attr.fg = DefaultFG;
537 term.c.attr.bg = DefaultBG; 545 term.c.attr.bg = DefaultBG;
538 break; 546 break;
539 case 1: 547 case 1:
540 term.c.attr.mode |= ATbold; 548 term.c.attr.mode |= ATbold;
541 break; 549 break;
542 case 4: 550 case 4:
543 term.c.attr.mode |= ATunderline; 551 term.c.attr.mode |= ATunderline;
544 break; 552 break;
545 case 7: 553 case 7:
546 term.c.attr.mode |= ATreverse; 554 term.c.attr.mode |= ATreverse;
547 break; 555 break;
548 case 8: 556 case 8:
549 term.c.hidden = CShide; 557 term.c.hidden = CShide;
550 break; 558 break;
551 case 22: 559 case 22:
552 term.c.attr.mode &= ~ATbold; 560 term.c.attr.mode &= ~ATbold;
553 break; 561 break;
554 case 24: 562 case 24:
555 term.c.attr.mode &= ~ATunderline; 563 term.c.attr.mode &= ~ATunderline;
556 break; 564 break;
557 case 27: 565 case 27:
558 term.c.attr.mode &= ~ATreverse; 566 term.c.attr.mode &= ~ATreverse;
559 break; 567 break;
560 case 39: 568 case 39:
561 term.c.attr.fg = DefaultFG; 569 term.c.attr.fg = DefaultFG;
562 break; 570 break;
563 case 49: 571 case 49:
564 term.c.attr.fg = DefaultBG; 572 term.c.attr.fg = DefaultBG;
565 break; 573 break;
566 default: 574 default:
567 if(BETWEEN(attr[i], 30, 37)) 575 if(BETWEEN(attr[i], 30, 37))
568 term.c.attr.fg = attr[i] - 30; 576 term.c.attr.fg = attr[i] - 30;
569 else if(BETWEEN(attr[i], 40, 47)) 577 else if(BETWEEN(attr[i], 40, 47))
570 term.c.attr.bg = attr[i] - 40; 578 term.c.attr.bg = attr[i] - 40;
571 break; 579 break;
572 }
573 } 580 }
581 }
574} 582}
575 583
576void 584void
@@ -588,9 +596,8 @@ tsetscroll(int t, int b) {
588 term.bot = b; 596 term.bot = b;
589} 597}
590 598
591
592void 599void
593eschandle(void) { 600eschandle(void) {
594 switch(escseq.pre) { 601 switch(escseq.pre) {
595 default: 602 default:
596 goto unknown_seq; 603 goto unknown_seq;
@@ -846,7 +853,6 @@ xgetcol(const char *s) {
846 return color.pixel; 853 return color.pixel;
847} 854}
848 855
849
850void 856void
851xclear(int x1, int y1, int x2, int y2) { 857xclear(int x1, int y1, int x2, int y2) {
852 XClearArea(xw.dis, xw.win, 858 XClearArea(xw.dis, xw.win,
@@ -855,7 +861,6 @@ xclear(int x1, int y1, int x2, int y2) {
855 False); 861 False);
856} 862}
857 863
858
859void 864void
860xscroll(void) { 865xscroll(void) {
861 int srcy = (term.top+1) * xw.ch; 866 int srcy = (term.top+1) * xw.ch;
@@ -867,9 +872,6 @@ xscroll(void) {
867 xclear(0, term.bot, term.col-1, term.bot); 872 xclear(0, term.bot, term.col-1, term.bot);
868} 873}
869 874
870
871
872
873void 875void
874xinit(void) { 876xinit(void) {
875 XGCValues values; 877 XGCValues values;
@@ -963,14 +965,15 @@ xcursor(int mode) {
963 /* remove the old cursor */ 965 /* remove the old cursor */
964 if(term.line[oldy][oldx].state & CRset) 966 if(term.line[oldy][oldx].state & CRset)
965 xdrawc(oldx, oldy, term.line[oldy][oldx]); 967 xdrawc(oldx, oldy, term.line[oldy][oldx]);
966 else xclear(oldx, oldy, oldx, oldy); /* XXX: maybe a bug */ 968 else
967 if(mode == CSdraw && !term.c.hidden) { 969 xclear(oldx, oldy, oldx, oldy);
970 /* draw the new one */
971 if(mode == CSdraw) {
968 xdrawc(term.c.x, term.c.y, g); 972 xdrawc(term.c.x, term.c.y, g);
969 oldx = term.c.x, oldy = term.c.y; 973 oldx = term.c.x, oldy = term.c.y;
970 } 974 }
971} 975}
972 976
973
974void 977void
975draw(int redraw_all) { 978draw(int redraw_all) {
976 int x, y; 979 int x, y;
@@ -978,14 +981,18 @@ draw(int redraw_all) {
978 981
979 if(redraw_all) 982 if(redraw_all)
980 XClearWindow(xw.dis, xw.win); 983 XClearWindow(xw.dis, xw.win);
984
981 /* XXX: drawing could be optimised */ 985 /* XXX: drawing could be optimised */
982 for(y = 0; y < term.row; y++) { 986 for(y = 0; y < term.row; y++) {
983 for(x = 0; x < term.col; x++) { 987 for(x = 0; x < term.col; x++) {
984 changed = term.line[y][x].state & CRupdate; 988 changed = term.line[y][x].state & CRupdate;
985 set = term.line[y][x].state & CRset; 989 set = term.line[y][x].state & CRset;
986 if((changed && set) || (redraw_all && set)) { 990 if(redraw_all || changed) {
987 term.line[y][x].state &= ~CRupdate; 991 term.line[y][x].state &= ~CRupdate;
988 xdrawc(x, y, term.line[y][x]); 992 if(set)
993 xdrawc(x, y, term.line[y][x]);
994 else
995 xclear(x, y, x, y);
989 } 996 }
990 } 997 }
991 } 998 }