diff options
| author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-08-30 01:35:37 +0200 |
|---|---|---|
| committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-08-30 01:35:37 +0200 |
| commit | 7d88cf88d05c5f5fffbe096da9fac79d7d8957f9 (patch) | |
| tree | 197aa4f713db716edc28d6fe77a357d85bd10389 /st.c | |
| parent | removed old VT52 escapes, fixed VT100 IND. (diff) | |
| download | st-7d88cf88d05c5f5fffbe096da9fac79d7d8957f9.tar.gz st-7d88cf88d05c5f5fffbe096da9fac79d7d8957f9.zip | |
added support for the "magic margin", changed c.hide to c.state, changed xcursor() to use term instead of a
parameter and fixed the cursor position after setting a scrolling region.
Diffstat (limited to 'st.c')
| -rw-r--r-- | st.c | 50 |
1 files changed, 28 insertions, 22 deletions
| @@ -46,8 +46,9 @@ | |||
| 46 | 46 | ||
| 47 | /* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */ | 47 | /* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */ |
| 48 | enum { ATTR_NULL=0 , ATTR_REVERSE=1 , ATTR_UNDERLINE=2, ATTR_BOLD=4, ATTR_GFX=8 }; | 48 | enum { ATTR_NULL=0 , ATTR_REVERSE=1 , ATTR_UNDERLINE=2, ATTR_BOLD=4, ATTR_GFX=8 }; |
| 49 | enum { CURSOR_UP, CURSOR_DOWN, CURSOR_LEFT, CURSOR_RIGHT, CURSOR_HIDE = 1, | 49 | enum { CURSOR_UP, CURSOR_DOWN, CURSOR_LEFT, CURSOR_RIGHT, |
| 50 | CURSOR_DRAW = 0, CURSOR_SAVE, CURSOR_LOAD }; | 50 | CURSOR_SAVE, CURSOR_LOAD }; |
| 51 | enum { CURSOR_DEFAULT = 0, CURSOR_HIDE = 1, CURSOR_WRAPNEXT = 2 }; | ||
| 51 | enum { GLYPH_SET=1, GLYPH_DIRTY=2 }; | 52 | enum { GLYPH_SET=1, GLYPH_DIRTY=2 }; |
| 52 | enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4 }; | 53 | enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4 }; |
| 53 | enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 }; | 54 | enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 }; |
| @@ -67,7 +68,7 @@ typedef struct { | |||
| 67 | Glyph attr; /* current char attributes */ | 68 | Glyph attr; /* current char attributes */ |
| 68 | int x; | 69 | int x; |
| 69 | int y; | 70 | int y; |
| 70 | char hide; | 71 | char state; |
| 71 | } TCursor; | 72 | } TCursor; |
| 72 | 73 | ||
| 73 | /* CSI Escape sequence structs */ | 74 | /* CSI Escape sequence structs */ |
| @@ -164,7 +165,7 @@ static void xbell(void); | |||
| 164 | static void xdraws(char *, Glyph, int, int, int); | 165 | static void xdraws(char *, Glyph, int, int, int); |
| 165 | static void xhints(void); | 166 | static void xhints(void); |
| 166 | static void xclear(int, int, int, int); | 167 | static void xclear(int, int, int, int); |
| 167 | static void xcursor(int); | 168 | static void xcursor(void); |
| 168 | static void xinit(void); | 169 | static void xinit(void); |
| 169 | static void xloadcols(void); | 170 | static void xloadcols(void); |
| 170 | 171 | ||
| @@ -329,7 +330,7 @@ treset(void) { | |||
| 329 | .mode = ATTR_NULL, | 330 | .mode = ATTR_NULL, |
| 330 | .fg = DefaultFG, | 331 | .fg = DefaultFG, |
| 331 | .bg = DefaultBG | 332 | .bg = DefaultBG |
| 332 | }, .x = 0, .y = 0, .hide = 0}; | 333 | }, .x = 0, .y = 0, .state = CURSOR_DEFAULT}; |
| 333 | 334 | ||
| 334 | term.top = 0, term.bot = term.row - 1; | 335 | term.top = 0, term.bot = term.row - 1; |
| 335 | term.mode = MODE_WRAP; | 336 | term.mode = MODE_WRAP; |
| @@ -414,8 +415,11 @@ csiparse(void) { | |||
| 414 | 415 | ||
| 415 | void | 416 | void |
| 416 | tmoveto(int x, int y) { | 417 | tmoveto(int x, int y) { |
| 417 | term.c.x = x < 0 ? 0 : x >= term.col ? term.col-1 : x; | 418 | LIMIT(x, 0, term.col-1); |
| 418 | term.c.y = y < 0 ? 0 : y >= term.row ? term.row-1 : y; | 419 | LIMIT(y, 0, term.row-1); |
| 420 | term.c.state &= ~CURSOR_WRAPNEXT; | ||
| 421 | term.c.x = x; | ||
| 422 | term.c.y = y; | ||
| 419 | } | 423 | } |
| 420 | 424 | ||
| 421 | void | 425 | void |
| @@ -711,7 +715,7 @@ csihandle(void) { | |||
| 711 | case 12: /* att610 -- Stop blinking cursor (IGNORED) */ | 715 | case 12: /* att610 -- Stop blinking cursor (IGNORED) */ |
| 712 | break; | 716 | break; |
| 713 | case 25: | 717 | case 25: |
| 714 | term.c.hide = CURSOR_HIDE; | 718 | term.c.state |= CURSOR_HIDE; |
| 715 | break; | 719 | break; |
| 716 | case 1048: /* XXX: no alt. screen to erase/save */ | 720 | case 1048: /* XXX: no alt. screen to erase/save */ |
| 717 | case 1049: | 721 | case 1049: |
| @@ -760,7 +764,7 @@ csihandle(void) { | |||
| 760 | case 12: /* att610 -- Start blinking cursor (IGNORED) */ | 764 | case 12: /* att610 -- Start blinking cursor (IGNORED) */ |
| 761 | break; | 765 | break; |
| 762 | case 25: | 766 | case 25: |
| 763 | term.c.hide = CURSOR_DRAW; | 767 | term.c.state &= ~CURSOR_HIDE; |
| 764 | break; | 768 | break; |
| 765 | case 1048: | 769 | case 1048: |
| 766 | case 1049: /* XXX: no alt. screen to erase/save */ | 770 | case 1049: /* XXX: no alt. screen to erase/save */ |
| @@ -788,6 +792,7 @@ csihandle(void) { | |||
| 788 | DEFAULT(escseq.arg[0], 1); | 792 | DEFAULT(escseq.arg[0], 1); |
| 789 | DEFAULT(escseq.arg[1], term.row); | 793 | DEFAULT(escseq.arg[1], term.row); |
| 790 | tsetscroll(escseq.arg[0]-1, escseq.arg[1]-1); | 794 | tsetscroll(escseq.arg[0]-1, escseq.arg[1]-1); |
| 795 | tmoveto(0, 0); | ||
| 791 | } | 796 | } |
| 792 | break; | 797 | break; |
| 793 | case 's': /* DECSC -- Save cursor position (ANSI.SYS) */ | 798 | case 's': /* DECSC -- Save cursor position (ANSI.SYS) */ |
| @@ -932,11 +937,13 @@ tputc(char c) { | |||
| 932 | term.esc = ESC_START; | 937 | term.esc = ESC_START; |
| 933 | break; | 938 | break; |
| 934 | default: | 939 | default: |
| 940 | if(IS_SET(MODE_WRAP) && term.c.state & CURSOR_WRAPNEXT) | ||
| 941 | tnewline(); | ||
| 935 | tsetchar(c); | 942 | tsetchar(c); |
| 936 | if(term.c.x+1 < term.col) { | 943 | if(term.c.x+1 < term.col) |
| 937 | tmoveto(term.c.x+1, term.c.y); | 944 | tmoveto(term.c.x+1, term.c.y); |
| 938 | } else if(IS_SET(MODE_WRAP)) | 945 | else |
| 939 | tnewline(); | 946 | term.c.state |= CURSOR_WRAPNEXT; |
| 940 | break; | 947 | break; |
| 941 | } | 948 | } |
| 942 | } | 949 | } |
| @@ -974,13 +981,12 @@ tresize(int col, int row) { | |||
| 974 | for(/* i == minrow */; i < row; i++) | 981 | for(/* i == minrow */; i < row; i++) |
| 975 | term.line[i] = calloc(col, sizeof(Glyph)); | 982 | term.line[i] = calloc(col, sizeof(Glyph)); |
| 976 | 983 | ||
| 977 | LIMIT(term.c.x, 0, col-1); | 984 | /* update terminal size */ |
| 978 | LIMIT(term.c.y, 0, row-1); | ||
| 979 | LIMIT(term.top, 0, row-1); | ||
| 980 | LIMIT(term.bot, 0, row-1); | ||
| 981 | |||
| 982 | term.bot = row-1; | ||
| 983 | term.col = col, term.row = row; | 985 | term.col = col, term.row = row; |
| 986 | /* make use of the LIMIT in tmoveto */ | ||
| 987 | tmoveto(term.c.x, term.c.y); | ||
| 988 | /* reset scrolling region */ | ||
| 989 | tsetscroll(0, row-1); | ||
| 984 | } | 990 | } |
| 985 | 991 | ||
| 986 | void | 992 | void |
| @@ -1112,7 +1118,7 @@ xdraws(char *s, Glyph base, int x, int y, int len) { | |||
| 1112 | } | 1118 | } |
| 1113 | 1119 | ||
| 1114 | void | 1120 | void |
| 1115 | xcursor(int mode) { | 1121 | xcursor(void) { |
| 1116 | static int oldx = 0; | 1122 | static int oldx = 0; |
| 1117 | static int oldy = 0; | 1123 | static int oldy = 0; |
| 1118 | Glyph g = {' ', ATTR_NULL, DefaultBG, DefaultCS, 0}; | 1124 | Glyph g = {' ', ATTR_NULL, DefaultBG, DefaultCS, 0}; |
| @@ -1130,7 +1136,7 @@ xcursor(int mode) { | |||
| 1130 | xclear(oldx, oldy, oldx, oldy); | 1136 | xclear(oldx, oldy, oldx, oldy); |
| 1131 | 1137 | ||
| 1132 | /* draw the new one */ | 1138 | /* draw the new one */ |
| 1133 | if(mode == CURSOR_DRAW) { | 1139 | if(!(term.c.state & CURSOR_HIDE)) { |
| 1134 | xdraws(&g.c, g, term.c.x, term.c.y, 1); | 1140 | xdraws(&g.c, g, term.c.x, term.c.y, 1); |
| 1135 | oldx = term.c.x, oldy = term.c.y; | 1141 | oldx = term.c.x, oldy = term.c.y; |
| 1136 | } | 1142 | } |
| @@ -1157,7 +1163,7 @@ draw(int dummy) { | |||
| 1157 | if(term.line[y][x].state & GLYPH_SET) | 1163 | if(term.line[y][x].state & GLYPH_SET) |
| 1158 | xdrawc(x, y, term.line[y][x]); | 1164 | xdrawc(x, y, term.line[y][x]); |
| 1159 | 1165 | ||
| 1160 | xcursor(term.c.hide); | 1166 | xcursor(); |
| 1161 | XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); | 1167 | XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); |
| 1162 | XFlush(xw.dis); | 1168 | XFlush(xw.dis); |
| 1163 | } | 1169 | } |
| @@ -1193,7 +1199,7 @@ draw(int redraw_all) { | |||
| 1193 | if(i > 0) | 1199 | if(i > 0) |
| 1194 | xdraws(buf, base, ox, y, i); | 1200 | xdraws(buf, base, ox, y, i); |
| 1195 | } | 1201 | } |
| 1196 | xcursor(term.c.hide); | 1202 | xcursor(); |
| 1197 | XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); | 1203 | XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); |
| 1198 | XFlush(xw.dis); | 1204 | XFlush(xw.dis); |
| 1199 | } | 1205 | } |
