summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2017-06-05 01:04:24 +0200
committerBoris Faure <billiob@gmail.com>2017-06-05 01:04:24 +0200
commit7d497c08c6ea74450c153d5fd9431e8412dd7454 (patch)
treec57e68048d1e4f92e0c4fefb09a97907dbc83a2d
parenta168dc6645d0302b56259e6ac424cace6e9d44df (diff)
termptyesc: extract handling CUP/HVP to one function
-rw-r--r--src/bin/termptyesc.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 35183f8..c808669 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -825,6 +825,28 @@ bad:
825 ty->termstate.bottom_margin = 0; 825 ty->termstate.bottom_margin = 0;
826} 826}
827 827
828static void
829_handle_esc_csi_cursor_pos_set(Termpty *ty, Eina_Unicode **b,
830 const Eina_Unicode *cc)
831{
832 int cx = 0, cy = 0;
833 ty->termstate.wrapnext = 0;
834 cy = _csi_arg_get(b);
835 cx = _csi_arg_get(b);
836
837 DBG("cursor pos set (%s) (%d;%d)", (*cc == 'H') ? "CUP" : "HVP",
838 cx, cy);
839 cx--;
840 cy--;
841 TERMPTY_RESTRICT_FIELD(cx, 0, ty->w);
842 if (ty->termstate.restrict_cursor)
843 cy += ty->termstate.top_margin;
844 TERMPTY_RESTRICT_FIELD(cy, 0, ty->h);
845
846 ty->cursor_state.cx = cx;
847 ty->cursor_state.cy = cy;
848}
849
828static int 850static int
829_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce) 851_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
830{ 852{
@@ -920,31 +942,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
920 break; 942 break;
921 case 'H': // cursor pos set (CUP) 943 case 'H': // cursor pos set (CUP)
922 case 'f': // cursor pos set (HVP) 944 case 'f': // cursor pos set (HVP)
923 DBG("cursor pos set (%s)", (*cc == 'H') ? "CUP" : "HVP"); 945 _handle_esc_csi_cursor_pos_set(ty, &b, cc);
924 ty->termstate.wrapnext = 0;
925 if (!*b)
926 {
927 ty->cursor_state.cx = 0;
928 ty->cursor_state.cy = 0;
929 }
930 else
931 {
932 arg = _csi_arg_get(&b);
933 if (arg < 1) arg = 1;
934 arg--;
935 if (arg >= ty->h) arg = ty->h - 1;
936 ty->cursor_state.cy = arg;
937
938 arg = _csi_arg_get(&b);
939 if (arg < 1) arg = 1;
940 arg--;
941 if (arg >= ty->w) arg = ty->w - 1;
942 ty->cursor_state.cx = arg;
943 }
944 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
945 if (ty->termstate.restrict_cursor)
946 ty->cursor_state.cy += ty->termstate.top_margin;
947 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
948 break; 946 break;
949 case 'G': // to column N 947 case 'G': // to column N
950 arg = _csi_arg_get(&b); 948 arg = _csi_arg_get(&b);
@@ -983,7 +981,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
983 case 'X': // erase N chars 981 case 'X': // erase N chars
984 arg = _csi_arg_get(&b); 982 arg = _csi_arg_get(&b);
985 TERMPTY_RESTRICT_FIELD(arg, 1, ty->w); 983 TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
986 DBG("erase %d chars", arg); 984 DBG("ECH: erase %d chars", arg);
987 termpty_clear_line(ty, TERMPTY_CLR_END, arg); 985 termpty_clear_line(ty, TERMPTY_CLR_END, arg);
988 break; 986 break;
989 case 'S': // scroll up N lines 987 case 'S': // scroll up N lines