separate "termstate" from cursor state and screens. Closes T725

terminology-0.9
Boris Faure 9 years ago
parent caf4e92302
commit be62d87f89
  1. 14
      src/bin/keyin.c
  2. 2
      src/bin/miniview.c
  3. 8
      src/bin/termio.c
  4. 52
      src/bin/termpty.c
  5. 54
      src/bin/termpty.h
  6. 2
      src/bin/termptydbl.c
  7. 417
      src/bin/termptyesc.c
  8. 6
      src/bin/termptygfx.c
  9. 2
      src/bin/termptygfx.h
  10. 173
      src/bin/termptyops.c
  11. 2
      src/bin/termptyops.h

@ -69,8 +69,8 @@ _key_try(Termpty *ty, const Tty_Key *map, int len, const Evas_Event_Key_Down *ev
const struct _s *s = NULL;
const Key_Values *kv;
if (!ty->state.appcursor) kv = &map[i].default_mode;
else kv = &map[i].cursor;
if (!ty->termstate.appcursor) kv = &map[i].default_mode;
else kv = &map[i].cursor;
if (!alt && !ctrl && !shift) s = &kv->plain;
else if (alt && !ctrl && !shift) s = &kv->alt;
else if (!alt && ctrl && !shift) s = &kv->ctrl;
@ -112,7 +112,7 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
{
if (alt)
termpty_write(ty, "\033", 1);
if (ty->state.send_bs)
if (ty->termstate.send_bs)
{
termpty_write(ty, "\b", 1);
}
@ -135,7 +135,7 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
{
if (alt)
termpty_write(ty, "\033", 1);
if (ty->state.crlf)
if (ty->termstate.crlf)
{
termpty_write(ty, "\r\n", sizeof("\r\n") - 1);
return;
@ -150,7 +150,7 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
{
if (!evas_key_lock_is_set(ev->locks, "Num_Lock"))
{
if (ty->state.alt_kp)
if (ty->termstate.alt_kp)
{
if (_key_try(ty, tty_keys_kp_app,
sizeof(tty_keys_kp_app)/sizeof(tty_keys_kp_app[0]),
@ -242,10 +242,10 @@ keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev,
}
// if term app asked for kbd lock - dont handle here
if (ty->state.kbd_lock) return EINA_TRUE;
if (ty->termstate.kbd_lock) return EINA_TRUE;
// if app asked us to not do autorepeat - ignore press if is it is the same
// timestamp as last one
if ((ty->state.no_autorepeat) &&
if ((ty->termstate.no_autorepeat) &&
(ev->timestamp == khdl->last_keyup)) return EINA_TRUE;
if (!khdl->composing)
{

@ -81,7 +81,7 @@ static void
_draw_cell(const Termpty *ty, unsigned int *pixel, const Termcell *cell, unsigned int *colors)
{
int fg, bg, fgext, bgext;
int inv = ty->state.reverse;
int inv = ty->termstate.reverse;
Eina_Unicode codepoint;
codepoint = cell->codepoint;

@ -4512,7 +4512,7 @@ _smart_apply(Evas_Object *obj)
blk->was_active = blk->active;
blk->active = EINA_FALSE;
}
inv = sd->pty->state.reverse;
inv = sd->pty->termstate.reverse;
termpty_cellcomp_freeze(sd->pty);
for (y = 0; y < sd->grid.h; y++)
{
@ -4753,12 +4753,12 @@ _smart_apply(Evas_Object *obj)
(sd->pty->block.active, l);
}
}
if ((sd->scroll != 0) || (sd->pty->state.hidecursor))
if ((sd->scroll != 0) || (sd->pty->termstate.hide_cursor))
evas_object_hide(sd->cursor.obj);
else
evas_object_show(sd->cursor.obj);
sd->cursor.x = sd->pty->state.cx;
sd->cursor.y = sd->pty->state.cy;
sd->cursor.x = sd->pty->cursor_state.cx;
sd->cursor.y = sd->pty->cursor_state.cy;
evas_object_move(sd->cursor.obj,
ox + ((sd->cursor.x + preedit_x) * sd->font.chw),
oy + ((sd->cursor.y + preedit_y) * sd->font.chh));

@ -268,13 +268,23 @@ _cb_fd_read(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
}
static void
_limit_coord(Termpty *ty, Termstate *state)
_limit_coord(Termpty *ty)
{
state->wrapnext = 0;
if (state->cx >= ty->w) state->cx = ty->w - 1;
if (state->cy >= ty->h) state->cy = ty->h - 1;
if (state->had_cr_x >= ty->w) state->had_cr_x = ty->w - 1;
if (state->had_cr_y >= ty->h) state->had_cr_y = ty->h - 1;
ty->termstate.wrapnext = 0;
if (ty->termstate.had_cr_x >= ty->w)
ty->termstate.had_cr_x = ty->w - 1;
if (ty->termstate.had_cr_y >= ty->h)
ty->termstate.had_cr_y = ty->h - 1;
if (ty->cursor_state.cx >= ty->w)
ty->cursor_state.cx = ty->w - 1;
if (ty->cursor_state.cy >= ty->h)
ty->cursor_state.cy = ty->h - 1;
if (ty->cursor_save.cx >= ty->w)
ty->cursor_save.cx = ty->w - 1;
if (ty->cursor_save.cy >= ty->h)
ty->cursor_save.cy = ty->h - 1;
}
Termpty *
@ -298,8 +308,6 @@ termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
ty->backmax = backscroll;
_termpty_reset_state(ty);
ty->save = ty->state;
ty->swap = ty->state;
ty->screen = calloc(1, sizeof(Termcell) * ty->w * ty->h);
if (!ty->screen)
@ -799,7 +807,7 @@ termpty_line_rewrap(Termpty *ty, int y_start, int y_end,
new_back[new_y + ty->backmax] = new_ts;
}
}
if (y == ty->state.cy)
if (y == ty->cursor_state.cy)
{
*new_cyp = new_y_start;
}
@ -831,7 +839,7 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
Termcell *new_screen = NULL;
Termsave **new_back = NULL;
int y_start = 0, y_end = 0, new_y_start = 0, new_y_end,
new_cy = ty->state.cy;
new_cy = ty->cursor_state.cy;
int i, altbuf = 0;
if ((ty->w == new_w) && (ty->h == new_h)) return;
@ -855,7 +863,7 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
goto bad;
new_back = calloc(sizeof(Termsave *), ty->backmax);
y_end = ty->state.cy;
y_end = ty->cursor_state.cy;
new_y_end = new_h - 1;
/* For each "full line" in old buffers, rewrap.
* From most recent to oldest */
@ -885,15 +893,13 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
ty->circular_offset = MAX(new_y_start, 0);
ty->backpos = 0;
ty->backscroll_num = MAX(-new_y_start, 0);
ty->state.had_cr = 0;
ty->termstate.had_cr = 0;
ty->state.cy = (new_cy + new_h - ty->circular_offset) % new_h;
ty->cursor_state.cy = (new_cy + new_h - ty->circular_offset) % new_h;
if (altbuf) termpty_screen_swap(ty);
_limit_coord(ty, &(ty->state));
_limit_coord(ty, &(ty->swap));
_limit_coord(ty, &(ty->save));
_limit_coord(ty);
_pty_size(ty);
@ -1100,25 +1106,11 @@ termpty_screen_swap(Termpty *ty)
{
Termcell *tmp_screen;
int tmp_circular_offset;
Termstate tmp;
tmp_screen = ty->screen;
ty->screen = ty->screen2;
ty->screen2 = tmp_screen;
if (ty->altbuf)
{
tmp = ty->state;
ty->state = ty->swap;
ty->swap = tmp;
}
else
{
tmp = ty->swap;
ty->swap = ty->state;
ty->state = tmp;
}
tmp_circular_offset = ty->circular_offset;
ty->circular_offset = ty->circular_offset2;
ty->circular_offset2 = tmp_circular_offset;

@ -6,7 +6,6 @@
typedef struct _Termpty Termpty;
typedef struct _Termcell Termcell;
typedef struct _Termatt Termatt;
typedef struct _Termstate Termstate;
typedef struct _Termsave Termsave;
typedef struct _Termsavecomp Termsavecomp;
typedef struct _Termblock Termblock;
@ -84,32 +83,6 @@ struct _Termatt
#endif
};
struct _Termstate
{
int cx, cy;
Termatt att;
unsigned char charset;
unsigned char charsetch;
unsigned char chset[4];
int scroll_y1, scroll_y2;
int had_cr_x, had_cr_y;
int margin_top; // soon, more to come...
unsigned int multibyte : 1;
unsigned int alt_kp : 1;
unsigned int insert : 1;
unsigned int appcursor : 1;
unsigned int wrap : 1;
unsigned int wrapnext : 1;
unsigned int hidecursor : 1;
unsigned int crlf : 1;
unsigned int had_cr : 1;
unsigned int send_bs : 1;
unsigned int kbd_lock : 1;
unsigned int reverse : 1;
unsigned int no_autorepeat : 1;
unsigned int cjk_ambiguous_wide : 1;
};
struct _Termpty
{
Evas_Object *obj;
@ -158,7 +131,32 @@ struct _Termpty
unsigned char by_line : 1;
unsigned char is_top_to_bottom : 1;
} selection;
Termstate state, save, swap;
struct {
Termatt att;
unsigned char charset;
unsigned char charsetch;
unsigned char chset[4];
int scroll_y1, scroll_y2;
int had_cr_x, had_cr_y;
int margin_top; // soon, more to come...
unsigned int multibyte : 1;
unsigned int alt_kp : 1;
unsigned int insert : 1;
unsigned int appcursor : 1;
unsigned int wrap : 1;
unsigned int wrapnext : 1;
unsigned int crlf : 1;
unsigned int had_cr : 1;
unsigned int send_bs : 1;
unsigned int kbd_lock : 1;
unsigned int reverse : 1;
unsigned int no_autorepeat : 1;
unsigned int cjk_ambiguous_wide : 1;
unsigned int hide_cursor : 1;
} termstate;
struct {
int cx, cy;
} cursor_state, cursor_save;
int exit_code;
pid_t pid;
unsigned int altbuf : 1;

@ -41,7 +41,7 @@ _termpty_is_dblwidth_slow_get(Termpty *ty, int g)
return EINA_TRUE;
// FIXME: can optimize by breaking into tree and ranges
// (A)
if (ty->state.cjk_ambiguous_wide)
if (ty->termstate.cjk_ambiguous_wide)
{
// grep ';A #' EastAsianWidth.txt | wc -l
// :(

@ -58,51 +58,51 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
switch (*cc)
{
case 0x07: // BEL '\a' (bell)
ty->state.had_cr = 0;
ty->termstate.had_cr = 0;
if (ty->cb.bell.func) ty->cb.bell.func(ty->cb.bell.data);
return;
case 0x08: // BS '\b' (backspace)
DBG("->BS");
ty->state.had_cr = 0;
ty->state.wrapnext = 0;
ty->state.cx--;
if (ty->state.cx < 0) ty->state.cx = 0;
ty->termstate.had_cr = 0;
ty->termstate.wrapnext = 0;
ty->cursor_state.cx--;
if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
return;
case 0x09: // HT '\t' (horizontal tab)
DBG("->HT");
ty->state.had_cr = 0;
TERMPTY_SCREEN(ty, ty->state.cx, ty->state.cy).att.tab = 1;
ty->state.wrapnext = 0;
ty->state.cx += 8;
ty->state.cx = (ty->state.cx / 8) * 8;
if (ty->state.cx >= ty->w)
ty->state.cx = ty->w - 1;
ty->termstate.had_cr = 0;
TERMPTY_SCREEN(ty, ty->cursor_state.cx, ty->cursor_state.cy).att.tab = 1;
ty->termstate.wrapnext = 0;
ty->cursor_state.cx += 8;
ty->cursor_state.cx = (ty->cursor_state.cx / 8) * 8;
if (ty->cursor_state.cx >= ty->w)
ty->cursor_state.cx = ty->w - 1;
return;
case 0x0a: // LF '\n' (new line)
case 0x0b: // VT '\v' (vertical tab)
case 0x0c: // FF '\f' (form feed)
DBG("->LF");
if (ty->state.had_cr)
if (ty->termstate.had_cr)
{
TERMPTY_SCREEN(ty, ty->state.had_cr_x,
ty->state.had_cr_y).att.newline = 1;
TERMPTY_SCREEN(ty, ty->termstate.had_cr_x,
ty->termstate.had_cr_y).att.newline = 1;
}
ty->state.had_cr = 0;
ty->state.wrapnext = 0;
if (ty->state.crlf) ty->state.cx = 0;
ty->state.cy++;
ty->termstate.had_cr = 0;
ty->termstate.wrapnext = 0;
if (ty->termstate.crlf) ty->cursor_state.cx = 0;
ty->cursor_state.cy++;
_termpty_text_scroll_test(ty, EINA_TRUE);
return;
case 0x0d: // CR '\r' (carriage ret)
DBG("->CR");
if (ty->state.cx != 0)
if (ty->cursor_state.cx != 0)
{
ty->state.had_cr_x = ty->state.cx;
ty->state.had_cr_y = ty->state.cy;
ty->state.wrapnext = 0;
ty->termstate.had_cr_x = ty->cursor_state.cx;
ty->termstate.had_cr_y = ty->cursor_state.cy;
ty->termstate.wrapnext = 0;
}
ty->state.cx = 0;
// ty->state.had_cr = 1;
ty->cursor_state.cx = 0;
// ty->termstate.had_cr = 1;
return;
default:
return;
@ -149,14 +149,14 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
switch (arg)
{
case 1:
ty->state.appcursor = mode;
ty->termstate.appcursor = mode;
break;
case 2:
ty->state.kbd_lock = mode;
ty->termstate.kbd_lock = mode;
break;
case 3: // 132 column modeโ€ฆ should we handle this?
#if defined(SUPPORT_80_132_COLUMNS)
if (ty->state.att.is_80_132_mode_allowed)
if (ty->termstate.att.is_80_132_mode_allowed)
{
/* ONLY FOR TESTING PURPOSE FTM */
Evas_Object *wn;
@ -180,18 +180,18 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
WRN("TODO: scrolling mode (DECSCLM): %i", mode);
break;
case 5:
ty->state.reverse = mode;
ty->termstate.reverse = mode;
break;
case 6:
if (mode)
{
ty->state.margin_top = ty->state.cy;
ty->state.cx = 0;
ty->termstate.margin_top = ty->cursor_state.cy;
ty->cursor_state.cx = 0;
}
else
{
ty->state.cx = 0;
ty->state.margin_top = 0;
ty->cursor_state.cx = 0;
ty->termstate.margin_top = 0;
}
DBG("origin mode (%d): cursor is at 0,0"
" cursor limited to screen/start point"
@ -200,10 +200,10 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
break;
case 7:
DBG("set wrap mode to %i", mode);
ty->state.wrap = mode;
ty->termstate.wrap = mode;
break;
case 8:
ty->state.no_autorepeat = !mode;
ty->termstate.no_autorepeat = !mode;
DBG("auto repeat %i", mode);
break;
case 9:
@ -218,10 +218,10 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
WRN("TODO: set print extent to full screen");
break;
case 20: // crfl==1 -> cur moves to col 0 on LF, FF or VT, ==0 -> mode is cr+lf
ty->state.crlf = mode;
ty->termstate.crlf = mode;
break;
case 25:
ty->state.hidecursor = !mode;
ty->termstate.hide_cursor = !mode;
DBG("hide cursor: %d", !mode);
break;
case 30: // ignore
@ -242,7 +242,7 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
case 40:
DBG("Allow 80 -> 132 Mode %i", mode);
#if defined(SUPPORT_80_132_COLUMNS)
ty->state.att.is_80_132_mode_allowed = mode;
ty->termstate.att.is_80_132_mode_allowed = mode;
#endif
break;
case 45: // ignore
@ -255,7 +255,7 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
WRN("TODO: app keypad mode %i", mode);
break;
case 67:
ty->state.send_bs = mode;
ty->termstate.send_bs = mode;
DBG("backspace send bs not del = %i", mode);
break;
case 1000:
@ -312,10 +312,7 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
break;
case 1048:
case 1049:
if (mode)
_termpty_cursor_copy(&(ty->state), &(ty->save));
else
_termpty_cursor_copy(&(ty->save), &(ty->state));
_termpty_cursor_copy(ty, mode);
if (arg == 1049)
_switch_to_alternative_screen(ty, mode);
break;
@ -345,11 +342,11 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
switch (arg)
{
case 1:
ty->state.appcursor = mode;
ty->termstate.appcursor = mode;
break;
case 4:
DBG("set insert mode to %i", mode);
ty->state.insert = mode;
ty->termstate.insert = mode;
break;
case 34:
WRN("TODO: hebrew keyboard mapping: %i", mode);
@ -381,75 +378,75 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
{
int arg = _csi_arg_get(&b);
if ((first) && (!b))
_termpty_reset_att(&(ty->state.att));
_termpty_reset_att(&(ty->termstate.att));
else if (b)
{
first = 0;
switch (arg)
{
case 0: // reset to normal
_termpty_reset_att(&(ty->state.att));
_termpty_reset_att(&(ty->termstate.att));
break;
case 1: // bold/bright
ty->state.att.bold = 1;
ty->termstate.att.bold = 1;
break;
case 2: // faint
ty->state.att.faint = 1;
ty->termstate.att.faint = 1;
break;
case 3: // italic
#if defined(SUPPORT_ITALIC)
ty->state.att.italic = 1;
ty->termstate.att.italic = 1;
#endif
break;
case 4: // underline
ty->state.att.underline = 1;
ty->termstate.att.underline = 1;
break;
case 5: // blink
ty->state.att.blink = 1;
ty->termstate.att.blink = 1;
break;
case 6: // blink rapid
ty->state.att.blink2 = 1;
ty->termstate.att.blink2 = 1;
break;
case 7: // reverse
ty->state.att.inverse = 1;
ty->termstate.att.inverse = 1;
break;
case 8: // invisible
ty->state.att.invisible = 1;
ty->termstate.att.invisible = 1;
break;
case 9: // strikethrough
ty->state.att.strike = 1;
ty->termstate.att.strike = 1;
break;
case 20: // fraktur!
ty->state.att.fraktur = 1;
ty->termstate.att.fraktur = 1;
break;
case 21: // no bold/bright
ty->state.att.bold = 0;
ty->termstate.att.bold = 0;
break;
case 22: // no bold/bright, no faint
ty->state.att.bold = 0;
ty->state.att.faint = 0;
ty->termstate.att.bold = 0;
ty->termstate.att.faint = 0;
break;
case 23: // no italic, not fraktur
#if defined(SUPPORT_ITALIC)
ty->state.att.italic = 0;
ty->termstate.att.italic = 0;
#endif
ty->state.att.fraktur = 0;
ty->termstate.att.fraktur = 0;
break;
case 24: // no underline
ty->state.att.underline = 0;
ty->termstate.att.underline = 0;
break;
case 25: // no blink
ty->state.att.blink = 0;
ty->state.att.blink2 = 0;
ty->termstate.att.blink = 0;
ty->termstate.att.blink2 = 0;
break;
case 27: // no reverse
ty->state.att.inverse = 0;
ty->termstate.att.inverse = 0;
break;
case 28: // no invisible
ty->state.att.invisible = 0;
ty->termstate.att.invisible = 0;
break;
case 29: // no strikethrough
ty->state.att.strike = 0;
ty->termstate.att.strike = 0;
break;
case 30: // fg
case 31:
@ -459,9 +456,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
case 35:
case 36:
case 37:
ty->state.att.fg256 = 0;
ty->state.att.fg = (arg - 30) + COL_BLACK;
ty->state.att.fgintense = 0;
ty->termstate.att.fg256 = 0;
ty->termstate.att.fg = (arg - 30) + COL_BLACK;
ty->termstate.att.fgintense = 0;
break;
case 38: // xterm 256 fg color ???
// now check if next arg is 5
@ -474,16 +471,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
if (!b) ERR("Failed xterm 256 color fg esc val");
else
{
ty->state.att.fg256 = 1;
ty->state.att.fg = arg;
ty->termstate.att.fg256 = 1;
ty->termstate.att.fg = arg;
}
}
ty->state.att.fgintense = 0;
ty->termstate.att.fgintense = 0;
break;
case 39: // default fg color
ty->state.att.fg256 = 0;
ty->state.att.fg = COL_DEF;
ty->state.att.fgintense = 0;
ty->termstate.att.fg256 = 0;
ty->termstate.att.fg = COL_DEF;
ty->termstate.att.fgintense = 0;
break;
case 40: // bg
case 41:
@ -493,9 +490,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
case 45:
case 46:
case 47:
ty->state.att.bg256 = 0;
ty->state.att.bg = (arg - 40) + COL_BLACK;
ty->state.att.bgintense = 0;
ty->termstate.att.bg256 = 0;
ty->termstate.att.bg = (arg - 40) + COL_BLACK;
ty->termstate.att.bgintense = 0;
break;
case 48: // xterm 256 bg color ???
// now check if next arg is 5
@ -508,16 +505,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
if (!b) ERR("Failed xterm 256 color bg esc val");
else
{
ty->state.att.bg256 = 1;
ty->state.att.bg = arg;
ty->termstate.att.bg256 = 1;
ty->termstate.att.bg = arg;
}
}
ty->state.att.bgintense = 0;
ty->termstate.att.bgintense = 0;
break;
case 49: // default bg color
ty->state.att.bg256 = 0;
ty->state.att.bg = COL_DEF;
ty->state.att.bgintense = 0;
ty->termstate.att.bg256 = 0;
ty->termstate.att.bg = COL_DEF;
ty->termstate.att.bgintense = 0;
break;
case 90: // fg
case 91:
@ -527,9 +524,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
case 95:
case 96:
case 97:
ty->state.att.fg256 = 0;
ty->state.att.fg = (arg - 90) + COL_BLACK;
ty->state.att.fgintense = 1;
ty->termstate.att.fg256 = 0;
ty->termstate.att.fg = (arg - 90) + COL_BLACK;
ty->termstate.att.fgintense = 1;
break;
case 98: // xterm 256 fg color ???
// now check if next arg is 5
@ -542,16 +539,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
if (!b) ERR("Failed xterm 256 color fg esc val");
else
{
ty->state.att.fg256 = 1;
ty->state.att.fg = arg;
ty->termstate.att.fg256 = 1;
ty->termstate.att.fg = arg;
}
}
ty->state.att.fgintense = 1;
ty->termstate.att.fgintense = 1;
break;
case 99: // default fg color
ty->state.att.fg256 = 0;
ty->state.att.fg = COL_DEF;
ty->state.att.fgintense = 1;
ty->termstate.att.fg256 = 0;
ty->termstate.att.fg = COL_DEF;
ty->termstate.att.fgintense = 1;
break;
case 100: // bg
case 101:
@ -561,9 +558,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
case 105:
case 106:
case 107:
ty->state.att.bg256 = 0;
ty->state.att.bg = (arg - 100) + COL_BLACK;
ty->state.att.bgintense = 1;
ty->termstate.att.bg256 = 0;
ty->termstate.att.bg = (arg - 100) + COL_BLACK;
ty->termstate.att.bgintense = 1;
break;
case 108: // xterm 256 bg color ???
// now check if next arg is 5
@ -576,16 +573,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
if (!b) ERR("Failed xterm 256 color bg esc val");
else
{
ty->state.att.bg256 = 1;
ty->state.att.bg = arg;
ty->termstate.att.bg256 = 1;
ty->termstate.att.bg = arg;
}
}
ty->state.att.bgintense = 1;
ty->termstate.att.bgintense = 1;
break;
case 109: // default bg color
ty->state.att.bg256 = 0;
ty->state.att.bg = COL_DEF;
ty->state.att.bgintense = 1;
ty->termstate.att.bg256 = 0;
ty->termstate.att.bg = COL_DEF;
ty->termstate.att.bgintense = 1;
break;
default: // not handled???
ERR("Unhandled color cmd [%i]", arg);
@ -614,7 +611,7 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
{
case 6:
len = snprintf(bf, sizeof(bf), "\033[?%d;%d;1R",
ty->state.cy + 1, ty->state.cx + 1);
ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
termpty_write(ty, bf, len);
break;
default:
@ -629,7 +626,7 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
{
case 6:
len = snprintf(bf, sizeof(bf), "\033[%d;%dR",
ty->state.cy + 1, ty->state.cx + 1);
ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
termpty_write(ty, bf, len);
break;
default:
@ -675,16 +672,16 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
if (arg < 1) arg = 1;
DBG("insert %d blank chars", arg);
{
int pi = ty->state.insert;
int pi = ty->termstate.insert;
Eina_Unicode blank[1] = { ' ' };
int cx = ty->state.cx;
int cx = ty->cursor_state.cx;
ty->state.wrapnext = 0;
ty->state.insert = 1;
ty->termstate.wrapnext = 0;
ty->termstate.insert = 1;
for (i = 0; i < arg; i++)
_termpty_text_append(ty, blank, 1);
ty->state.insert = pi;
ty->state.cx = cx;
ty->termstate.insert = pi;
ty->cursor_state.cx = cx;
}
break;
case 'A': // cursor up N
@ -692,25 +689,25 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor up %d", arg);
ty->state.wrapnext = 0;
ty->state.cy = MAX(0, ty->state.cy - arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg);
break;
case 'B': // cursor down N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor down %d", arg);
ty->state.wrapnext = 0;
ty->state.cy = MIN(ty->h - 1, ty->state.cy + arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy = MIN(ty->h - 1, ty->cursor_state.cy + arg);
break;
case 'D': // cursor left N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor left %d", arg);
ty->state.wrapnext = 0;
ty->termstate.wrapnext = 0;
for (i = 0; i < arg; i++)
{
ty->state.cx--;
if (ty->state.cx < 0) ty->state.cx = 0;
ty->cursor_state.cx--;
if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
}
break;
case 'C': // cursor right N
@ -718,21 +715,21 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor right %d", arg);
ty->state.wrapnext = 0;
ty->termstate.wrapnext = 0;
for (i = 0; i < arg; i++)
{
ty->state.cx++;
if (ty->state.cx >= ty->w) ty->state.cx = ty->w - 1;
ty->cursor_state.cx++;
if (ty->cursor_state.cx >= ty->w) ty->cursor_state.cx = ty->w - 1;
}
break;
case 'H': // cursor pos set
case 'f': // cursor pos set
DBG("cursor pos set");
ty->state.wrapnext = 0;
ty->termstate.wrapnext = 0;
if (!*b)
{
ty->state.cx = 0;
ty->state.cy = 0;
ty->cursor_state.cx = 0;
ty->cursor_state.cy = 0;
}
else
{
@ -742,7 +739,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
if (arg >= ty->h) arg = ty->h - 1;
if (b)
{
ty->state.cy = arg;
ty->cursor_state.cy = arg;
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
arg--;
@ -750,47 +747,47 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
else arg = 0;
if (arg >= ty->w) arg = ty->w - 1;
if (b) ty->state.cx = arg;
if (b) ty->cursor_state.cx = arg;
}
ty->state.cy += ty->state.margin_top;
ty->cursor_state.cy += ty->termstate.margin_top;
break;
case 'G': // to column N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("to column %d", arg);
ty->state.wrapnext = 0;
ty->state.cx = arg - 1;
if (ty->state.cx < 0) ty->state.cx = 0;
else if (ty->state.cx >= ty->w) ty->state.cx = ty->w - 1;
ty->termstate.wrapnext = 0;
ty->cursor_state.cx = arg - 1;
if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
else if (ty->cursor_state.cx >= ty->w) ty->cursor_state.cx = ty->w - 1;
break;
case 'd': // to row N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("to row %d", arg);
ty->state.wrapnext = 0;
ty->state.cy = arg - 1;
if (ty->state.cy < 0) ty->state.cy = 0;
else if (ty->state.cy >= ty->h) ty->state.cy = ty->h - 1;
ty->termstate.wrapnext = 0;
ty->cursor_state.cy = arg - 1;
if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
else if (ty->cursor_state.cy >= ty->h) ty->cursor_state.cy = ty->h - 1;
break;
case 'E': // down relative N rows, and to col 0
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("down relative %d rows, and to col 0", arg);
ty->state.wrapnext = 0;
ty->state.cy += arg;
if (ty->state.cy < 0) ty->state.cy = 0;
else if (ty->state.cy >= ty->h) ty->state.cy = ty->h - 1;
ty->state.cx = 0;
ty->termstate.wrapnext = 0;
ty->cursor_state.cy += arg;
if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
else if (ty->cursor_state.cy >= ty->h) ty->cursor_state.cy = ty->h - 1;
ty->cursor_state.cx = 0;
break;
case 'F': // up relative N rows, and to col 0
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("up relative %d rows, and to col 0", arg);
ty->state.wrapnext = 0;
ty->state.cy -= arg;
if (ty->state.cy < 0) ty->state.cy = 0;
else if (ty->state.cy >= ty->h) ty->state.cy = ty->h - 1;
ty->state.cx = 0;
ty->termstate.wrapnext = 0;
ty->cursor_state.cy -= arg;
if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
else if (ty->cursor_state.cy >= ty->h) ty->cursor_state.cy = ty->h - 1;
ty->cursor_state.cx = 0;
break;
case 'X': // erase N chars
arg = _csi_arg_get(&b);
@ -818,26 +815,26 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
{
int sy1, sy2;
sy1 = ty->state.scroll_y1;
sy2 = ty->state.scroll_y2;
if (ty->state.scroll_y2 == 0)
sy1 = ty->termstate.scroll_y1;
sy2 = ty->termstate.scroll_y2;
if (ty->termstate.scroll_y2 == 0)
{
ty->state.scroll_y1 = ty->state.cy;
ty->state.scroll_y2 = ty->h;
ty->termstate.scroll_y1 = ty->cursor_state.cy;
ty->termstate.scroll_y2 = ty->h;
}
else
{
ty->state.scroll_y1 = ty->state.cy;
if (ty->state.scroll_y2 <= ty->state.scroll_y1)
ty->state.scroll_y2 = ty->state.scroll_y1 + 1;
ty->termstate.scroll_y1 = ty->cursor_state.cy;
if (ty->termstate.scroll_y2 <= ty->termstate.scroll_y1)
ty->termstate.scroll_y2 = ty->termstate.scroll_y1 + 1;
}
for (i = 0; i < arg; i++)
{
if (*cc == 'M') _termpty_text_scroll(ty, EINA_TRUE);
else _termpty_text_scroll_rev(ty, EINA_TRUE);
}
ty->state.scroll_y1 = sy1;
ty->state.scroll_y2 = sy2;
ty->termstate.scroll_y1 = sy1;
ty->termstate.scroll_y2 = sy2;
}
break;
case 'P': // erase and scrollback N chars
@ -848,9 +845,9 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
Termcell *cells;
int x, lim;
cells = &(TERMPTY_SCREEN(ty, 0, ty->state.cy));
cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
lim = ty->w - arg;
for (x = ty->state.cx; x < (ty->w); x++)
for (x = ty->cursor_state.cx; x < (ty->w); x++)
{
if (x < lim)
termpty_cell_copy(ty, &(cells[x + arg]), &(cells[x]), 1);
@ -929,8 +926,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
if (!b)
{
WRN("no region args reset region");
ty->state.scroll_y1 = 0;
ty->state.scroll_y2 = 0;
ty->termstate.scroll_y1 = 0;
ty->termstate.scroll_y2 = 0;
}
else
{
@ -940,16 +937,16 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
if (!b)
{
WRN("failed to give 2 regions args reset region");
ty->state.scroll_y1 = 0;
ty->state.scroll_y2 = 0;
ty->termstate.scroll_y1 = 0;
ty->termstate.scroll_y2 = 0;
}
else
{
if (arg > arg2)
{
DBG("scroll region beginning > end [%i %i]", arg, arg2);
ty->state.scroll_y1 = 0;
ty->state.scroll_y2 = 0;
ty->termstate.scroll_y1 = 0;
ty->termstate.scroll_y2 = 0;
}
else
{
@ -957,19 +954,19 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
if (arg >= ty->h) arg = ty->h - 1;
if (arg == 0) arg = 1;
if (arg2 > ty->h) arg2 = ty->h;
ty->state.scroll_y1 = arg - 1;
ty->state.scroll_y2 = arg2;
ty->termstate.scroll_y1 = arg - 1;
ty->termstate.scroll_y2 = arg2;
if ((arg == 1) && (arg2 == ty->h))
ty->state.scroll_y2 = 0;
ty->termstate.scroll_y2 = 0;
}
}
}
break;
case 's': // store cursor pos
_termpty_cursor_copy(&(ty->state), &(ty->save));
_termpty_cursor_copy(ty, EINA_TRUE);
break;
case 'u': // restore cursor pos
_termpty_cursor_copy(&(ty->save), &(ty->state));
_termpty_cursor_copy(ty, EINA_FALSE);
break;
case 'p': // define key assignments based on keycode
if (b && *b == '!')
@ -1007,7 +1004,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
break;
case 'Z': // Cursor Back Tab
{
int idx, size, cx = ty->state.cx, cy = ty->state.cy;
int idx, size, cx = ty->cursor_state.cx, cy = ty->cursor_state.cy;
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
@ -1026,8 +1023,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
}
if (!arg)
{
ty->state.cx = cx;
ty->state.cy = cy;
ty->cursor_state.cx = cx;
ty->cursor_state.cy = cy;
}
}
break;
@ -1559,25 +1556,25 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
if (len == 0) return 0;
return 1 + len;
case '=': // set alternate keypad mode
ty->state.alt_kp = 1;
ty->termstate.alt_kp = 1;
return 1;
case '>': // set numeric keypad mode
ty->state.alt_kp = 0;
ty->termstate.alt_kp = 0;
return 1;
case 'M': // move to prev line
ty->state.wrapnext = 0;
ty->state.cy--;
ty->termstate.wrapnext = 0;
ty->cursor_state.cy--;
_termpty_text_scroll_rev_test(ty, EINA_TRUE);
return 1;
case 'D': // move to next line
ty->state.wrapnext = 0;
ty->state.cy++;
ty->termstate.wrapnext = 0;
ty->cursor_state.cy++;
_termpty_text_scroll_test(ty, EINA_FALSE);
return 1;
case 'E': // add \n\r
ty->state.wrapnext = 0;
ty->state.cx = 0;
ty->state.cy++;
ty->termstate.wrapnext = 0;
ty->cursor_state.cx = 0;
ty->cursor_state.cy++;
_termpty_text_scroll_test(ty, EINA_FALSE);
return 1;
case 'Z': // same a 'ESC [ Pn c'
@ -1592,29 +1589,29 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
return 1;
case '(': // charset 0
if (len < 2) return 0;
ty->state.chset[0] = c[1];
ty->state.multibyte = 0;
ty->state.charsetch = c[1];
ty->termstate.chset[0] = c[1];
ty->termstate.multibyte = 0;
ty->termstate.charsetch = c[1];
return 2;
case ')': // charset 1
if (len < 2) return 0;
ty->state.chset[1] = c[1];
ty->state.multibyte = 0;
ty->termstate.chset[1] = c[1];
ty->termstate.multibyte = 0;
return 2;
case '*': // charset 2
if (len < 2) return 0;
ty->state.chset[2] = c[1];
ty->state.multibyte = 0;
ty->termstate.chset[2] = c[1];
ty->termstate.multibyte = 0;
return 2;
case '+': // charset 3
if (len < 2) return 0;
ty->state.chset[3] = c[1];
ty->state.multibyte = 0;
ty->termstate.chset[3] = c[1];
ty->termstate.multibyte = 0;
return 2;
case '$': // charset -2
if (len < 2) return 0;
ty->state.chset[2] = c[1];
ty->state.multibyte = 1;
ty->termstate.chset[2] = c[1];
ty->termstate.multibyte = 1;
return 2;
case '#': // #8 == test mode -> fill screen with "E";
if (len < 2) return 0;
@ -1625,8 +1622,6 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
DBG("reset to init mode and clear then fill with E");
_termpty_reset_state(ty);
ty->save = ty->state;
ty->swap = ty->state;
_termpty_clear_screen(ty, TERMPTY_CLR_ALL);
if (ty->cb.cancel_sel.func)
ty->cb.cancel_sel.func(ty->cb.cancel_sel.data);
@ -1635,7 +1630,7 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
if (cells)
{
Termatt att;
memset((&att), 0, sizeof(att));
termpty_cell_codepoint_att_fill(ty, 'E', att, cells, size);
}
@ -1645,10 +1640,10 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
if (len < 2) return 0;
return 2;
case '7': // save cursor pos
_termpty_cursor_copy(&(ty->state), &(ty->save));
_termpty_cursor_copy(ty, EINA_TRUE);
return 1;
case '8': // restore cursor pos
_termpty_cursor_copy(&(ty->save), &(ty->state));
_termpty_cursor_copy(ty, EINA_FALSE);
return 1;
case 'H': // set tab at current column
DBG("Character Tabulation Set (HTS)");
@ -1706,7 +1701,7 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, Eina_Unicode *ce)
/*
case 0x05: // ENQ (enquiry)
_term_txt_write(ty, "ABC\r\n");
ty->state.had_cr = 0;
ty->termstate.had_cr = 0;
return 1;
*/
/*
@ -1724,14 +1719,14 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, Eina_Unicode *ce)
return 1;
case 0x0e: // SO (shift out) // Maps G1 character set into GL.
ty->state.had_cr = 0;
ty->state.charset = 1;
ty->state.charsetch = ty->state.chset[1];
ty->termstate.had_cr = 0;
ty->termstate.charset = 1;
ty->termstate.charsetch = ty->termstate.chset[1];