aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorAurélien Aptel <aurelien.aptel@gmail.com>2010-09-01 23:20:54 +0200
committerAurélien Aptel <aurelien.aptel@gmail.com>2010-09-01 23:20:54 +0200
commit97695baf4f9bc3632792a3330fb46e188ef166a2 (patch)
tree61b49574e905d8d381a41ac867d74e0080123807 /st.c
parent32e160c939ba1c6bdda7b2181c72ca6df06d94ad (diff)
downloadst-97695baf4f9bc3632792a3330fb46e188ef166a2.tar.gz
st-97695baf4f9bc3632792a3330fb46e188ef166a2.zip
factored code and fixed behaviour of tnewline().
Diffstat (limited to 'st.c')
-rw-r--r--st.c60
1 files changed, 20 insertions, 40 deletions
diff --git a/st.c b/st.c
index 0c876f5..5633e40 100644
--- a/st.c
+++ b/st.c
@@ -161,8 +161,8 @@ static void tputc(char);
161static void tputs(char*, int); 161static void tputs(char*, int);
162static void treset(void); 162static void treset(void);
163static void tresize(int, int); 163static void tresize(int, int);
164static void tscrollup(int); 164static void tscrollup(int, int);
165static void tscrolldown(int); 165static void tscrolldown(int, int);
166static void tsetattr(int*, int); 166static void tsetattr(int*, int);
167static void tsetchar(char); 167static void tsetchar(char);
168static void tsetscroll(int, int); 168static void tsetscroll(int, int);
@@ -459,15 +459,15 @@ tswapscreen(void) {
459} 459}
460 460
461void 461void
462tscrolldown (int n) { 462tscrolldown(int orig, int n) {
463 int i; 463 int i;
464 Line temp; 464 Line temp;
465 465
466 LIMIT(n, 0, term.bot-term.top+1); 466 LIMIT(n, 0, term.bot-orig+1);
467 467
468 tclearregion(0, term.bot-n+1, term.col-1, term.bot); 468 tclearregion(0, term.bot-n+1, term.col-1, term.bot);
469 469
470 for(i = term.bot; i >= term.top+n; i--) { 470 for(i = term.bot; i >= orig+n; i--) {
471 temp = term.line[i]; 471 temp = term.line[i];
472 term.line[i] = term.line[i-n]; 472 term.line[i] = term.line[i-n];
473 term.line[i-n] = temp; 473 term.line[i-n] = temp;
@@ -475,14 +475,14 @@ tscrolldown (int n) {
475} 475}
476 476
477void 477void
478tscrollup (int n) { 478tscrollup(int orig, int n) {
479 int i; 479 int i;
480 Line temp; 480 Line temp;
481 LIMIT(n, 0, term.bot-term.top+1); 481 LIMIT(n, 0, term.bot-orig+1);
482 482
483 tclearregion(0, term.top, term.col-1, term.top+n-1); 483 tclearregion(0, orig, term.col-1, orig+n-1);
484 484
485 for(i = term.top; i <= term.bot-n; i++) { 485 for(i = orig; i <= term.bot-n; i++) {
486 temp = term.line[i]; 486 temp = term.line[i];
487 term.line[i] = term.line[i+n]; 487 term.line[i] = term.line[i+n];
488 term.line[i+n] = temp; 488 term.line[i+n] = temp;
@@ -491,9 +491,11 @@ tscrollup (int n) {
491 491
492void 492void
493tnewline(void) { 493tnewline(void) {
494 int y = term.c.y + 1; 494 int y = term.c.y;
495 if(y > term.bot) 495 if(term.c.y == term.bot)
496 tscrollup(1), y = term.bot; 496 tscrollup(term.top, 1);
497 else
498 y++;
497 tmoveto(0, y); 499 tmoveto(0, y);
498} 500}
499 501
@@ -585,40 +587,18 @@ tinsertblank(int n) {
585 587
586void 588void
587tinsertblankline(int n) { 589tinsertblankline(int n) {
588 int i;
589 Line blank;
590 int bot = term.bot;
591
592 if(term.c.y < term.top || term.c.y > term.bot) 590 if(term.c.y < term.top || term.c.y > term.bot)
593 return; 591 return;
594 592
595 LIMIT(n, 0, bot-term.c.y+1); 593 tscrolldown(term.c.y, n);
596 tclearregion(0, bot-n+1, term.col-1, bot);
597 for(i = bot; i >= term.c.y+n; i--) {
598 /* swap deleted line <-> blanked line */
599 blank = term.line[i];
600 term.line[i] = term.line[i-n];
601 term.line[i-n] = blank;
602 }
603} 594}
604 595
605void 596void
606tdeleteline(int n) { 597tdeleteline(int n) {
607 int i;
608 Line blank;
609 int bot = term.bot;
610
611 if(term.c.y < term.top || term.c.y > term.bot) 598 if(term.c.y < term.top || term.c.y > term.bot)
612 return; 599 return;
613 600
614 LIMIT(n, 0, bot-term.c.y+1); 601 tscrollup(term.c.y, n);
615 tclearregion(0, term.c.y, term.col-1, term.c.y+n-1);
616 for(i = term.c.y; i <= bot-n; i++) {
617 /* swap deleted line <-> blanked line */
618 blank = term.line[i];
619 term.line[i] = term.line[i+n];
620 term.line[i+n] = blank;
621 }
622} 602}
623 603
624void 604void
@@ -790,11 +770,11 @@ csihandle(void) {
790 break; 770 break;
791 case 'S': /* SU -- Scroll <n> line up */ 771 case 'S': /* SU -- Scroll <n> line up */
792 DEFAULT(escseq.arg[0], 1); 772 DEFAULT(escseq.arg[0], 1);
793 tscrollup(escseq.arg[0]); 773 tscrollup(term.top, escseq.arg[0]);
794 break; 774 break;
795 case 'T': /* SD -- Scroll <n> line down */ 775 case 'T': /* SD -- Scroll <n> line down */
796 DEFAULT(escseq.arg[0], 1); 776 DEFAULT(escseq.arg[0], 1);
797 tscrolldown(escseq.arg[0]); 777 tscrolldown(term.top, escseq.arg[0]);
798 break; 778 break;
799 case 'L': /* IL -- Insert <n> blank lines */ 779 case 'L': /* IL -- Insert <n> blank lines */
800 DEFAULT(escseq.arg[0], 1); 780 DEFAULT(escseq.arg[0], 1);
@@ -984,7 +964,7 @@ tputc(char c) {
984 break; 964 break;
985 case 'D': /* IND -- Linefeed */ 965 case 'D': /* IND -- Linefeed */
986 if(term.c.y == term.bot) 966 if(term.c.y == term.bot)
987 tscrollup(1); 967 tscrollup(term.top, 1);
988 else 968 else
989 tmoveto(term.c.x, term.c.y+1); 969 tmoveto(term.c.x, term.c.y+1);
990 term.esc = 0; 970 term.esc = 0;
@@ -995,7 +975,7 @@ tputc(char c) {
995 break; 975 break;
996 case 'M': /* RI -- Reverse index */ 976 case 'M': /* RI -- Reverse index */
997 if(term.c.y == term.top) 977 if(term.c.y == term.top)
998 tscrolldown(1); 978 tscrolldown(term.top, 1);
999 else 979 else
1000 tmoveto(term.c.x, term.c.y-1); 980 tmoveto(term.c.x, term.c.y-1);
1001 term.esc = 0; 981 term.esc = 0;