aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2018-12-31 18:25:56 +0100
committerBoris Faure <billiob@gmail.com>2019-01-01 18:10:36 +0100
commit66617198295b725844b69880879f99d57e667384 (patch)
treeedbc9ef995cbb70cab5801026f634434643f53e8
parenttermptyesc: support DECIC/DECDC + tests (diff)
downloadterminology-66617198295b725844b69880879f99d57e667384.tar.gz
termptyesc: extract ICH to its own function and add tests
-rw-r--r--src/bin/termptyesc.c70
-rwxr-xr-xtests/ich.sh103
-rw-r--r--tests/tests.results1
3 files changed, 154 insertions, 20 deletions
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 30b3d6f..5b8444e 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -2193,6 +2193,53 @@ _handle_esc_csi_decdc(Termpty *ty, Eina_Unicode **b)
}
}
+static void
+_handle_esc_csi_ich(Termpty *ty, Eina_Unicode **ptr)
+{
+ Eina_Unicode blank[1] = { ' ' };
+ Eina_Unicode *b = *ptr;
+ int arg = _csi_arg_get(ty, &b);
+ int i;
+ int old_insert = ty->termstate.insert;
+ int old_cx = ty->cursor_state.cx;
+ int max = ty->w;
+
+ if (arg == -CSI_ARG_ERROR)
+ return;
+ TERMPTY_RESTRICT_FIELD(arg, 1, ty->w * ty->h);
+
+ DBG("ICH - Insert %d Characters", arg);
+
+ if (ty->termstate.lr_margins)
+ {
+ if ((ty->termstate.left_margin)
+ && (ty->cursor_state.cx < ty->termstate.left_margin))
+ {
+ return;
+ }
+ if (ty->termstate.right_margin)
+ {
+ if (ty->cursor_state.cx >= ty->termstate.right_margin)
+ {
+ return;
+ }
+ max = ty->termstate.right_margin;
+ }
+ }
+
+ if (ty->cursor_state.cx + arg > max)
+ {
+ arg = max - ty->cursor_state.cx;
+ }
+
+ ty->termstate.wrapnext = 0;
+ ty->termstate.insert = 1;
+ for (i = 0; i < arg; i++)
+ termpty_text_append(ty, blank, 1);
+ ty->termstate.insert = old_insert;
+ ty->cursor_state.cx = old_cx;
+}
+
static int
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
{
@@ -2223,26 +2270,9 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
switch (*cc)
{
/* sorted by ascii value */
- case '@': // insert N blank chars (ICH)
- /* TODO: SL */
- arg = _csi_arg_get(ty, &b);
- if (arg == -CSI_ARG_ERROR)
- goto error;
- TERMPTY_RESTRICT_FIELD(arg, 1, ty->w * ty->h);
- DBG("insert %d blank chars", arg);
- {
- int pi = ty->termstate.insert;
- Eina_Unicode blank[1] = { ' ' };
- int cx = ty->cursor_state.cx;
-
- ty->termstate.wrapnext = 0;
- ty->termstate.insert = 1;
- for (i = 0; i < arg; i++)
- termpty_text_append(ty, blank, 1);
- ty->termstate.insert = pi;
- ty->cursor_state.cx = cx;
- TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
- }
+ case '@':
+ /* TODO: SL */
+ _handle_esc_csi_ich(ty, &b);
break;
case 'A': // cursor up N (CUU)
/* TODO: SR */
diff --git a/tests/ich.sh b/tests/ich.sh
new file mode 100755
index 0000000..42c3cfd
--- /dev/null
+++ b/tests/ich.sh
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+# move to 0; 0
+printf '\033[H'
+# 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
+
+# move to 0; 0
+printf '\033[H'
+
+#set color
+printf '\033[43;32;3m'
+
+# move
+printf '\033[3;60H'
+# insert spaces
+printf '\033[200@'
+
+# move
+printf '\033[4;12H'
+# insert spaces
+printf '\033[13@'
+
+# set top/bottom margins:
+printf '\033[3;20r'
+# allow left/right margins
+printf '\033[?69h'
+# set left/right margins:
+printf '\033[5;75s'
+
+# move
+printf '\033[20;70H'
+# insert spaces
+printf '\033[200@'
+
+# move
+printf '\033[0;70H'
+# insert spaces
+printf '\033[200@'
+
+# move
+printf '\033[2;4H'
+# do not insert spaces, out of left/right margins
+printf '\033[200@'
+
+# move
+printf '\033[2;76H'
+# do not insert spaces, out of left/right margins
+printf '\033[200@'
+
+
+# move
+printf '\033[7;5H'
+# insert spaces
+printf '\033[20@'
+
+# move
+printf '\033[7;75H'
+# insert spaces
+printf '\033[20@'
+
+# WITH MARGINS ENFORCED
+
+# set top/bottom margins:
+printf '\033[3;10r'
+# allow left/right margins
+printf '\033[?69h'
+# set left/right margins:
+printf '\033[5;60s'
+
+# restrict cursor
+printf '\033[?6h'
+
+
+# move
+printf '\033[8;50H'
+# insert spaces
+printf '\033[200@'
diff --git a/tests/tests.results b/tests/tests.results
index a06e713..324b8ea 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -50,3 +50,4 @@ decrara-rectangular-restrict-cursor.sh e98723f8f749e4902f7f4aaa677b85d6
decrara-no-rectangular-no-restrict-cursor.sh c375dd5d6538aff4c920b022f32f4ab0
decrara-no-rectangular-restrict-cursor.sh 815a848844cf7ea33d60e71948346a33
decic-decdc.sh 6d67999a7c5c771281ff2229cdbdda76
+ich.sh fe1bfee25582f37a27665af1f66513df