From 6315ed294985d87722cb58d4f76822472653a8cf Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 21 Aug 2017 23:46:28 +0200 Subject: [PATCH 1/3] termpty: remove termstate.had_cr since it's unused --- src/bin/termpty.c | 1 - src/bin/termpty.h | 1 - src/bin/termptyesc.c | 25 +------------------------ src/bin/termptyops.c | 1 - 4 files changed, 1 insertion(+), 27 deletions(-) diff --git a/src/bin/termpty.c b/src/bin/termpty.c index 66bee834..7a355c01 100644 --- a/src/bin/termpty.c +++ b/src/bin/termpty.c @@ -1332,7 +1332,6 @@ termpty_resize(Termpty *ty, int new_w, int new_h) ty->w = new_w; ty->h = new_h; - ty->termstate.had_cr = 0; ty->termstate.wrapnext = 0; if (altbuf) diff --git a/src/bin/termpty.h b/src/bin/termpty.h index 30742c00..64ad99a4 100644 --- a/src/bin/termpty.h +++ b/src/bin/termpty.h @@ -146,7 +146,6 @@ struct _Termpty unsigned int wrap : 1; unsigned int wrapnext : 1; unsigned int crlf : 1; - unsigned int had_cr : 1; unsigned int send_bs : 1; unsigned int kbd_lock : 1; unsigned int reverse : 1; diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c index a62e823a..d2ca4fd2 100644 --- a/src/bin/termptyesc.c +++ b/src/bin/termptyesc.c @@ -156,12 +156,10 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc) switch (*cc) { case 0x07: // BEL '\a' (bell) - ty->termstate.had_cr = 0; if (ty->cb.bell.func) ty->cb.bell.func(ty->cb.bell.data); return; case 0x08: // BS '\b' (backspace) DBG("->BS"); - ty->termstate.had_cr = 0; ty->termstate.wrapnext = 0; ty->cursor_state.cx--; TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w); @@ -169,18 +167,11 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc) case 0x09: // HT '\t' (horizontal tab) DBG("->HT"); _tab_forward(ty, 1); - ty->termstate.had_cr = 0; return; case 0x0a: // LF '\n' (new line) case 0x0b: // VT '\v' (vertical tab) case 0x0c: // FF '\f' (form feed) DBG("->LF"); - if (ty->termstate.had_cr) - { - TERMPTY_SCREEN(ty, ty->termstate.had_cr_x, - ty->termstate.had_cr_y).att.newline = 1; - } - ty->termstate.had_cr = 0; ty->termstate.wrapnext = 0; if (ty->termstate.crlf) ty->cursor_state.cx = 0; ty->cursor_state.cy++; @@ -195,7 +186,6 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc) ty->termstate.wrapnext = 0; } ty->cursor_state.cx = 0; -// ty->termstate.had_cr = 1; return; default: return; @@ -2083,7 +2073,6 @@ termpty_handle_seq(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) /* case 0x05: // ENQ (enquiry) _term_txt_write(ty, "ABC\r\n"); - ty->termstate.had_cr = 0; return 1; */ /* @@ -2101,13 +2090,11 @@ termpty_handle_seq(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) return 1; case 0x0e: // SO (shift out) // Maps G1 character set into GL. - ty->termstate.had_cr = 0; ty->termstate.charset = 1; ty->termstate.charsetch = ty->termstate.chset[1]; return 1; case 0x0f: // SI (shift in) // Maps G0 character set into GL. ty->termstate.charset = 0; - ty->termstate.had_cr = 0; ty->termstate.charsetch = ty->termstate.chset[0]; return 1; /* @@ -2135,7 +2122,6 @@ termpty_handle_seq(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) return 1; */ case 0x1b: // ESC (escape) - ty->termstate.had_cr = 0; len = _handle_esc(ty, c + 1, ce); if (len == 0) return 0; return 1 + len; @@ -2150,20 +2136,17 @@ termpty_handle_seq(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) return 1; */ default: - ty->termstate.had_cr = 0; //ERR("unhandled char 0x%02x", c[0]); return 1; } } else if (c[0] == 0x7f) // DEL { - ty->termstate.had_cr = 0; WRN("Unhandled char 0x%02x [DEL]", (unsigned int) c[0]); return 1; } else if (c[0] == 0x9b) // ANSI ESC!!! { - ty->termstate.had_cr = 0; DBG("ANSI CSI!!!!!"); len = _handle_esc_csi(ty, c + 1, ce); if (len == 0) return 0; @@ -2173,8 +2156,7 @@ termpty_handle_seq(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) { Termexp *ex; Eina_List *l; - - ty->termstate.had_cr = 0; + EINA_LIST_FOREACH(ty->block.expecting, l, ex) { if (c[0] == ex->ch) @@ -2206,10 +2188,6 @@ termpty_handle_seq(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) termpty_text_append(ty, c, 1); return 1; } - else - { - ty->termstate.had_cr = 0; - } cc = (Eina_Unicode *)c; DBG("txt: ["); while ((cc < ce) && (*cc >= 0x20) && (*cc != 0x7f)) @@ -2220,6 +2198,5 @@ termpty_handle_seq(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) } DBG("]"); termpty_text_append(ty, c, len); - ty->termstate.had_cr = 0; return len; } diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c index 4a005886..f4fb345c 100644 --- a/src/bin/termptyops.c +++ b/src/bin/termptyops.c @@ -439,7 +439,6 @@ termpty_reset_state(Termpty *ty) ty->termstate.wrap = 1; ty->termstate.wrapnext = 0; ty->termstate.crlf = 0; - ty->termstate.had_cr = 0; ty->termstate.send_bs = 0; ty->termstate.reverse = 0; ty->termstate.no_autorepeat = 0; From 7c358c3592f01346d555c38daf01f34bcda9f545 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Tue, 22 Aug 2017 20:51:20 +0200 Subject: [PATCH 2/3] termptyesc: correctly handle going to start of line when there is a left margin --- src/bin/termptyesc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c index d2ca4fd2..c71a8939 100644 --- a/src/bin/termptyesc.c +++ b/src/bin/termptyesc.c @@ -150,6 +150,12 @@ _tab_forward(Termpty *ty, int n) TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w); } +static void +_cursor_to_start_of_line(Termpty *ty) +{ + ty->cursor_state.cx = ty->termstate.left_margin; +} + static void _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc) { @@ -173,7 +179,8 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc) case 0x0c: // FF '\f' (form feed) DBG("->LF"); ty->termstate.wrapnext = 0; - if (ty->termstate.crlf) ty->cursor_state.cx = 0; + if (ty->termstate.crlf) + _cursor_to_start_of_line(ty); ty->cursor_state.cy++; termpty_text_scroll_test(ty, EINA_TRUE); return; @@ -185,7 +192,7 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc) ty->termstate.had_cr_y = ty->cursor_state.cy; ty->termstate.wrapnext = 0; } - ty->cursor_state.cx = 0; + _cursor_to_start_of_line(ty); return; default: return; From 0478a36799d3b4a2050f67486e1649045d9f46c8 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Tue, 22 Aug 2017 22:08:11 +0200 Subject: [PATCH 3/3] termptyops.c: fix scrolling wrt bottom margin Thanks to @ncim for the report --- src/bin/termptyops.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c index f4fb345c..ba7bbf19 100644 --- a/src/bin/termptyops.c +++ b/src/bin/termptyops.c @@ -134,8 +134,17 @@ termpty_text_scroll_test(Termpty *ty, Eina_Bool clear) { int e = ty->h; - if (ty->termstate.bottom_margin != 0) e = ty->termstate.bottom_margin; - if (ty->cursor_state.cy >= e) + if (ty->termstate.bottom_margin != 0) + { + e = ty->termstate.bottom_margin; + if (ty->cursor_state.cy == e) + { + termpty_text_scroll(ty, clear); + ty->cursor_state.cy = e - 1; + TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h); + } + } + else if (ty->cursor_state.cy >= ty->h) { termpty_text_scroll(ty, clear); ty->cursor_state.cy = e - 1;