aboutsummaryrefslogtreecommitdiffstats
path: root/src
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 /src
parenttermptyesc: support DECIC/DECDC + tests (diff)
downloadterminology-66617198295b725844b69880879f99d57e667384.tar.gz
termptyesc: extract ICH to its own function and add tests
Diffstat (limited to 'src')
-rw-r--r--src/bin/termptyesc.c70
1 files changed, 50 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 */