aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2019-01-02 23:32:38 +0100
committerBoris Faure <billiob@gmail.com>2019-01-02 23:32:38 +0100
commit0ca634cd698006eba8f9235fc0e6df4df14c7f90 (patch)
tree52dab7e655fea55c13140df215aaaf7802f7139b
parenttermptyesc: move ED handler to its own functions + add tests (diff)
downloadterminology-0ca634cd698006eba8f9235fc0e6df4df14c7f90.tar.gz
termptyesc: export EL handler to its own function + add tests
-rw-r--r--src/bin/termptyesc.c62
-rw-r--r--src/bin/termptyops.h6
-rwxr-xr-xtests/el.sh74
-rw-r--r--tests/tests.results1
4 files changed, 113 insertions, 30 deletions
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 9551f80..b70fe89 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -2533,6 +2533,37 @@ _handle_esc_csi_decsed(Termpty *ty, Eina_Unicode **ptr)
_handle_esc_csi_ed(ty, ptr);
}
+static void
+_handle_esc_csi_el(Termpty *ty, Eina_Unicode **ptr)
+{
+ Eina_Unicode *b = *ptr;
+ int arg = _csi_arg_get(ty, &b);
+
+ if (arg == -CSI_ARG_ERROR)
+ return;
+ if (arg < 1)
+ arg = 0;
+ DBG("EL - Erase in Line: %d", arg);
+ switch (arg)
+ {
+ case TERMPTY_CLR_END:
+ case TERMPTY_CLR_BEGIN:
+ case TERMPTY_CLR_ALL:
+ termpty_clear_line(ty, arg, ty->w);
+ break;
+ default:
+ ERR("invalid EL/DECSEL argument %d", arg);
+ ty->decoding_error = EINA_TRUE;
+ }
+}
+
+static void
+_handle_esc_csi_decsel(Termpty *ty, Eina_Unicode **ptr)
+{
+ WRN("DECSEL - Selective Erase in Line: Unsupported");
+ _handle_esc_csi_el(ty, ptr);
+}
+
static int
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
{
@@ -2601,34 +2632,11 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
else
_handle_esc_csi_ed(ty, &b);
break;
- case 'K': // 0K erase to end of line, 1K erase from screen start to cursor, 2K erase all of line
+ case 'K':
if (*b == '?')
- {
- b++;
- arg = _csi_arg_get(ty, &b);
- if (arg == -CSI_ARG_ERROR)
- goto error;
- WRN("Unsupported selected erase in line %d", arg);
- ty->decoding_error = EINA_TRUE;
- break;
- }
- arg = _csi_arg_get(ty, &b);
- if (arg == -CSI_ARG_ERROR)
- goto error;
- if (arg < 1)
- arg = 0;
- DBG("EL/DECSEL %d: erase in line", arg);
- switch (arg)
- {
- case TERMPTY_CLR_END:
- case TERMPTY_CLR_BEGIN:
- case TERMPTY_CLR_ALL:
- termpty_clear_line(ty, arg, ty->w);
- break;
- default:
- ERR("invalid EL/DECSEL argument %d", arg);
- ty->decoding_error = EINA_TRUE;
- }
+ _handle_esc_csi_decsel(ty, &b);
+ else
+ _handle_esc_csi_el(ty, &b);
break;
case 'L': // insert N lines - cy
EINA_FALLTHROUGH;
diff --git a/src/bin/termptyops.h b/src/bin/termptyops.h
index 48cbc0a..dd5bd1d 100644
--- a/src/bin/termptyops.h
+++ b/src/bin/termptyops.h
@@ -3,9 +3,9 @@
typedef enum _Termpty_Clear
{
- TERMPTY_CLR_END,
- TERMPTY_CLR_BEGIN,
- TERMPTY_CLR_ALL
+ TERMPTY_CLR_END = 0,
+ TERMPTY_CLR_BEGIN = 1,
+ TERMPTY_CLR_ALL = 2
} Termpty_Clear;
void termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max);
diff --git a/tests/el.sh b/tests/el.sh
new file mode 100755
index 0000000..9587727
--- /dev/null
+++ b/tests/el.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+# fill space
+PL=0
+for _ in $(seq 0 23); do
+ PL=$((PL+1))
+ if [ $PL -ge 9 ] ; then
+ PL=0
+ fi
+ for _ in $(seq 1 $PL); do
+ printf '#'
+ done
+ PR=$((10 - PL))
+ for _ in $(seq 0 6); do
+ printf '\033[0;1m\-'
+ printf '\033[0;46;1;4m/'
+ printf '\033[0;46;1;4m|'
+ printf '\033[0;1;4;7m\\'
+ printf '\033[0m~'
+ printf '\033[0;1m_'
+ printf '\033[0;31;7m>'
+ printf '\033[0;31;4;7m^'
+ printf '\033[0;1;7m<'
+ done
+ printf '\033[0m'
+ for _ in $(seq 1 $PR); do
+ printf '#'
+ done
+done
+
+
+# set color
+printf '\033[43;32;3m'
+
+# set top/bottom margins:
+printf '\033[3;20r'
+# allow left/right margins
+printf '\033[?69h'
+# set left/right margins:
+printf '\033[5;75s'
+
+# restrict cursor
+printf '\033[?6h'
+
+printf '\033[3;30H#'
+# move
+printf '\033[4;30H#\033[4;30H'
+# EL 0 -> Erase Line Right
+printf '\033[0K'
+# move
+printf '\033[5;30H#\033[5;30H'
+# EL 0 (default) -> Erase Line Right
+printf '\033[K'
+
+printf '\033[6;30H#'
+
+# move
+printf '\033[7;30H#\033[7;30H'
+# EL 1 -> Erase Line Left
+printf '\033[1K'
+
+printf '\033[8;30H#'
+
+# move
+printf '\033[9;30H#\033[9;30H'
+# EL 2 -> Erase Complete Line
+printf '\033[2K'
+
+printf '\033[10;30H#'
+
+# move
+printf '\033[11;30H#\033[11;30H'
+# EL 3 -> Nothing
+printf '\033[3K'
diff --git a/tests/tests.results b/tests/tests.results
index e104152..e064dae 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -57,3 +57,4 @@ ed-1.sh 399897d5dd697adea2cc460ca6132826
ed-2.sh 82e7919a46fdea3a003143b41562b148
ed-3.sh 005871b7e4d63017c08a73ab34f99b14
ed-4.sh 574f37ac24ead26ef86c03d7dfae3152
+el.sh abca9d5e5990bed6bd72a7ab9f72b849