diff options
| author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-08-26 23:43:08 +0200 |
|---|---|---|
| committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-08-26 23:43:08 +0200 |
| commit | 5d611cd5476b56884077120bc2a6ba9727fcdd2c (patch) | |
| tree | 06307ba2e82aeb8537fbf35e8265209fe44fb81d | |
| parent | 4db3df312ada9d92564d5580fb4e67f7704efff8 (diff) | |
| download | st-5d611cd5476b56884077120bc2a6ba9727fcdd2c.tar.gz st-5d611cd5476b56884077120bc2a6ba9727fcdd2c.zip | |
added macro to test flags, removed tmovecursor().
| -rw-r--r-- | st.c | 42 |
1 files changed, 15 insertions, 27 deletions
| @@ -34,6 +34,7 @@ | |||
| 34 | #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) | 34 | #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) |
| 35 | #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) | 35 | #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) |
| 36 | #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) | 36 | #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) |
| 37 | #define IS_SET(flag) (term.mode & flag) | ||
| 37 | 38 | ||
| 38 | /* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */ | 39 | /* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */ |
| 39 | enum { ATTR_NULL=0 , ATTR_REVERSE=1 , ATTR_UNDERLINE=2, ATTR_BOLD=4, ATTR_GFX=8 }; | 40 | enum { ATTR_NULL=0 , ATTR_REVERSE=1 , ATTR_UNDERLINE=2, ATTR_BOLD=4, ATTR_GFX=8 }; |
| @@ -128,7 +129,7 @@ static void csireset(void); | |||
| 128 | 129 | ||
| 129 | static void tclearregion(int, int, int, int); | 130 | static void tclearregion(int, int, int, int); |
| 130 | static void tcursor(int); | 131 | static void tcursor(int); |
| 131 | static void tmovecursor(int); | 132 | static void twrapcursor(void); |
| 132 | static void tdeletechar(int); | 133 | static void tdeletechar(int); |
| 133 | static void tdeleteline(int); | 134 | static void tdeleteline(int); |
| 134 | static void tinsertblank(int); | 135 | static void tinsertblank(int); |
| @@ -437,29 +438,13 @@ tmoveto(int x, int y) { | |||
| 437 | } | 438 | } |
| 438 | 439 | ||
| 439 | void | 440 | void |
| 440 | tmovecursor(int dir) { | 441 | twrapcursor(void) { |
| 441 | int xf = term.c.x, yf = term.c.y; | 442 | int y = term.c.y+1; |
| 442 | 443 | if(y > term.bot) { | |
| 443 | switch(dir) { | 444 | tmoveto(0, term.bot); |
| 444 | case CURSOR_UP: | 445 | tscroll(); |
| 445 | yf--; | 446 | } else |
| 446 | break; | 447 | tmoveto(0, y); |
| 447 | case CURSOR_DOWN: | ||
| 448 | yf++; | ||
| 449 | break; | ||
| 450 | case CURSOR_LEFT: | ||
| 451 | xf--; | ||
| 452 | break; | ||
| 453 | case CURSOR_RIGHT: | ||
| 454 | xf++; | ||
| 455 | if(term.mode & MODE_WRAP && xf >= term.col) { | ||
| 456 | xf = 0, yf++; | ||
| 457 | if(yf > term.bot) | ||
| 458 | yf = term.bot, tscroll(); | ||
| 459 | } | ||
| 460 | break; | ||
| 461 | } | ||
| 462 | tmoveto(xf, yf); | ||
| 463 | } | 448 | } |
| 464 | 449 | ||
| 465 | void | 450 | void |
| @@ -969,7 +954,7 @@ tputc(char c) { | |||
| 969 | tputtab(); | 954 | tputtab(); |
| 970 | break; | 955 | break; |
| 971 | case '\b': | 956 | case '\b': |
| 972 | tmovecursor(CURSOR_LEFT); | 957 | tmoveto(term.c.x-1, term.c.y); |
| 973 | break; | 958 | break; |
| 974 | case '\r': | 959 | case '\r': |
| 975 | tmoveto(0, term.c.y); | 960 | tmoveto(0, term.c.y); |
| @@ -986,7 +971,10 @@ tputc(char c) { | |||
| 986 | break; | 971 | break; |
| 987 | default: | 972 | default: |
| 988 | tsetchar(c); | 973 | tsetchar(c); |
| 989 | tmovecursor(CURSOR_RIGHT); | 974 | if(term.c.x+1 < term.col) { |
| 975 | tmoveto(term.c.x+1, term.c.y); | ||
| 976 | } else if(IS_SET(MODE_WRAP)) | ||
| 977 | twrapcursor(); | ||
| 990 | break; | 978 | break; |
| 991 | } | 979 | } |
| 992 | } | 980 | } |
| @@ -1282,7 +1270,7 @@ kpress(XEvent *ev) { | |||
| 1282 | case XK_Down: | 1270 | case XK_Down: |
| 1283 | case XK_Left: | 1271 | case XK_Left: |
| 1284 | case XK_Right: | 1272 | case XK_Right: |
| 1285 | sprintf(buf, "\033%c%c", term.mode & MODE_APPKEYPAD ? 'O' : '[', "DACB"[ksym - XK_Left]); | 1273 | sprintf(buf, "\033%c%c", IS_SET(MODE_APPKEYPAD) ? 'O' : '[', "DACB"[ksym - XK_Left]); |
| 1286 | ttywrite(buf, 3); | 1274 | ttywrite(buf, 3); |
| 1287 | break; | 1275 | break; |
| 1288 | case XK_Insert: | 1276 | case XK_Insert: |
