aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2018-12-17 23:03:19 +0100
committerBoris Faure <billiob@gmail.com>2018-12-27 22:14:44 +0100
commit4b32aec0ed7644f9982cf6d0b6742fb716bb23bb (patch)
tree065d0b3e9d959a7e81e3a73c42007c7364cb9277
parentcol: assert in case of invalid values (diff)
downloadterminology-4b32aec0ed7644f9982cf6d0b6742fb716bb23bb.tar.gz
termptyesc: DCH shall handle margins. space created follows SGR + test
-rw-r--r--src/bin/termptyesc.c74
-rwxr-xr-xtests/dch.sh100
-rw-r--r--tests/tests.results1
3 files changed, 148 insertions, 27 deletions
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 45bc0fc..c694f86 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -1112,6 +1112,52 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr,
}
static void
+_handle_esc_csi_dch(Termpty *ty, Eina_Unicode **ptr,
+ const Eina_Unicode * const end)
+{
+ Eina_Unicode *b = *ptr;
+ int arg = _csi_arg_get(ty, &b);
+ Termcell *cells;
+ int x, lim, max;
+
+ if (arg == -CSI_ARG_ERROR)
+ return;
+
+ DBG("DCH - Delete Character: %d chars", arg);
+
+ cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
+ max = ty->w;
+ if (ty->termstate.left_margin)
+ {
+ if (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;
+ }
+ TERMPTY_RESTRICT_FIELD(arg, 1, max + 1);
+ lim = max - arg;
+ for (x = ty->cursor_state.cx; x < max; x++)
+ {
+ if (x < lim)
+ TERMPTY_CELL_COPY(ty, &(cells[x + arg]), &(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;
+ }
+ }
+}
+
+
+static void
_handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
{
int arg, len;
@@ -1819,33 +1865,7 @@ CUF:
}
break;
case 'P': // erase and scrollback N chars
- arg = _csi_arg_get(ty, &b);
- if (arg == -CSI_ARG_ERROR)
- goto error;
- TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
- DBG("DCH - Delete Character: %d chars", arg);
- {
- Termcell *cells;
- int x, lim;
-
- cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
- lim = ty->w - arg;
- for (x = ty->cursor_state.cx; x < (ty->w); x++)
- {
- if (x < lim)
- TERMPTY_CELL_COPY(ty, &(cells[x + arg]), &(cells[x]), 1);
- else
- {
- cells[x].codepoint = ' ';
- cells[x].att.underline = 0;
- cells[x].att.blink = 0;
- cells[x].att.blink2 = 0;
- cells[x].att.inverse = 0;
- cells[x].att.strike = 0;
- cells[x].att.dblwidth = 0;
- }
- }
- }
+ _handle_esc_csi_dch(ty, &b, be);
break;
case 'S': // scroll up N lines
arg = _csi_arg_get(ty, &b);
diff --git a/tests/dch.sh b/tests/dch.sh
new file mode 100755
index 0000000..6712f97
--- /dev/null
+++ b/tests/dch.sh
@@ -0,0 +1,100 @@
+#!/bin/sh
+
+# move to 0; 0
+printf '\033[H'
+# fill space
+for Y in $(seq 0 23); do
+ for X in $(seq 0 7); do
+ printf '\-/|\\~_>^<'
+ done
+done
+# move to 0; 0
+printf '\033[H'
+
+#set color
+printf '\033[46;31;3m'
+
+# move to 2; 1
+printf '\033[2;1H'
+# remove one char
+printf '\033[P'
+# move to 3; 1
+printf '\033[3;1H'
+# remove 8 chars
+printf '\033[8P'
+# move to 4; 1
+printf '\033[4;1H'
+# remove too many chars
+printf '\033[888P'
+
+
+# allow left/right margins
+printf '\033[?69h'
+# set left/right margins:
+printf '\033[5;22s'
+
+# outside margins
+# move to 5; 2
+printf '\033[5;5H'
+# remove one char
+printf '\033[P'
+# move to 6; 2
+printf '\033[6;2H'
+# remove 8 chars
+printf '\033[8P'
+# move to 7; 2
+printf '\033[7;2H'
+# remove too many chars
+printf '\033[888P'
+
+# outside margins
+# move to 8; 22
+printf '\033[8;22H'
+# remove one char
+printf '\033[P'
+# move to 9; 2
+printf '\033[9;27H'
+# remove 8 chars
+printf '\033[8P'
+# move to 10; 2
+printf '\033[10;27H'
+# remove too many chars
+printf '\033[888P'
+
+# inside margins
+# move to 11; 2
+printf '\033[11;7H'
+# remove one char
+printf '\033[P'
+# move to 12; 2
+printf '\033[12;7H'
+# remove 8 chars
+printf '\033[8P'
+# move to 13; 2
+printf '\033[13;7H'
+# remove too many chars
+printf '\033[888P'
+
+# restrict cursor
+printf '\033[?6h'
+
+# inside margins
+# move to 14; 2
+printf '\033[14;2H'
+# remove one char
+printf '\033[P'
+# move to 15; 2
+printf '\033[15;2H'
+# remove 8 chars
+printf '\033[8P'
+# move to 16; 2
+printf '\033[16;2H'
+# remove too many chars
+printf '\033[888P'
+
+#remove margins
+printf '\033[?69l'
+# move to 20; 41
+printf '\033[20;41H'
+# remove 40 chars
+printf '\033[40P'
diff --git a/tests/tests.results b/tests/tests.results
index 657cece..33f9a43 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -31,3 +31,4 @@ sgr-truecolors.sh 9db4becc728bb9f1730f3573dc7fc668
sgr-long.sh ec0425b1daabaa59096c10939e79b105
decsclm.sh 1ffcea3bfc4704d9091272dc59cbb311
cha.sh 04092c42102eb0d71ae700ee47c9ac34
+dch.sh 40cf655681c098251f0dc3e7733c4db9