diff options
| author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-09-01 23:20:54 +0200 |
|---|---|---|
| committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-09-01 23:20:54 +0200 |
| commit | 97695baf4f9bc3632792a3330fb46e188ef166a2 (patch) | |
| tree | 61b49574e905d8d381a41ac867d74e0080123807 | |
| parent | 32e160c939ba1c6bdda7b2181c72ca6df06d94ad (diff) | |
| download | st-97695baf4f9bc3632792a3330fb46e188ef166a2.tar.gz st-97695baf4f9bc3632792a3330fb46e188ef166a2.zip | |
factored code and fixed behaviour of tnewline().
| -rw-r--r-- | st.c | 60 |
1 files changed, 20 insertions, 40 deletions
| @@ -161,8 +161,8 @@ static void tputc(char); | |||
| 161 | static void tputs(char*, int); | 161 | static void tputs(char*, int); |
| 162 | static void treset(void); | 162 | static void treset(void); |
| 163 | static void tresize(int, int); | 163 | static void tresize(int, int); |
| 164 | static void tscrollup(int); | 164 | static void tscrollup(int, int); |
| 165 | static void tscrolldown(int); | 165 | static void tscrolldown(int, int); |
| 166 | static void tsetattr(int*, int); | 166 | static void tsetattr(int*, int); |
| 167 | static void tsetchar(char); | 167 | static void tsetchar(char); |
| 168 | static void tsetscroll(int, int); | 168 | static void tsetscroll(int, int); |
| @@ -459,15 +459,15 @@ tswapscreen(void) { | |||
| 459 | } | 459 | } |
| 460 | 460 | ||
| 461 | void | 461 | void |
| 462 | tscrolldown (int n) { | 462 | tscrolldown(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 | ||
| 477 | void | 477 | void |
| 478 | tscrollup (int n) { | 478 | tscrollup(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 | ||
| 492 | void | 492 | void |
| 493 | tnewline(void) { | 493 | tnewline(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 | ||
| 586 | void | 588 | void |
| 587 | tinsertblankline(int n) { | 589 | tinsertblankline(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 | ||
| 605 | void | 596 | void |
| 606 | tdeleteline(int n) { | 597 | tdeleteline(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 | ||
| 624 | void | 604 | void |
| @@ -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; |
