From 19a99dadfffbc5a83eeb2df14913bbdd0af78419 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Fri, 28 Dec 2018 23:11:54 +0100 Subject: [PATCH] termptyesc: support DECFI Introduce different behaviour from xterm as I don't see why it behaves like that when outside of left/right margin and on right border. Xterm does not wrap. --- src/bin/termptyesc.c | 64 ++++++++++++++++++++++++++++++++- tests/decbi.sh | 2 +- tests/decfi.sh | 86 ++++++++++++++++++++++++++++++++++++++++++++ tests/tests.results | 1 + 4 files changed, 151 insertions(+), 2 deletions(-) create mode 100755 tests/decfi.sh diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c index 8f178f10..814f4e7c 100644 --- a/src/bin/termptyesc.c +++ b/src/bin/termptyesc.c @@ -2827,7 +2827,7 @@ _handle_decbi(Termpty *ty) ty->cursor_state.cx = old_cx; ty->cursor_state.cy = old_cy; } - else + else { if ((ty->cursor_state.cx == 0) && (ty->termstate.lr_margins != 0)) return; @@ -2836,6 +2836,65 @@ _handle_decbi(Termpty *ty) } } +static void +_handle_decfi(Termpty *ty) +{ + DBG("DECFI - Forward Index"); + if ((ty->cursor_state.cx == ty->w - 1) + || ((ty->termstate.right_margin > 0) + && (ty->cursor_state.cx == ty->termstate.right_margin - 1))) + { + int y; + int max_x = ty->w - 1; + int max_y = ty->h; + + if (((ty->termstate.lr_margins != 0) + && (ty->cursor_state.cx == ty->w - 1)) + || ((ty->termstate.top_margin != 0) + && (ty->cursor_state.cy < ty->termstate.top_margin)) + || ((ty->termstate.bottom_margin != 0) + && (ty->cursor_state.cy >= ty->termstate.bottom_margin))) + { + return; + } + if (ty->termstate.bottom_margin != 0) + max_y = ty->termstate.bottom_margin; + if (ty->termstate.right_margin != 0) + max_x = ty->termstate.right_margin - 1; + + for (y = ty->termstate.top_margin; y < max_y; y++) + { + int x; + Termcell *cells = &(TERMPTY_SCREEN(ty, 0, y)); + + for (x = ty->termstate.left_margin; x <= max_x; x++) + { + if (x < max_x) + TERMPTY_CELL_COPY(ty, &(cells[x + 1]), &(cells[x]), 1); + else + { + cells[x].codepoint = ' '; + if (EINA_UNLIKELY(cells[x].att.link_id)) + term_link_refcount_dec(ty, cells[x].att.link_id, 1); + cells[x].att = ty->termstate.att; + cells[x].att.link_id = 0; + cells[x].att.dblwidth = 0; + } + } + } + } + else + { + if ((ty->cursor_state.cx == ty->w - 1) + && (ty->termstate.lr_margins != 0)) + return; + ERR("ty->cursor_state.cx=%d", ty->cursor_state.cx); + ERR("ty->cursor_state.cy=%d", ty->cursor_state.cy); + /* cursor forward */ + ty->cursor_state.cx++; + } +} + static int _handle_esc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) { @@ -2939,6 +2998,9 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) case '8': // restore cursor pos termpty_cursor_copy(ty, EINA_FALSE); return 1; + case '9': + _handle_decfi(ty); + return 1; case 'H': // set tab at current column DBG("Character Tabulation Set (HTS) at x:%d", ty->cursor_state.cx); TAB_SET(ty, ty->cursor_state.cx); diff --git a/tests/decbi.sh b/tests/decbi.sh index 3c06f43f..1c67bea5 100755 --- a/tests/decbi.sh +++ b/tests/decbi.sh @@ -29,7 +29,7 @@ printf '\033[5;22r' # move to printf '\033[4;0H' -# decbi, not within top/right margin, do nothing +# decbi, not within top/bottom margin, do nothing printf '\033\066b' # move to 3; 0 printf '\033[6;0H' diff --git a/tests/decfi.sh b/tests/decfi.sh new file mode 100755 index 00000000..bcad3823 --- /dev/null +++ b/tests/decfi.sh @@ -0,0 +1,86 @@ +#!/bin/sh + +# move to 0; 0 +printf '\033[H' +# fill space +for _ in $(seq 0 23); do + for _ in $(seq 0 7); do + printf '\-/|\\~_>^<' + done +done + +# move to 0; 0 +printf '\033[H' + +#set color +printf '\033[46;31;3m' + +printf ' format is:\n \-/|\\~_>^<' + +# move to +printf '\033[3;81H' +# decfi, insert column +printf '\033\071a' + +# set top/bottom margins: +printf '\033[5;22r' + +# move to +printf '\033[4;81H' +# decfi, not within top/bottom margin, do nothing +printf '\033\071b' +# move to 3; 0 +printf '\033[6;81H' +# decfi, insert column within margins +printf 'C\033\071c' + + +# set top/bottom margins: +printf '\033[10;20r' +# allow left/right margins +printf '\033[?69h' + +# move +printf '\033[7;81H' +# decfi, do nothing +printf 'D\033\071d' + +# set right margin only +printf '\033[;14s' + +# move +printf '\033[8;81H' +# decfi, do nothing. Xterm seems change wrapping here. I don't see why +printf 'E\033\071e' + + +# set left/right margins: +printf '\033[5;14s' +# move to 0; 0 +printf '\033[10;5H' +# fill space +for Y in $(seq 10 20); do + # move to 0; 0 + printf '\033[%s;5H' "$Y" + printf '\-/|\\~_>^<' +done + +# move +printf '\033[11;81H' +# decfi, do nothing. Xterm seems change wrapping here. I don't see why +printf 'f\033\071g' + +# move +printf '\033[12;12H' +#decfi, outside right margin, cursor forward +printf 'h\033\071i' + +# move +printf '\033[13;3H' +#decfi, outside right margin, cursor forward +printf '\033\071j' + +# move +printf '\033[14;14H' +#decfi, on left margin, insert column +printf '\033\071k' diff --git a/tests/tests.results b/tests/tests.results index aea16ebf..55777059 100644 --- a/tests/tests.results +++ b/tests/tests.results @@ -38,3 +38,4 @@ cup.sh 11f5939a6cc990f6a7b9d1730ab3a8bf decaln.sh 9c0cf4de336193bcdaed6ba6c0d6f590 decawm.sh 84321e76f07b40cf9462238ec0919dc0 decbi.sh 8153bff12a0d529cb8ba0dbff036a1ee +decfi.sh e93690447902b923d3d9d2ae72a31de4