X-Git-Url: http://git.madism.org/?a=blobdiff_plain;ds=sidebyside;f=madtty%2Finject.c;h=f1f2e21498e3da0cda8e852b2cff20d49c23fa4b;hb=5618d7a42ce62103e5f29da3756b81f57198b22f;hp=5d1f7d792274d4575ba71d7660d7e787561be026;hpb=8f56ed8cb875b860ded79f630d439c953bc4aa4d;p=apps%2Fmadtty.git diff --git a/madtty/inject.c b/madtty/inject.c index 5d1f7d7..f1f2e21 100644 --- a/madtty/inject.c +++ b/madtty/inject.c @@ -30,14 +30,23 @@ static inline void clamp_cursor_to_bounds(RoteTerm *rt) { - if (rt->crow < 0) rt->curpos_dirty = true, rt->crow = 0; - if (rt->ccol < 0) rt->curpos_dirty = true, rt->ccol = 0; - - if (rt->crow >= rt->rows) - rt->curpos_dirty = true, rt->crow = rt->rows - 1; + if (rt->crow < 0) { + rt->curpos_dirty = true; + rt->crow = 0; + } + if (rt->ccol < 0) { + rt->curpos_dirty = true; + rt->ccol = 0; + } - if (rt->ccol >= rt->cols) - rt->curpos_dirty = true, rt->ccol = rt->cols - 1; + if (rt->crow >= rt->rows) { + rt->curpos_dirty = true; + rt->crow = rt->rows - 1; + } + if (rt->ccol >= rt->cols) { + rt->curpos_dirty = true; + rt->ccol = rt->cols - 1; + } } static void cursor_line_down(RoteTerm *rt) @@ -89,12 +98,12 @@ static void cursor_line_up(RoteTerm *rt) /* clear first row of the scrolling region */ for (i = 0; i < rt->cols; i++) { - rt->cells[rt->pd->scrolltop][i].ch = 0x20; + rt->cells[rt->pd->scrolltop][i].ch = 0x20; rt->cells[rt->pd->scrolltop][i].attr = 0x70; } } -static inline void put_normal_char(RoteTerm *rt, char c) +static inline void put_normal_char(RoteTerm *rt, int c) { if (rt->ccol >= rt->cols) { rt->ccol = 0; @@ -116,7 +125,7 @@ static inline void put_normal_char(RoteTerm *rt, char c) rt->curpos_dirty = true; } -static inline void put_graphmode_char(RoteTerm *rt, char c) +static inline void put_graphmode_char(RoteTerm *rt, int c) { char nc; /* do some very pitiful translation to regular ascii chars */ @@ -155,17 +164,19 @@ static void handle_control_char(RoteTerm *rt, int c) break; case '\n': /* line feed */ - rt->ccol = 0; cursor_line_down(rt); + rt->ccol = 0; + cursor_line_down(rt); rt->curpos_dirty = true; break; case '\b': /* backspace */ - if (rt->ccol > 0) rt->ccol--; + if (rt->ccol > 0) + rt->ccol--; rt->curpos_dirty = true; break; case '\t': /* tab */ - rt->ccol += 8 - (rt->ccol % 8); + rt->ccol = (rt->ccol + 8) & ~7; clamp_cursor_to_bounds(rt); break; @@ -197,7 +208,7 @@ static void handle_control_char(RoteTerm *rt, int c) } } -static inline bool is_valid_csi_ender(char c) +static inline bool is_valid_csi_ender(int c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') @@ -209,29 +220,8 @@ static void try_interpret_escape_seq(RoteTerm *rt) char firstchar = rt->pd->esbuf[0]; char lastchar = rt->pd->esbuf[rt->pd->esbuf_len-1]; - if (!firstchar) return; /* too early to do anything */ - - if (rt->pd->handler) { - /* call custom handler */ - - int answer = (*(rt->pd->handler))(rt, rt->pd->esbuf); - if (answer == ROTE_HANDLERESULT_OK) { - /* successfully handled */ - - cancel_escape_sequence(rt); - return; - } else - if (answer == ROTE_HANDLERESULT_NOTYET) { - /* handler might handle it when more characters are appended to - * it. So for now we don't interpret it */ - return; - } - - /* If we got here then answer == ROTE_HANDLERESULT_NOWAY */ - /* handler said it can't handle that escape sequence, - * but we can still try handling it ourselves, so - * we proceed normally. */ - } + if (!firstchar) + return; /* too early to do anything */ /* interpret ESC-M as reverse line-feed */ if (firstchar == 'M') {