aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2019-01-01 18:53:46 +0100
committerBoris Faure <billiob@gmail.com>2019-01-01 18:53:46 +0100
commiteb84e538b172487dfaf9d80051e2ff24372d1250 (patch)
treef625046c95f4884aec8dcd0bd974a3dc7e5b201f /src
parenttermptyesc: move CUU/CUD handlers to their own functions (diff)
downloadterminology-eb84e538b172487dfaf9d80051e2ff24372d1250.tar.gz
termptyesc: move CUF/CUB handlers to their own functions
Diffstat (limited to 'src')
-rw-r--r--src/bin/termptyesc.c82
1 files changed, 49 insertions, 33 deletions
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index e1bd1b8..2ab39b8 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -2409,6 +2409,48 @@ _handle_esc_csi_cud(Termpty *ty, Eina_Unicode **ptr)
}
}
+static void
+_handle_esc_csi_cuf(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 = 1;
+ DBG("CUF - Cursor Forward %d", arg);
+ ty->termstate.wrapnext = 0;
+ ty->cursor_state.cx += arg;
+ TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
+ if (ty->termstate.restrict_cursor && (ty->termstate.right_margin != 0)
+ && (ty->cursor_state.cx >= ty->termstate.right_margin))
+ {
+ ty->cursor_state.cx = ty->termstate.right_margin - 1;
+ }
+}
+
+static void
+_handle_esc_csi_cub(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 = 1;
+ DBG("CUB - Cursor Backward %d", arg);
+ ty->termstate.wrapnext = 0;
+ ty->cursor_state.cx -= arg;
+ TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
+ if (ty->termstate.restrict_cursor && (ty->termstate.left_margin != 0)
+ && (ty->cursor_state.cx < ty->termstate.left_margin))
+ {
+ ty->cursor_state.cx = ty->termstate.left_margin;
+ }
+}
+
static int
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
{
@@ -2447,41 +2489,14 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
/* TODO: SR */
_handle_esc_csi_cuu(ty, &b);
break;
- case 'B': // cursor down N (CUD)
+ case 'B':
_handle_esc_csi_cud(ty, &b);
break;
- case 'C': // cursor right N
-CUF:
- arg = _csi_arg_get(ty, &b);
- if (arg == -CSI_ARG_ERROR)
- goto error;
- if (arg < 1)
- arg = 1;
- DBG("cursor right %d", arg);
- ty->termstate.wrapnext = 0;
- ty->cursor_state.cx += arg;
- TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
- if (ty->termstate.restrict_cursor && (ty->termstate.right_margin != 0)
- && (ty->cursor_state.cx >= ty->termstate.right_margin))
- {
- ty->cursor_state.cx = ty->termstate.right_margin - 1;
- }
+ case 'C':
+ _handle_esc_csi_cuf(ty, &b);
break;
- case 'D': // cursor left N (CUB)
- arg = _csi_arg_get(ty, &b);
- if (arg == -CSI_ARG_ERROR)
- goto error;
- if (arg < 1)
- arg = 1;
- DBG("cursor left %d", arg);
- ty->termstate.wrapnext = 0;
- ty->cursor_state.cx -= arg;
- TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
- if (ty->termstate.restrict_cursor && (ty->termstate.left_margin != 0)
- && (ty->cursor_state.cx < ty->termstate.left_margin))
- {
- ty->cursor_state.cx = ty->termstate.left_margin;
- }
+ case 'D':
+ _handle_esc_csi_cub(ty, &b);
break;
case 'E':
_handle_esc_csi_cnl(ty, &b);
@@ -2695,7 +2710,8 @@ CUF:
}
break;
case 'a': // cursor right N (HPR)
- goto CUF;
+ _handle_esc_csi_cuf(ty, &b);
+ break;
case 'b': // repeat last char
if (ty->last_char)
{