From e23d78e10249bea1f0ab221a2fa1e9b8a5b72b0b Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 24 Dec 2018 18:10:20 +0100 Subject: [PATCH] termptyesc: cpl and margins + tests --- src/bin/termptyesc.c | 37 +++++++++++++++++++++++++++---------- tests/cpl.sh | 36 ++++++++++++++++++++++++++++++++++++ tests/tests.results | 1 + 3 files changed, 64 insertions(+), 10 deletions(-) create mode 100755 tests/cpl.sh diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c index 6efc8aab..48741321 100644 --- a/src/bin/termptyesc.c +++ b/src/bin/termptyesc.c @@ -1136,6 +1136,31 @@ _handle_esc_csi_cnl(Termpty *ty, Eina_Unicode **ptr) ty->cursor_state.cx = ty->termstate.left_margin; } +static void +_handle_esc_csi_cpl(Termpty *ty, Eina_Unicode **ptr) +{ + Eina_Unicode *b = *ptr; + int arg = _csi_arg_get(ty, &b); + int max = ty->h; + + if (arg == -CSI_ARG_ERROR) + return; + if (arg < 1) + arg = 1; + + DBG("CPL - Cursor Previous Line: %d", arg); + ty->termstate.wrapnext = 0; + ty->cursor_state.cy -= arg; + if (ty->termstate.bottom_margin) + { + max = ty->termstate.bottom_margin; + } + TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, + ty->termstate.top_margin, + max); + ty->cursor_state.cx = ty->termstate.left_margin; +} + static void _handle_esc_csi_dch(Termpty *ty, Eina_Unicode **ptr, const Eina_Unicode * const end) @@ -1740,16 +1765,8 @@ CUF: case 'E': _handle_esc_csi_cnl(ty, &b); break; - case 'F': // up relative N rows, and to col 0 - arg = _csi_arg_get(ty, &b); - if (arg == -CSI_ARG_ERROR) - goto error; - TERMPTY_RESTRICT_FIELD(arg, 1, ty->h); - DBG("CPL - Cursor Previous Line: %d", arg); - ty->termstate.wrapnext = 0; - ty->cursor_state.cy -= arg; - TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h); - ty->cursor_state.cx = 0; + case 'F': + _handle_esc_csi_cpl(ty, &b); break; case 'G': // to column N arg = _csi_arg_get(ty, &b); diff --git a/tests/cpl.sh b/tests/cpl.sh new file mode 100755 index 00000000..8243784f --- /dev/null +++ b/tests/cpl.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# fill space with E +printf '\033[69;1;1;25;80$x' +#set color +printf '\033[46;31;3m' + +# move to 7; 7 +printf '\033[7;7H' +printf 'a\033[Fb' + +printf 'c\033[2Fd' +# set top/bottom margins: +printf '\033[10;20r' +# allow left/right margins +printf '\033[?69h' +# set left/right margins: +printf '\033[5;15s' +# fill margin with @ +printf '\033[64;10;5;20;15$x' + +# move +printf '\033[12;19H' +printf 'e\033[5Ff' + + + + +# set left/right margins: +printf '\033[25;35s' +# fill margin with @ +printf '\033[64;10;25;20;35$x' +# restrict cursor +printf '\033[?6h' +# move +printf '\033[2;2H' +printf 'g\033[5Fh' diff --git a/tests/tests.results b/tests/tests.results index d5e09928..94723ed6 100644 --- a/tests/tests.results +++ b/tests/tests.results @@ -33,3 +33,4 @@ decsclm.sh 1ffcea3bfc4704d9091272dc59cbb311 cha.sh 04092c42102eb0d71ae700ee47c9ac34 dch.sh 40cf655681c098251f0dc3e7733c4db9 cnl.sh 1f1512179c8e47e4bd880142774a3c66 +cpl.sh 9145c88adb762a6a59c5bf69191b949e