aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2019-01-02 22:41:41 +0100
committerBoris Faure <billiob@gmail.com>2019-01-02 22:41:41 +0100
commit06abd7e9bc46e2845c8389d5ccfb23f540fb0ef2 (patch)
tree54d571b7e11ba7528dd4273b52d7328a7b8d1dfc
parenttests/cursor-movements.sh: test cursor up for real (diff)
downloadterminology-06abd7e9bc46e2845c8389d5ccfb23f540fb0ef2.tar.gz
termptyesc: move ED handler to its own functions + add tests
-rw-r--r--src/bin/termptyesc.c78
-rwxr-xr-xtests/ed-0.sh55
-rwxr-xr-xtests/ed-1.sh55
-rwxr-xr-xtests/ed-2.sh55
-rwxr-xr-xtests/ed-3.sh55
-rwxr-xr-xtests/ed-4.sh55
-rw-r--r--tests/tests.results5
7 files changed, 322 insertions, 36 deletions
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index eb26b88..9551f80 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -2493,6 +2493,46 @@ _handle_esc_csi_cht(Termpty *ty, Eina_Unicode **ptr)
_tab_forward(ty, arg);
}
+static void
+_handle_esc_csi_ed(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;
+ /* 3J erases the backlog,
+ * 2J erases the screen,
+ * 1J erase from screen start to cursor,
+ * 0J erase form cursor to end of screen
+ */
+ DBG("ED/DECSED %d: erase in display", arg);
+ switch (arg)
+ {
+ case TERMPTY_CLR_END /* 0 */:
+ case TERMPTY_CLR_BEGIN /* 1 */:
+ case TERMPTY_CLR_ALL /* 2 */:
+ termpty_clear_screen(ty, arg);
+ break;
+ case 3:
+ termpty_clear_backlog(ty);
+ break;
+ default:
+ ERR("invalid EL/DECSEL argument %d", arg);
+ ty->decoding_error = EINA_TRUE;
+ }
+ TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
+}
+
+static void
+_handle_esc_csi_decsed(Termpty *ty, Eina_Unicode **ptr)
+{
+ WRN("DECSED - Selective Erase in Display: Unsupported");
+ _handle_esc_csi_ed(ty, ptr);
+}
+
static int
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
{
@@ -2557,43 +2597,9 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
break;
case 'J':
if (*b == '?')
- {
- b++;
- arg = _csi_arg_get(ty, &b);
- if (arg == -CSI_ARG_ERROR)
- goto error;
- WRN("Unsupported selected erase in display %d", arg);
- ty->decoding_error = EINA_TRUE;
- break;
- }
+ _handle_esc_csi_decsed(ty, &b);
else
- {
- arg = _csi_arg_get(ty, &b);
- if (arg == -CSI_ARG_ERROR)
- goto error;
- }
- if (arg < 1)
- arg = 0;
- /* 3J erases the backlog,
- * 2J erases the screen,
- * 1J erase from screen start to cursor,
- * 0J erase form cursor to end of screen
- */
- DBG("ED/DECSED %d: erase in display", arg);
- switch (arg)
- {
- case TERMPTY_CLR_END /* 0 */:
- case TERMPTY_CLR_BEGIN /* 1 */:
- case TERMPTY_CLR_ALL /* 2 */:
- termpty_clear_screen(ty, arg);
- break;
- case 3:
- termpty_clear_backlog(ty);
- break;
- default:
- ERR("invalid EL/DECSEL argument %d", arg);
- ty->decoding_error = EINA_TRUE;
- }
+ _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
if (*b == '?')
diff --git a/tests/ed-0.sh b/tests/ed-0.sh
new file mode 100755
index 0000000..cbfb7bb
--- /dev/null
+++ b/tests/ed-0.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+
+# fill space
+for V in $(seq 0 50); do
+ printf '%s\n' "$V"
+done
+
+# 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'
+
+# move
+printf '\033[10;30H'
+
+# ED 0 (default) (Erase from the cursor to the end)
+printf '\033[J'
diff --git a/tests/ed-1.sh b/tests/ed-1.sh
new file mode 100755
index 0000000..08b9887
--- /dev/null
+++ b/tests/ed-1.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+
+# fill space
+for V in $(seq 0 50); do
+ printf '%s\n' "$V"
+done
+
+# 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'
+
+# move
+printf '\033[10;30H'
+
+# ED 1 (Erase the beginning of the display through the cursor)
+printf '\033[1J'
diff --git a/tests/ed-2.sh b/tests/ed-2.sh
new file mode 100755
index 0000000..a3bfac0
--- /dev/null
+++ b/tests/ed-2.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+
+# fill space
+for V in $(seq 0 50); do
+ printf '%s\n' "$V"
+done
+
+# 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'
+
+# move
+printf '\033[10;30H'
+
+# ED 2 (The complete display)
+printf '\033[2J'
diff --git a/tests/ed-3.sh b/tests/ed-3.sh
new file mode 100755
index 0000000..4a88620
--- /dev/null
+++ b/tests/ed-3.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+
+# fill space
+for V in $(seq 0 50); do
+ printf '%s\n' "$V"
+done
+
+# 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'
+
+# move
+printf '\033[10;30H'
+
+# ED 3 (The display scrollback)
+printf '\033[3J'
diff --git a/tests/ed-4.sh b/tests/ed-4.sh
new file mode 100755
index 0000000..0936693
--- /dev/null
+++ b/tests/ed-4.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+
+# fill space
+for V in $(seq 0 50); do
+ printf '%s\n' "$V"
+done
+
+# 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'
+
+# move
+printf '\033[10;30H'
+
+# ED 4 nothing
+printf '\033[4J'
diff --git a/tests/tests.results b/tests/tests.results
index 5ca47af..e104152 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -52,3 +52,8 @@ decrara-no-rectangular-restrict-cursor.sh 815a848844cf7ea33d60e71948346a33
decic-decdc.sh 6d67999a7c5c771281ff2229cdbdda76
ich.sh 3bd7dfc4a7cbcdf0985cda5da46e07ec
deccra.sh 6a0846004c4effb9d5eb45b8044d5f7e
+ed-0.sh 169d09249a920f95e5c9fc517d5f90a9
+ed-1.sh 399897d5dd697adea2cc460ca6132826
+ed-2.sh 82e7919a46fdea3a003143b41562b148
+ed-3.sh 005871b7e4d63017c08a73ab34f99b14
+ed-4.sh 574f37ac24ead26ef86c03d7dfae3152