2012-07-13 01:46:33 -07:00
|
|
|
#include "private.h"
|
|
|
|
#include <Elementary.h>
|
2015-11-08 03:49:08 -08:00
|
|
|
#include <stdint.h>
|
2014-08-17 13:20:40 -07:00
|
|
|
#include "termio.h"
|
2012-07-13 01:46:33 -07:00
|
|
|
#include "termpty.h"
|
|
|
|
#include "termptydbl.h"
|
|
|
|
#include "termptyesc.h"
|
|
|
|
#include "termptyops.h"
|
|
|
|
#include "termptyext.h"
|
2013-04-21 14:18:03 -07:00
|
|
|
#if defined(SUPPORT_80_132_COLUMNS)
|
|
|
|
#include "termio.h"
|
|
|
|
#endif
|
2012-07-13 01:46:33 -07:00
|
|
|
|
|
|
|
#undef CRITICAL
|
|
|
|
#undef ERR
|
|
|
|
#undef WRN
|
|
|
|
#undef INF
|
|
|
|
#undef DBG
|
|
|
|
|
|
|
|
#define CRITICAL(...) EINA_LOG_DOM_CRIT(_termpty_log_dom, __VA_ARGS__)
|
|
|
|
#define ERR(...) EINA_LOG_DOM_ERR(_termpty_log_dom, __VA_ARGS__)
|
|
|
|
#define WRN(...) EINA_LOG_DOM_WARN(_termpty_log_dom, __VA_ARGS__)
|
|
|
|
#define INF(...) EINA_LOG_DOM_INFO(_termpty_log_dom, __VA_ARGS__)
|
2012-12-14 23:48:17 -08:00
|
|
|
#define DBG(...) EINA_LOG_DOM_DBG(_termpty_log_dom, __VA_ARGS__)
|
2012-07-13 01:46:33 -07:00
|
|
|
|
2012-10-04 16:18:46 -07:00
|
|
|
#define ST 0x9c // String Terminator
|
|
|
|
#define BEL 0x07 // Bell
|
2012-10-04 16:18:54 -07:00
|
|
|
#define ESC 033 // Escape
|
2015-06-23 21:46:48 -07:00
|
|
|
#define DEL 127
|
2012-10-04 16:18:46 -07:00
|
|
|
|
2012-12-14 10:52:19 -08:00
|
|
|
/* XXX: all handle_ functions return the number of bytes successfully read, 0
|
2014-08-14 12:48:26 -07:00
|
|
|
* if not enough bytes could be read
|
2012-12-14 10:52:19 -08:00
|
|
|
*/
|
|
|
|
|
2015-06-23 21:46:48 -07:00
|
|
|
static const char *ASCII_CHARS_TABLE[] =
|
|
|
|
{
|
|
|
|
"NUL", // '\0'
|
|
|
|
"SOH", // '\001'
|
|
|
|
"STX", // '\002'
|
|
|
|
"ETX", // '\003'
|
|
|
|
"EOT", // '\004'
|
|
|
|
"ENQ", // '\005'
|
|
|
|
"ACK", // '\006'
|
|
|
|
"BEL", // '\007'
|
|
|
|
"BS", // '\010'
|
|
|
|
"HT", // '\011'
|
|
|
|
"LF", // '\012'
|
|
|
|
"VT", // '\013'
|
|
|
|
"FF", // '\014'
|
|
|
|
"CR" , // '\015'
|
|
|
|
"SO", // '\016'
|
|
|
|
"SI", // '\017'
|
|
|
|
"DLE", // '\020'
|
|
|
|
"DC1", // '\021'
|
|
|
|
"DC2", // '\022'
|
|
|
|
"DC3", // '\023'
|
|
|
|
"DC4", // '\024'
|
|
|
|
"NAK", // '\025'
|
|
|
|
"SYN", // '\026'
|
|
|
|
"ETB", // '\027'
|
|
|
|
"CAN", // '\030'
|
|
|
|
"EM", // '\031'
|
|
|
|
"SUB", // '\032'
|
|
|
|
"ESC", // '\033'
|
|
|
|
"FS", // '\034'
|
|
|
|
"GS", // '\035'
|
|
|
|
"RS", // '\036'
|
|
|
|
"US" // '\037'
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
_safechar(unsigned int c)
|
|
|
|
{
|
|
|
|
static char _str[9];
|
|
|
|
|
|
|
|
// This should avoid 'BEL' and 'ESC' in particular, which would
|
|
|
|
// have side effects in the parent terminal (esp. ESC).
|
|
|
|
if (c < (sizeof(ASCII_CHARS_TABLE) / sizeof(ASCII_CHARS_TABLE[0])))
|
|
|
|
return ASCII_CHARS_TABLE[c];
|
|
|
|
|
|
|
|
if (c == DEL)
|
|
|
|
return "DEL";
|
|
|
|
|
|
|
|
// The rest should be safe (?)
|
|
|
|
snprintf(_str, 9, "%c", c);
|
|
|
|
_str[8] = '\0';
|
|
|
|
return _str;
|
|
|
|
}
|
|
|
|
|
2012-07-13 01:46:33 -07:00
|
|
|
static int
|
|
|
|
_csi_arg_get(Eina_Unicode **ptr)
|
|
|
|
{
|
|
|
|
Eina_Unicode *b = *ptr;
|
|
|
|
int sum = 0;
|
|
|
|
|
2017-05-17 14:34:06 -07:00
|
|
|
if (!b)
|
|
|
|
goto error;
|
|
|
|
|
2017-06-01 14:29:55 -07:00
|
|
|
/* Skip potential '?', '>'.... */
|
|
|
|
while ((*b) && ( (*b) != ';' && ((*b) < '0' || (*b) > '9')))
|
2017-05-17 14:34:06 -07:00
|
|
|
b++;
|
|
|
|
|
2017-06-01 14:29:55 -07:00
|
|
|
if (*b == ';')
|
|
|
|
{
|
|
|
|
b++;
|
|
|
|
*ptr = b;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-13 01:46:33 -07:00
|
|
|
if (!*b)
|
2017-05-17 14:34:06 -07:00
|
|
|
goto error;
|
|
|
|
|
2014-09-15 14:10:55 -07:00
|
|
|
while ((*b >= '0') && (*b <= '9'))
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2015-11-08 03:49:08 -08:00
|
|
|
if (sum > INT32_MAX/10 )
|
2017-05-17 14:34:06 -07:00
|
|
|
goto error;
|
2013-04-28 08:35:48 -07:00
|
|
|
sum *= 10;
|
2012-07-13 01:46:33 -07:00
|
|
|
sum += *b - '0';
|
|
|
|
b++;
|
|
|
|
}
|
2017-05-17 14:34:06 -07:00
|
|
|
|
2017-06-01 14:29:55 -07:00
|
|
|
if (*b == ';')
|
|
|
|
{
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
|
2012-07-13 01:46:33 -07:00
|
|
|
*ptr = b;
|
|
|
|
return sum;
|
2017-05-17 14:34:06 -07:00
|
|
|
|
|
|
|
error:
|
|
|
|
*ptr = NULL;
|
|
|
|
return -1;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
|
2016-12-18 10:17:42 -08:00
|
|
|
static void
|
|
|
|
_tab_forward(Termpty *ty, int n)
|
|
|
|
{
|
|
|
|
int cx = ty->cursor_state.cx;
|
|
|
|
|
|
|
|
for (; n > 0; n--)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
cx++;
|
|
|
|
}
|
|
|
|
while ((cx < ty->w) && (!TAB_TEST(ty, cx)));
|
|
|
|
}
|
|
|
|
|
|
|
|
ty->cursor_state.cx = cx;
|
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
|
|
|
}
|
|
|
|
|
2013-04-27 12:17:14 -07:00
|
|
|
static void
|
2014-03-05 13:23:13 -08:00
|
|
|
_handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
|
2013-04-27 12:17:14 -07:00
|
|
|
{
|
|
|
|
switch (*cc)
|
|
|
|
{
|
|
|
|
case 0x07: // BEL '\a' (bell)
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
2013-04-27 12:17:14 -07:00
|
|
|
if (ty->cb.bell.func) ty->cb.bell.func(ty->cb.bell.data);
|
|
|
|
return;
|
|
|
|
case 0x08: // BS '\b' (backspace)
|
|
|
|
DBG("->BS");
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
ty->cursor_state.cx--;
|
2015-06-02 13:48:50 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
2013-04-27 12:17:14 -07:00
|
|
|
return;
|
|
|
|
case 0x09: // HT '\t' (horizontal tab)
|
|
|
|
DBG("->HT");
|
2016-12-18 10:17:42 -08:00
|
|
|
_tab_forward(ty, 1);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
2013-04-27 12:17:14 -07:00
|
|
|
return;
|
|
|
|
case 0x0a: // LF '\n' (new line)
|
|
|
|
case 0x0b: // VT '\v' (vertical tab)
|
|
|
|
case 0x0c: // FF '\f' (form feed)
|
|
|
|
DBG("->LF");
|
2015-04-19 10:59:29 -07:00
|
|
|
if (ty->termstate.had_cr)
|
2013-04-27 12:17:14 -07:00
|
|
|
{
|
2015-04-19 10:59:29 -07:00
|
|
|
TERMPTY_SCREEN(ty, ty->termstate.had_cr_x,
|
|
|
|
ty->termstate.had_cr_y).att.newline = 1;
|
2013-04-27 12:17:14 -07:00
|
|
|
}
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
if (ty->termstate.crlf) ty->cursor_state.cx = 0;
|
|
|
|
ty->cursor_state.cy++;
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_text_scroll_test(ty, EINA_TRUE);
|
2013-04-27 12:17:14 -07:00
|
|
|
return;
|
|
|
|
case 0x0d: // CR '\r' (carriage ret)
|
|
|
|
DBG("->CR");
|
2015-04-19 10:59:29 -07:00
|
|
|
if (ty->cursor_state.cx != 0)
|
2013-04-27 12:17:14 -07:00
|
|
|
{
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr_x = ty->cursor_state.cx;
|
|
|
|
ty->termstate.had_cr_y = ty->cursor_state.cy;
|
|
|
|
ty->termstate.wrapnext = 0;
|
2013-04-27 12:17:14 -07:00
|
|
|
}
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->cursor_state.cx = 0;
|
|
|
|
// ty->termstate.had_cr = 1;
|
2013-04-27 12:17:14 -07:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-01 08:18:45 -08:00
|
|
|
static void
|
|
|
|
_switch_to_alternative_screen(Termpty *ty, int mode)
|
|
|
|
{
|
|
|
|
// swap screen content now
|
|
|
|
if (mode != ty->altbuf)
|
|
|
|
termpty_screen_swap(ty);
|
|
|
|
}
|
|
|
|
|
2017-06-03 14:17:33 -07:00
|
|
|
static void
|
|
|
|
_move_cursor_to_origin(Termpty *ty)
|
|
|
|
{
|
|
|
|
if (ty->termstate.restrict_cursor)
|
|
|
|
{
|
|
|
|
ty->cursor_state.cx = ty->termstate.left_margin;
|
|
|
|
ty->cursor_state.cy = ty->termstate.top_margin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ty->cursor_state.cx = 0;
|
|
|
|
ty->cursor_state.cy = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-11 13:02:56 -07:00
|
|
|
static void
|
|
|
|
_handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
|
|
|
|
{
|
|
|
|
int mode = 0, priv = 0, arg;
|
|
|
|
|
|
|
|
if (cc == 'h') mode = 1;
|
|
|
|
if (*b == '?')
|
|
|
|
{
|
|
|
|
priv = 1;
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
if (priv) /* DEC Private Mode Reset (DECRST) */
|
|
|
|
{
|
|
|
|
while (b)
|
|
|
|
{
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (b)
|
|
|
|
{
|
|
|
|
// complete-ish list here:
|
|
|
|
// http://ttssh2.sourceforge.jp/manual/en/about/ctrlseq.html
|
|
|
|
switch (arg)
|
|
|
|
{
|
|
|
|
case 1:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.appcursor = mode;
|
2014-08-11 13:02:56 -07:00
|
|
|
break;
|
|
|
|
case 2:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.kbd_lock = mode;
|
2014-08-11 13:02:56 -07:00
|
|
|
break;
|
|
|
|
case 3: // 132 column mode… should we handle this?
|
|
|
|
#if defined(SUPPORT_80_132_COLUMNS)
|
2015-04-19 10:59:29 -07:00
|
|
|
if (ty->termstate.att.is_80_132_mode_allowed)
|
2014-08-11 13:02:56 -07:00
|
|
|
{
|
|
|
|
/* ONLY FOR TESTING PURPOSE FTM */
|
|
|
|
Evas_Object *wn;
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
wn = termio_win_get(ty->obj);
|
|
|
|
elm_win_size_step_get(wn, &w, &h);
|
|
|
|
evas_object_resize(wn,
|
|
|
|
4 +
|
|
|
|
(mode ? 132 : 80) * w,
|
|
|
|
4 + ty->h * h);
|
|
|
|
termpty_resize(ty, mode ? 132 : 80,
|
|
|
|
ty->h);
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_reset_state(ty);
|
|
|
|
termpty_clear_screen(ty,
|
2014-08-11 13:02:56 -07:00
|
|
|
TERMPTY_CLR_ALL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
WRN("TODO: scrolling mode (DECSCLM): %i", mode);
|
|
|
|
break;
|
|
|
|
case 5:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.reverse = mode;
|
2014-08-11 13:02:56 -07:00
|
|
|
break;
|
|
|
|
case 6:
|
2017-05-30 15:39:02 -07:00
|
|
|
/* DECOM */
|
2014-08-11 13:02:56 -07:00
|
|
|
if (mode)
|
|
|
|
{
|
2017-05-30 15:39:02 -07:00
|
|
|
/* set, within margins */
|
|
|
|
ty->termstate.restrict_cursor = 1;
|
2014-08-11 13:02:56 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-30 15:39:02 -07:00
|
|
|
ty->termstate.restrict_cursor = 0;
|
2014-08-11 13:02:56 -07:00
|
|
|
}
|
2017-06-03 14:17:33 -07:00
|
|
|
_move_cursor_to_origin(ty);
|
2017-06-01 12:29:07 -07:00
|
|
|
DBG("DECOM: mode (%d): cursor is at 0,0"
|
2014-08-11 13:02:56 -07:00
|
|
|
" cursor limited to screen/start point"
|
|
|
|
" for line #'s depends on top margin",
|
|
|
|
mode);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
DBG("set wrap mode to %i", mode);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrap = mode;
|
2014-08-11 13:02:56 -07:00
|
|
|
break;
|
|
|
|
case 8:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.no_autorepeat = !mode;
|
2014-08-11 13:02:56 -07:00
|
|
|
DBG("auto repeat %i", mode);
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
DBG("set mouse (X10) %i", mode);
|
|
|
|
if (mode) ty->mouse_mode = MOUSE_X10;
|
|
|
|
else ty->mouse_mode = MOUSE_OFF;
|
|
|
|
break;
|
|
|
|
case 12: // ignore
|
|
|
|
WRN("TODO: set blinking cursor to (stop?) %i or local echo (ignored)", mode);
|
|
|
|
break;
|
|
|
|
case 19: // never seen this - what to do?
|
|
|
|
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
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.crlf = mode;
|
2014-08-11 13:02:56 -07:00
|
|
|
break;
|
|
|
|
case 25:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.hide_cursor = !mode;
|
2014-08-11 13:02:56 -07:00
|
|
|
DBG("hide cursor: %d", !mode);
|
|
|
|
break;
|
|
|
|
case 30: // ignore
|
|
|
|
WRN("TODO: set scrollbar mapping %i", mode);
|
|
|
|
break;
|
|
|
|
case 33: // ignore
|
|
|
|
WRN("TODO: Stop cursor blink %i", mode);
|
|
|
|
break;
|
|
|
|
case 34: // ignore
|
|
|
|
WRN("TODO: Underline cursor mode %i", mode);
|
|
|
|
break;
|
|
|
|
case 35: // ignore
|
|
|
|
WRN("TODO: set shift keys %i", mode);
|
|
|
|
break;
|
|
|
|
case 38: // ignore
|
|
|
|
WRN("TODO: switch to tek window %i", mode);
|
|
|
|
break;
|
|
|
|
case 40:
|
|
|
|
DBG("Allow 80 -> 132 Mode %i", mode);
|
|
|
|
#if defined(SUPPORT_80_132_COLUMNS)
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.is_80_132_mode_allowed = mode;
|
2014-08-11 13:02:56 -07:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 45: // ignore
|
|
|
|
WRN("TODO: Reverse-wraparound Mode");
|
|
|
|
break;
|
2016-10-17 15:14:19 -07:00
|
|
|
case 47:
|
|
|
|
_switch_to_alternative_screen(ty, mode);
|
|
|
|
break;
|
2014-08-11 13:02:56 -07:00
|
|
|
case 59: // ignore
|
|
|
|
WRN("TODO: kanji terminal mode %i", mode);
|
|
|
|
break;
|
|
|
|
case 66:
|
|
|
|
WRN("TODO: app keypad mode %i", mode);
|
|
|
|
break;
|
|
|
|
case 67:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.send_bs = mode;
|
2014-08-11 13:02:56 -07:00
|
|
|
DBG("backspace send bs not del = %i", mode);
|
|
|
|
break;
|
2017-06-03 14:17:33 -07:00
|
|
|
case 69:
|
|
|
|
ty->termstate.lr_margins = mode;
|
|
|
|
if (!mode)
|
|
|
|
{
|
|
|
|
ty->termstate.left_margin = 0;
|
|
|
|
ty->termstate.right_margin = 0;
|
|
|
|
}
|
2014-08-11 13:02:56 -07:00
|
|
|
case 1000:
|
|
|
|
if (mode) ty->mouse_mode = MOUSE_NORMAL;
|
|
|
|
else ty->mouse_mode = MOUSE_OFF;
|
|
|
|
DBG("set mouse (press+release only) to %i", mode);
|
|
|
|
break;
|
|
|
|
case 1001:
|
|
|
|
WRN("TODO: x11 mouse highlighting %i", mode);
|
|
|
|
break;
|
|
|
|
case 1002:
|
|
|
|
if (mode) ty->mouse_mode = MOUSE_NORMAL_BTN_MOVE;
|
|
|
|
else ty->mouse_mode = MOUSE_OFF;
|
|
|
|
DBG("set mouse (press+release+motion while pressed) %i", mode);
|
|
|
|
break;
|
|
|
|
case 1003:
|
|
|
|
if (mode) ty->mouse_mode = MOUSE_NORMAL_ALL_MOVE;
|
|
|
|
else ty->mouse_mode = MOUSE_OFF;
|
|
|
|
DBG("set mouse (press+release+all motion) %i", mode);
|
|
|
|
break;
|
|
|
|
case 1004: // i dont know what focus repporting is?
|
|
|
|
WRN("TODO: enable focus reporting %i", mode);
|
|
|
|
break;
|
|
|
|
case 1005:
|
|
|
|
if (mode) ty->mouse_ext = MOUSE_EXT_UTF8;
|
|
|
|
else ty->mouse_ext = MOUSE_EXT_NONE;
|
|
|
|
DBG("set mouse (xterm utf8 style) %i", mode);
|
|
|
|
break;
|
|
|
|
case 1006:
|
|
|
|
if (mode) ty->mouse_ext = MOUSE_EXT_SGR;
|
|
|
|
else ty->mouse_ext = MOUSE_EXT_NONE;
|
|
|
|
DBG("set mouse (xterm sgr style) %i", mode);
|
|
|
|
break;
|
|
|
|
case 1010: // ignore
|
|
|
|
WRN("TODO: set home on tty output %i", mode);
|
|
|
|
break;
|
|
|
|
case 1012: // ignore
|
|
|
|
WRN("TODO: set home on tty input %i", mode);
|
|
|
|
break;
|
|
|
|
case 1015:
|
|
|
|
if (mode) ty->mouse_ext = MOUSE_EXT_URXVT;
|
|
|
|
else ty->mouse_ext = MOUSE_EXT_NONE;
|
|
|
|
DBG("set mouse (rxvt-unicode style) %i", mode);
|
|
|
|
break;
|
|
|
|
case 1034: // ignore
|
|
|
|
/* libreadline6 emits it but it shouldn't.
|
|
|
|
See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=577012
|
|
|
|
*/
|
|
|
|
DBG("Ignored screen mode %i", arg);
|
|
|
|
break;
|
|
|
|
case 1047:
|
2016-10-17 15:14:19 -07:00
|
|
|
if (!mode && ty->altbuf)
|
|
|
|
/* clear screen before switching back to normal */
|
|
|
|
termpty_clear_screen(ty, TERMPTY_CLR_ALL);
|
2015-03-01 08:18:45 -08:00
|
|
|
_switch_to_alternative_screen(ty, mode);
|
2016-11-07 02:35:50 -08:00
|
|
|
break;
|
2014-08-11 13:02:56 -07:00
|
|
|
case 1048:
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_cursor_copy(ty, mode);
|
2016-10-17 15:14:19 -07:00
|
|
|
break;
|
|
|
|
case 1049:
|
|
|
|
if (mode)
|
|
|
|
{
|
|
|
|
// switch to altbuf
|
|
|
|
termpty_cursor_copy(ty, mode);
|
|
|
|
_switch_to_alternative_screen(ty, mode);
|
|
|
|
if (ty->altbuf)
|
|
|
|
/* clear screen before switching back to normal */
|
|
|
|
termpty_clear_screen(ty, TERMPTY_CLR_ALL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ty->altbuf)
|
|
|
|
/* clear screen before switching back to normal */
|
|
|
|
termpty_clear_screen(ty, TERMPTY_CLR_ALL);
|
|
|
|
_switch_to_alternative_screen(ty, mode);
|
|
|
|
termpty_cursor_copy(ty, mode);
|
|
|
|
}
|
2014-08-11 13:02:56 -07:00
|
|
|
break;
|
|
|
|
case 2004:
|
|
|
|
ty->bracketed_paste = mode;
|
|
|
|
break;
|
|
|
|
case 7727: // ignore
|
|
|
|
WRN("TODO: enable application escape mode %i", mode);
|
|
|
|
break;
|
|
|
|
case 7786: // ignore
|
|
|
|
WRN("TODO: enable mouse wheel -> cursor key xlation %i", mode);
|
|
|
|
break;
|
|
|
|
default:
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("Unhandled DEC Private Reset Mode arg %i", arg);
|
2014-08-11 13:02:56 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* Reset Mode (RM) */
|
|
|
|
{
|
|
|
|
while (b)
|
|
|
|
{
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (b)
|
|
|
|
{
|
|
|
|
switch (arg)
|
|
|
|
{
|
|
|
|
case 1:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.appcursor = mode;
|
2014-08-11 13:02:56 -07:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
DBG("set insert mode to %i", mode);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.insert = mode;
|
2014-08-11 13:02:56 -07:00
|
|
|
break;
|
|
|
|
case 34:
|
|
|
|
WRN("TODO: hebrew keyboard mapping: %i", mode);
|
|
|
|
break;
|
|
|
|
case 36:
|
|
|
|
WRN("TODO: hebrew encoding mode: %i", mode);
|
|
|
|
break;
|
|
|
|
default:
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("Unhandled ANSI Reset Mode arg %i", arg);
|
2014-08-11 13:02:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-21 09:10:48 -07:00
|
|
|
static void
|
|
|
|
_handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
|
|
|
|
{
|
|
|
|
Eina_Unicode *b = *ptr;
|
|
|
|
int first = 1;
|
|
|
|
|
|
|
|
if (b && (*b == '>'))
|
|
|
|
{ // key resources used by xterm
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("TODO: set/reset key resources used by xterm");
|
2013-09-21 09:10:48 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
DBG("color set");
|
|
|
|
while (b)
|
|
|
|
{
|
|
|
|
int arg = _csi_arg_get(&b);
|
|
|
|
if ((first) && (!b))
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_reset_att(&(ty->termstate.att));
|
2013-09-21 09:10:48 -07:00
|
|
|
else if (b)
|
|
|
|
{
|
|
|
|
first = 0;
|
|
|
|
switch (arg)
|
|
|
|
{
|
|
|
|
case 0: // reset to normal
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_reset_att(&(ty->termstate.att));
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 1: // bold/bright
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.bold = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 2: // faint
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.faint = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 3: // italic
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.italic = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 4: // underline
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.underline = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 5: // blink
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.blink = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 6: // blink rapid
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.blink2 = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 7: // reverse
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.inverse = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 8: // invisible
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.invisible = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 9: // strikethrough
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.strike = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
2014-04-06 05:42:38 -07:00
|
|
|
case 20: // fraktur!
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.fraktur = 1;
|
2014-04-06 05:42:38 -07:00
|
|
|
break;
|
2013-09-21 09:10:48 -07:00
|
|
|
case 21: // no bold/bright
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.bold = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
2014-03-03 14:02:17 -08:00
|
|
|
case 22: // no bold/bright, no faint
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.bold = 0;
|
|
|
|
ty->termstate.att.faint = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
2014-04-06 05:42:38 -07:00
|
|
|
case 23: // no italic, not fraktur
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.italic = 0;
|
|
|
|
ty->termstate.att.fraktur = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 24: // no underline
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.underline = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 25: // no blink
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.blink = 0;
|
|
|
|
ty->termstate.att.blink2 = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 27: // no reverse
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.inverse = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 28: // no invisible
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.invisible = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 29: // no strikethrough
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.strike = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 30: // fg
|
|
|
|
case 31:
|
|
|
|
case 32:
|
|
|
|
case 33:
|
|
|
|
case 34:
|
|
|
|
case 35:
|
|
|
|
case 36:
|
|
|
|
case 37:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.fg256 = 0;
|
|
|
|
ty->termstate.att.fg = (arg - 30) + COL_BLACK;
|
|
|
|
ty->termstate.att.fgintense = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 38: // xterm 256 fg color ???
|
|
|
|
// now check if next arg is 5
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg != 5) ERR("Failed xterm 256 color fg esc 5 (got %d)", arg);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// then get next arg - should be color index 0-255
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (!b) ERR("Failed xterm 256 color fg esc val");
|
2017-05-15 12:56:54 -07:00
|
|
|
else if (arg < 0 || arg > 255)
|
|
|
|
ERR("Invalid fg color %d", arg);
|
2013-09-21 09:10:48 -07:00
|
|
|
else
|
|
|
|
{
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.fg256 = 1;
|
|
|
|
ty->termstate.att.fg = arg;
|
2013-09-21 09:10:48 -07:00
|
|
|
}
|
|
|
|
}
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.fgintense = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 39: // default fg color
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.fg256 = 0;
|
|
|
|
ty->termstate.att.fg = COL_DEF;
|
|
|
|
ty->termstate.att.fgintense = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 40: // bg
|
|
|
|
case 41:
|
|
|
|
case 42:
|
|
|
|
case 43:
|
|
|
|
case 44:
|
|
|
|
case 45:
|
|
|
|
case 46:
|
|
|
|
case 47:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.bg256 = 0;
|
|
|
|
ty->termstate.att.bg = (arg - 40) + COL_BLACK;
|
|
|
|
ty->termstate.att.bgintense = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 48: // xterm 256 bg color ???
|
|
|
|
// now check if next arg is 5
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg != 5) ERR("Failed xterm 256 color bg esc 5 (got %d)", arg);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// then get next arg - should be color index 0-255
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (!b) ERR("Failed xterm 256 color bg esc val");
|
2017-05-15 12:56:54 -07:00
|
|
|
else if (arg < 0 || arg > 255)
|
|
|
|
ERR("Invalid bg color %d", arg);
|
2013-09-21 09:10:48 -07:00
|
|
|
else
|
|
|
|
{
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.bg256 = 1;
|
|
|
|
ty->termstate.att.bg = arg;
|
2013-09-21 09:10:48 -07:00
|
|
|
}
|
|
|
|
}
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.bgintense = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 49: // default bg color
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.bg256 = 0;
|
|
|
|
ty->termstate.att.bg = COL_DEF;
|
|
|
|
ty->termstate.att.bgintense = 0;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 90: // fg
|
|
|
|
case 91:
|
|
|
|
case 92:
|
|
|
|
case 93:
|
|
|
|
case 94:
|
|
|
|
case 95:
|
|
|
|
case 96:
|
|
|
|
case 97:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.fg256 = 0;
|
|
|
|
ty->termstate.att.fg = (arg - 90) + COL_BLACK;
|
|
|
|
ty->termstate.att.fgintense = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 98: // xterm 256 fg color ???
|
|
|
|
// now check if next arg is 5
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg != 5) ERR("Failed xterm 256 color fg esc 5 (got %d)", arg);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// then get next arg - should be color index 0-255
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (!b) ERR("Failed xterm 256 color fg esc val");
|
2017-05-15 12:56:54 -07:00
|
|
|
else if (arg < 0 || arg > 255)
|
|
|
|
ERR("Invalid fg color %d", arg);
|
2013-09-21 09:10:48 -07:00
|
|
|
else
|
|
|
|
{
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.fg256 = 1;
|
|
|
|
ty->termstate.att.fg = arg;
|
2013-09-21 09:10:48 -07:00
|
|
|
}
|
|
|
|
}
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.fgintense = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 99: // default fg color
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.fg256 = 0;
|
|
|
|
ty->termstate.att.fg = COL_DEF;
|
|
|
|
ty->termstate.att.fgintense = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 100: // bg
|
|
|
|
case 101:
|
|
|
|
case 102:
|
|
|
|
case 103:
|
|
|
|
case 104:
|
|
|
|
case 105:
|
|
|
|
case 106:
|
|
|
|
case 107:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.bg256 = 0;
|
|
|
|
ty->termstate.att.bg = (arg - 100) + COL_BLACK;
|
|
|
|
ty->termstate.att.bgintense = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 108: // xterm 256 bg color ???
|
|
|
|
// now check if next arg is 5
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg != 5) ERR("Failed xterm 256 color bg esc 5 (got %d)", arg);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// then get next arg - should be color index 0-255
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (!b) ERR("Failed xterm 256 color bg esc val");
|
2017-05-15 12:56:54 -07:00
|
|
|
else if (arg < 0 || arg > 255)
|
|
|
|
ERR("Invalid bg color %d", arg);
|
2013-09-21 09:10:48 -07:00
|
|
|
else
|
|
|
|
{
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.bg256 = 1;
|
|
|
|
ty->termstate.att.bg = arg;
|
2013-09-21 09:10:48 -07:00
|
|
|
}
|
|
|
|
}
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.bgintense = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
case 109: // default bg color
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.att.bg256 = 0;
|
|
|
|
ty->termstate.att.bg = COL_DEF;
|
|
|
|
ty->termstate.att.bgintense = 1;
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
default: // not handled???
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("Unhandled color cmd [%i]", arg);
|
2013-09-21 09:10:48 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-14 12:48:26 -07:00
|
|
|
static void
|
|
|
|
_handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
|
|
|
|
{
|
|
|
|
int arg, len;
|
|
|
|
char bf[32];
|
|
|
|
|
|
|
|
if (*b == '>')
|
|
|
|
{
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("TODO: disable key resources used by xterm");
|
2014-08-14 12:48:26 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*b == '?')
|
|
|
|
{
|
|
|
|
b++;
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
switch (arg)
|
|
|
|
{
|
|
|
|
case 6:
|
|
|
|
len = snprintf(bf, sizeof(bf), "\033[?%d;%d;1R",
|
2016-10-17 15:14:19 -07:00
|
|
|
ty->cursor_state.cy + 1,
|
|
|
|
ty->cursor_state.cx + 1);
|
2014-08-14 12:48:26 -07:00
|
|
|
termpty_write(ty, bf, len);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRN("unhandled DSR (dec specific) %d", arg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
switch (arg)
|
|
|
|
{
|
|
|
|
case 6:
|
|
|
|
len = snprintf(bf, sizeof(bf), "\033[%d;%dR",
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
|
2014-08-14 12:48:26 -07:00
|
|
|
termpty_write(ty, bf, len);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRN("unhandled DSR %d", arg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-03 14:17:33 -07:00
|
|
|
static void
|
|
|
|
_handle_esc_csi_decslrm(Termpty *ty, Eina_Unicode **b)
|
|
|
|
{
|
|
|
|
int left = _csi_arg_get(b);
|
|
|
|
int right = _csi_arg_get(b);
|
|
|
|
DBG("DECSLRM (%d;%d) Set Left and Right Margins", left, right);
|
|
|
|
if (left < 1) left = 0;
|
|
|
|
if (right < 1) right = 0;
|
|
|
|
if (left >= right) return;
|
|
|
|
if (right - left < 2) return;
|
|
|
|
ty->termstate.left_margin = left;
|
|
|
|
ty->termstate.right_margin = right;
|
|
|
|
_move_cursor_to_origin(ty);
|
|
|
|
}
|
|
|
|
|
2012-07-13 01:46:33 -07:00
|
|
|
static int
|
|
|
|
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
|
|
|
|
{
|
2014-03-05 12:42:33 -08:00
|
|
|
int arg, i;
|
2014-03-05 13:23:13 -08:00
|
|
|
const Eina_Unicode *cc, *be;
|
2012-07-13 01:46:33 -07:00
|
|
|
Eina_Unicode buf[4096], *b;
|
|
|
|
|
|
|
|
cc = (Eina_Unicode *)c;
|
|
|
|
b = buf;
|
2014-03-05 13:23:13 -08:00
|
|
|
be = buf + sizeof(buf) / sizeof(buf[0]);
|
|
|
|
while ((cc < ce) && (*cc <= '?') && (b < be))
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2013-04-27 12:17:14 -07:00
|
|
|
_handle_cursor_control(ty, cc);
|
2012-07-13 01:46:33 -07:00
|
|
|
*b = *cc;
|
|
|
|
b++;
|
|
|
|
cc++;
|
|
|
|
}
|
2014-03-05 13:23:13 -08:00
|
|
|
if (b == be)
|
|
|
|
{
|
|
|
|
ERR("csi parsing overflowed, skipping the whole buffer (binary data?)");
|
|
|
|
return cc - c;
|
|
|
|
}
|
2012-12-14 10:52:19 -08:00
|
|
|
if (cc == ce) return 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
*b = 0;
|
|
|
|
b = buf;
|
2015-06-23 21:46:48 -07:00
|
|
|
DBG(" CSI: '%s' args '%s'", _safechar(*cc), (char *) buf);
|
2012-07-13 01:46:33 -07:00
|
|
|
switch (*cc)
|
|
|
|
{
|
|
|
|
case 'm': // color set
|
2013-09-21 09:10:48 -07:00
|
|
|
_handle_esc_csi_color_set(ty, &b);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case '@': // insert N blank chars
|
|
|
|
arg = _csi_arg_get(&b);
|
2017-05-17 14:40:19 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 1, ty->w * ty->h);
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("insert %d blank chars", arg);
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2015-04-19 10:59:29 -07:00
|
|
|
int pi = ty->termstate.insert;
|
2015-02-23 13:20:18 -08:00
|
|
|
Eina_Unicode blank[1] = { ' ' };
|
2015-04-19 10:59:29 -07:00
|
|
|
int cx = ty->cursor_state.cx;
|
2012-07-13 01:46:33 -07:00
|
|
|
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
ty->termstate.insert = 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
for (i = 0; i < arg; i++)
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_text_append(ty, blank, 1);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.insert = pi;
|
|
|
|
ty->cursor_state.cx = cx;
|
2015-06-02 13:48:50 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
break;
|
2017-05-30 15:39:02 -07:00
|
|
|
case 'A': // cursor up N CUU
|
|
|
|
case 'e': // cursor up N, VPR
|
2012-07-13 01:46:33 -07:00
|
|
|
arg = _csi_arg_get(&b);
|
2013-12-25 18:36:51 -08:00
|
|
|
if (arg < 1) arg = 1;
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("cursor up %d", arg);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg);
|
2015-06-02 13:48:50 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
|
2017-05-30 15:39:02 -07:00
|
|
|
if (ty->termstate.restrict_cursor && (ty->termstate.top_margin != 0)
|
|
|
|
&& (ty->cursor_state.cy < ty->termstate.top_margin))
|
|
|
|
{
|
|
|
|
ty->cursor_state.cy = ty->termstate.top_margin;
|
|
|
|
}
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'B': // cursor down N
|
|
|
|
arg = _csi_arg_get(&b);
|
2013-12-25 18:36:51 -08:00
|
|
|
if (arg < 1) arg = 1;
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("cursor down %d", arg);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
ty->cursor_state.cy = MIN(ty->h - 1, ty->cursor_state.cy + arg);
|
2015-06-02 13:48:50 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
|
2017-05-30 15:39:02 -07:00
|
|
|
if (ty->termstate.restrict_cursor && (ty->termstate.bottom_margin != 0)
|
|
|
|
&& (ty->cursor_state.cy > ty->termstate.bottom_margin))
|
|
|
|
{
|
|
|
|
ty->cursor_state.cy = ty->termstate.bottom_margin;
|
|
|
|
}
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'D': // cursor left N
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg < 1) arg = 1;
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("cursor left %d", arg);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
2017-05-15 13:34:01 -07:00
|
|
|
ty->cursor_state.cx -= arg;
|
2015-06-02 13:48:50 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'C': // cursor right N
|
|
|
|
case 'a': // cursor right N
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg < 1) arg = 1;
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("cursor right %d", arg);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
2017-05-15 13:34:01 -07:00
|
|
|
ty->cursor_state.cx += arg;
|
2015-06-02 13:48:50 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
2017-06-01 13:51:34 -07:00
|
|
|
case 'H': // cursor pos set (CUP)
|
|
|
|
case 'f': // cursor pos set (HVP)
|
|
|
|
DBG("cursor pos set (%s)", (*cc == 'H') ? "CUP" : "HVP");
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
if (!*b)
|
|
|
|
{
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->cursor_state.cx = 0;
|
|
|
|
ty->cursor_state.cy = 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg < 1) arg = 1;
|
|
|
|
arg--;
|
2014-01-22 14:19:11 -08:00
|
|
|
if (arg >= ty->h) arg = ty->h - 1;
|
2017-06-01 14:33:58 -07:00
|
|
|
ty->cursor_state.cy = arg;
|
2014-03-24 05:40:05 -07:00
|
|
|
|
2017-06-01 14:33:58 -07:00
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg < 1) arg = 1;
|
|
|
|
arg--;
|
2014-03-24 05:40:05 -07:00
|
|
|
if (arg >= ty->w) arg = ty->w - 1;
|
2017-06-01 14:33:58 -07:00
|
|
|
ty->cursor_state.cx = arg;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
2017-05-30 15:39:02 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
2017-06-01 13:51:34 -07:00
|
|
|
if (ty->termstate.restrict_cursor)
|
|
|
|
ty->cursor_state.cy += ty->termstate.top_margin;
|
2015-06-02 13:48:50 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'G': // to column N
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg < 1) arg = 1;
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("to column %d", arg);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
ty->cursor_state.cx = arg - 1;
|
2015-06-02 13:48:50 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'd': // to row N
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg < 1) arg = 1;
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("to row %d", arg);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
ty->cursor_state.cy = arg - 1;
|
2015-06-02 13:48:50 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'E': // down relative N rows, and to col 0
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg < 1) arg = 1;
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("down relative %d rows, and to col 0", arg);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
ty->cursor_state.cy += arg;
|
2015-06-02 13:48:50 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->cursor_state.cx = 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'F': // up relative N rows, and to col 0
|
|
|
|
arg = _csi_arg_get(&b);
|
2017-05-15 13:34:01 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("up relative %d rows, and to col 0", arg);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
ty->cursor_state.cy -= arg;
|
2015-06-02 13:48:50 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->cursor_state.cx = 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'X': // erase N chars
|
|
|
|
arg = _csi_arg_get(&b);
|
2017-05-15 13:34:01 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("erase %d chars", arg);
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_clear_line(ty, TERMPTY_CLR_END, arg);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'S': // scroll up N lines
|
|
|
|
arg = _csi_arg_get(&b);
|
2017-05-15 13:34:01 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("scroll up %d lines", arg);
|
2015-06-01 13:52:07 -07:00
|
|
|
for (i = 0; i < arg; i++)
|
|
|
|
termpty_text_scroll(ty, EINA_TRUE);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'T': // scroll down N lines
|
|
|
|
arg = _csi_arg_get(&b);
|
2017-05-15 13:34:01 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("scroll down %d lines", arg);
|
2015-06-01 13:52:07 -07:00
|
|
|
for (i = 0; i < arg; i++)
|
|
|
|
termpty_text_scroll_rev(ty, EINA_TRUE);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'M': // delete N lines - cy
|
|
|
|
case 'L': // insert N lines - cy
|
|
|
|
arg = _csi_arg_get(&b);
|
2017-05-15 13:34:01 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
2013-11-16 10:26:10 -08:00
|
|
|
DBG("%s %d lines", (*cc == 'M') ? "delete" : "insert", arg);
|
2017-06-01 13:52:16 -07:00
|
|
|
if ((ty->cursor_state.cy >= ty->termstate.top_margin) &&
|
|
|
|
((ty->termstate.bottom_margin == 0) ||
|
|
|
|
(ty->cursor_state.cy < ty->termstate.bottom_margin)))
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
|
|
|
int sy1, sy2;
|
|
|
|
|
2017-05-29 14:26:32 -07:00
|
|
|
sy1 = ty->termstate.top_margin;
|
|
|
|
sy2 = ty->termstate.bottom_margin;
|
|
|
|
if (ty->termstate.bottom_margin == 0)
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2017-05-29 14:26:32 -07:00
|
|
|
ty->termstate.top_margin = ty->cursor_state.cy;
|
|
|
|
ty->termstate.bottom_margin = ty->h;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-29 14:26:32 -07:00
|
|
|
ty->termstate.top_margin = ty->cursor_state.cy;
|
|
|
|
if (ty->termstate.bottom_margin <= ty->termstate.top_margin)
|
|
|
|
ty->termstate.bottom_margin = ty->termstate.top_margin + 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
for (i = 0; i < arg; i++)
|
|
|
|
{
|
2015-06-01 13:52:07 -07:00
|
|
|
if (*cc == 'M')
|
|
|
|
termpty_text_scroll(ty, EINA_TRUE);
|
|
|
|
else
|
|
|
|
termpty_text_scroll_rev(ty, EINA_TRUE);
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
2017-05-29 14:26:32 -07:00
|
|
|
ty->termstate.top_margin = sy1;
|
|
|
|
ty->termstate.bottom_margin = sy2;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'P': // erase and scrollback N chars
|
|
|
|
arg = _csi_arg_get(&b);
|
2017-05-15 13:34:01 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
|
2013-09-14 09:52:48 -07:00
|
|
|
DBG("erase and scrollback %d chars", arg);
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
|
|
|
Termcell *cells;
|
|
|
|
int x, lim;
|
|
|
|
|
2015-04-19 10:59:29 -07:00
|
|
|
cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
|
2012-07-13 01:46:33 -07:00
|
|
|
lim = ty->w - arg;
|
2015-04-19 10:59:29 -07:00
|
|
|
for (x = ty->cursor_state.cx; x < (ty->w); x++)
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
|
|
|
if (x < lim)
|
2013-01-29 07:54:47 -08:00
|
|
|
termpty_cell_copy(ty, &(cells[x + arg]), &(cells[x]), 1);
|
2012-07-13 01:46:33 -07:00
|
|
|
else
|
2013-11-23 10:29:31 -08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-04-17 13:13:00 -07:00
|
|
|
case 'c': // query device attributes
|
2013-05-27 13:03:34 -07:00
|
|
|
DBG("query device attributes");
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
|
|
|
char bf[32];
|
2013-04-17 13:13:00 -07:00
|
|
|
if (b && *b == '>')
|
|
|
|
{
|
|
|
|
// Primary device attributes
|
|
|
|
// 0 → VT100
|
|
|
|
// 1 → VT220
|
|
|
|
// 2 → VT240
|
|
|
|
// 18 → VT330
|
|
|
|
// 19 → VT340
|
|
|
|
// 24 → VT320
|
|
|
|
// 41 → VT420
|
|
|
|
// 61 → VT510
|
|
|
|
// 64 → VT520
|
|
|
|
// 65 → VT525
|
|
|
|
snprintf(bf, sizeof(bf), "\033[>41;285;%ic", 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Secondary device attributes
|
|
|
|
snprintf(bf, sizeof(bf), "\033[?64;1;2;6;9;15;18;21;22c");
|
|
|
|
}
|
2012-07-13 01:46:33 -07:00
|
|
|
termpty_write(ty, bf, strlen(bf));
|
|
|
|
}
|
|
|
|
break;
|
2016-12-20 13:43:37 -08:00
|
|
|
case 'J':
|
|
|
|
if (*b == '?')
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2016-12-20 13:43:37 -08:00
|
|
|
b++;
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
WRN("Unsupported selected erase in display %d", arg);
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
2015-06-01 13:52:07 -07:00
|
|
|
else
|
2016-12-20 13:43:37 -08:00
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (arg < 1) arg = 0;
|
|
|
|
/* 3J erases the backlog,
|
|
|
|
* 2J erases the screen,
|
|
|
|
* 1J erase from screen start to cursor,
|
|
|
|
* 0J erase form cursor to end of screen
|
|
|
|
*/
|
|
|
|
DBG("ED/DECSED %d: erase in display", arg);
|
|
|
|
switch (arg)
|
|
|
|
{
|
|
|
|
case TERMPTY_CLR_END:
|
|
|
|
case TERMPTY_CLR_BEGIN:
|
|
|
|
case TERMPTY_CLR_ALL:
|
|
|
|
termpty_clear_screen(ty, arg);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
termpty_clear_backlog(ty);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("invalid EL/DECSEL argument %d", arg);
|
|
|
|
}
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'K': // 0K erase to end of line, 1K erase from screen start to cursor, 2K erase all of line
|
2016-12-20 13:43:37 -08:00
|
|
|
if (*b == '?')
|
|
|
|
{
|
|
|
|
b++;
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
WRN("Unsupported selected erase in line %d", arg);
|
|
|
|
}
|
2012-07-13 01:46:33 -07:00
|
|
|
arg = _csi_arg_get(&b);
|
2016-12-20 13:43:37 -08:00
|
|
|
if (arg < 1) arg = 0;
|
|
|
|
DBG("EL/DECSEL %d: erase in line", arg);
|
|
|
|
switch (arg)
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2016-12-20 13:43:37 -08:00
|
|
|
case TERMPTY_CLR_END:
|
|
|
|
case TERMPTY_CLR_BEGIN:
|
|
|
|
case TERMPTY_CLR_ALL:
|
|
|
|
termpty_clear_line(ty, arg, ty->w);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("invalid EL/DECSEL argument %d", arg);
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
break;
|
2014-08-11 13:02:56 -07:00
|
|
|
case 'h':
|
2012-07-13 01:46:33 -07:00
|
|
|
case 'l':
|
2014-08-11 13:02:56 -07:00
|
|
|
_handle_esc_csi_reset_mode(ty, *cc, b);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
if (!b)
|
|
|
|
{
|
2013-11-10 06:35:16 -08:00
|
|
|
WRN("no region args reset region");
|
2017-05-29 14:26:32 -07:00
|
|
|
ty->termstate.top_margin = 0;
|
|
|
|
ty->termstate.bottom_margin = 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int arg2;
|
|
|
|
|
|
|
|
arg2 = _csi_arg_get(&b);
|
|
|
|
if (!b)
|
|
|
|
{
|
2017-05-30 15:39:02 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
|
|
|
ty->termstate.top_margin = arg - 1;
|
2017-05-29 14:26:32 -07:00
|
|
|
ty->termstate.bottom_margin = 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (arg > arg2)
|
|
|
|
{
|
2013-11-10 06:35:16 -08:00
|
|
|
DBG("scroll region beginning > end [%i %i]", arg, arg2);
|
2017-05-29 14:26:32 -07:00
|
|
|
ty->termstate.top_margin = 0;
|
|
|
|
ty->termstate.bottom_margin = 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-10 06:35:16 -08:00
|
|
|
DBG("2 regions args: %i %i", arg, arg2);
|
2017-05-16 13:48:18 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
2017-05-17 12:49:29 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(arg2, 1, ty->h+1);
|
2017-05-29 14:26:32 -07:00
|
|
|
ty->termstate.top_margin = arg - 1;
|
|
|
|
ty->termstate.bottom_margin = arg2;
|
2013-11-17 08:25:09 -08:00
|
|
|
if ((arg == 1) && (arg2 == ty->h))
|
2017-05-29 14:26:32 -07:00
|
|
|
ty->termstate.bottom_margin = 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
}
|
2017-06-03 14:17:33 -07:00
|
|
|
_move_cursor_to_origin(ty);
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
break;
|
2017-06-03 14:17:33 -07:00
|
|
|
case 's':
|
|
|
|
if (ty->termstate.lr_margins)
|
|
|
|
{
|
|
|
|
_handle_esc_csi_decslrm(ty, &b);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG("SCOSC: Save Current Cursor Position");
|
|
|
|
termpty_cursor_copy(ty, EINA_TRUE);
|
|
|
|
}
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
2016-05-21 06:15:19 -07:00
|
|
|
case 't': // window manipulation
|
2015-08-17 14:18:04 -07:00
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
WRN("TODO: window operation %d not supported", arg);
|
|
|
|
break;
|
2012-07-13 01:46:33 -07:00
|
|
|
case 'u': // restore cursor pos
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_cursor_copy(ty, EINA_FALSE);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
2014-03-01 06:39:20 -08:00
|
|
|
case 'p': // define key assignments based on keycode
|
|
|
|
if (b && *b == '!')
|
|
|
|
{
|
|
|
|
DBG("soft reset (DECSTR)");
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_reset_state(ty);
|
2014-03-01 06:39:20 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
goto unhandled;
|
|
|
|
}
|
|
|
|
break;
|
2014-08-14 12:48:26 -07:00
|
|
|
case 'n':
|
|
|
|
_handle_esc_csi_dsr(ty, b);
|
|
|
|
break;
|
2012-07-13 01:46:33 -07:00
|
|
|
/*
|
|
|
|
case 'R': // report cursor
|
|
|
|
break;
|
|
|
|
case 'q': // set/clear led's
|
|
|
|
break;
|
|
|
|
case 'x': // request terminal parameters
|
|
|
|
break;
|
|
|
|
case 'y': // invoke confidence test
|
|
|
|
break;
|
2015-01-10 08:02:54 -08:00
|
|
|
*/
|
2012-07-13 01:46:33 -07:00
|
|
|
case 'g': // clear tabulation
|
2015-01-10 08:02:54 -08:00
|
|
|
arg = _csi_arg_get(&b);
|
2016-12-18 09:48:03 -08:00
|
|
|
if (arg < 0) arg = 0;
|
|
|
|
if (arg == 0)
|
|
|
|
{
|
|
|
|
int cx = ty->cursor_state.cx;
|
|
|
|
TAB_UNSET(ty, cx);
|
|
|
|
}
|
|
|
|
else if (arg == 3)
|
|
|
|
{
|
|
|
|
termpty_clear_tabs_on_screen(ty);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Tabulation Clear (TBC) with invalid argument: %d", arg);
|
|
|
|
}
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
2016-12-18 10:17:42 -08:00
|
|
|
case 'Z':
|
|
|
|
{
|
|
|
|
int cx = ty->cursor_state.cx;
|
2012-10-04 08:23:07 -07:00
|
|
|
|
2016-12-18 10:17:42 -08:00
|
|
|
arg = _csi_arg_get(&b);
|
|
|
|
DBG("Cursor Backward Tabulation (CBT): %d", arg);
|
2017-05-15 13:34:01 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
|
2016-12-18 10:17:42 -08:00
|
|
|
for (; arg > 0; arg--)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
cx--;
|
|
|
|
}
|
|
|
|
while ((cx >= 0) && (!TAB_TEST(ty, cx)));
|
|
|
|
}
|
2016-12-15 13:57:30 -08:00
|
|
|
|
2016-12-18 10:17:42 -08:00
|
|
|
ty->cursor_state.cx = cx;
|
|
|
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
arg = _csi_arg_get(&b);
|
2017-05-15 13:34:01 -07:00
|
|
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
|
2016-12-18 10:17:42 -08:00
|
|
|
DBG("Cursor Forward Tabulation (CHT): %d", arg);
|
|
|
|
_tab_forward(ty, arg);
|
|
|
|
break;
|
2012-07-13 01:46:33 -07:00
|
|
|
default:
|
2016-12-18 10:17:42 -08:00
|
|
|
goto unhandled;
|
2014-03-01 06:29:32 -08:00
|
|
|
}
|
|
|
|
cc++;
|
|
|
|
return cc - c;
|
|
|
|
unhandled:
|
2017-05-17 14:33:06 -07:00
|
|
|
#ifndef ENABLE_FUZZING
|
2017-05-15 14:54:25 -07:00
|
|
|
if (eina_log_domain_level_check(_termpty_log_dom, EINA_LOG_LEVEL_WARN))
|
2014-03-01 06:29:32 -08:00
|
|
|
{
|
2014-03-05 12:42:33 -08:00
|
|
|
Eina_Strbuf *bf = eina_strbuf_new();
|
|
|
|
|
|
|
|
for (i = 0; c + i <= cc && i < 100; i++)
|
|
|
|
{
|
|
|
|
if ((c[i] < ' ') || (c[i] >= 0x7f))
|
2015-02-23 13:20:18 -08:00
|
|
|
eina_strbuf_append_printf(bf, "\033[35m%08x\033[0m",
|
|
|
|
(unsigned int) c[i]);
|
2014-03-05 12:42:33 -08:00
|
|
|
else
|
|
|
|
eina_strbuf_append_char(bf, c[i]);
|
|
|
|
}
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("unhandled CSI '%s': %s", _safechar(*cc), eina_strbuf_string_get(bf));
|
2014-03-05 12:42:33 -08:00
|
|
|
eina_strbuf_free(bf);
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
2017-05-17 14:33:06 -07:00
|
|
|
#endif
|
2012-07-13 01:46:33 -07:00
|
|
|
cc++;
|
|
|
|
return cc - c;
|
|
|
|
}
|
|
|
|
|
2014-08-17 08:32:57 -07:00
|
|
|
static int
|
|
|
|
_xterm_arg_get(Eina_Unicode **ptr)
|
|
|
|
{
|
|
|
|
Eina_Unicode *b = *ptr;
|
|
|
|
int sum = 0;
|
|
|
|
|
2014-09-15 14:10:55 -07:00
|
|
|
while (*b >= '0' && *b <= '9')
|
2014-08-17 08:32:57 -07:00
|
|
|
{
|
|
|
|
sum *= 10;
|
|
|
|
sum += *b - '0';
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
if (*b != ';')
|
|
|
|
sum = -1;
|
|
|
|
else
|
|
|
|
b++;
|
|
|
|
*ptr = b;
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2014-08-17 13:20:40 -07:00
|
|
|
static int
|
|
|
|
_eina_unicode_to_hex(Eina_Unicode u)
|
|
|
|
{
|
|
|
|
if (u >= '0' && u <= '9')
|
|
|
|
return u - '0';
|
|
|
|
if (u >= 'a' && u <= 'f')
|
|
|
|
return 10 + u - 'a';
|
|
|
|
if (u >= 'A' && u <= 'F')
|
|
|
|
return 10 + u - 'A';
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_xterm_parse_color(Eina_Unicode **ptr, unsigned char *r, unsigned char *g,
|
|
|
|
unsigned char *b, int len)
|
|
|
|
{
|
|
|
|
Eina_Unicode *p = *ptr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (*p != '#')
|
|
|
|
{
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("unsupported xterm color");
|
2014-08-17 13:20:40 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
len--;
|
|
|
|
if (len == 7)
|
|
|
|
{
|
|
|
|
i = _eina_unicode_to_hex(p[0]);
|
|
|
|
if (i < 0) goto err;
|
|
|
|
*r = i;
|
|
|
|
i = _eina_unicode_to_hex(p[1]);
|
|
|
|
if (i < 0) goto err;
|
|
|
|
*r = *r * 16 + i;
|
|
|
|
|
|
|
|
i = _eina_unicode_to_hex(p[2]);
|
|
|
|
if (i < 0) goto err;
|
|
|
|
*g = i;
|
|
|
|
i = _eina_unicode_to_hex(p[3]);
|
|
|
|
if (i < 0) goto err;
|
|
|
|
*g = *g * 16 + i;
|
|
|
|
|
|
|
|
i = _eina_unicode_to_hex(p[4]);
|
|
|
|
if (i < 0) goto err;
|
|
|
|
*b = i;
|
|
|
|
i = _eina_unicode_to_hex(p[5]);
|
|
|
|
if (i < 0) goto err;
|
|
|
|
*b = *b * 16 + i;
|
|
|
|
}
|
|
|
|
else if (len == 4)
|
|
|
|
{
|
|
|
|
i = _eina_unicode_to_hex(p[0]);
|
|
|
|
if (i < 0) goto err;
|
|
|
|
*r = i;
|
|
|
|
i = _eina_unicode_to_hex(p[1]);
|
|
|
|
if (i < 0) goto err;
|
|
|
|
*g = i;
|
|
|
|
i = _eina_unicode_to_hex(p[2]);
|
|
|
|
if (i < 0) goto err;
|
|
|
|
*b = i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("invalid xterm color");
|
2014-08-17 13:20:40 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-05-21 05:40:41 -07:00
|
|
|
static void
|
|
|
|
_handle_xterm_50_command(Termpty *ty,
|
|
|
|
char *s,
|
|
|
|
int len)
|
|
|
|
{
|
2017-05-28 13:49:39 -07:00
|
|
|
int pattern_len = strlen(":size=");
|
|
|
|
while (len > pattern_len)
|
2016-05-21 05:40:41 -07:00
|
|
|
{
|
2017-05-28 13:49:39 -07:00
|
|
|
if (strncmp(s, ":size=", pattern_len) == 0)
|
2016-05-21 05:40:41 -07:00
|
|
|
{
|
2017-05-28 13:49:39 -07:00
|
|
|
char *endptr = NULL;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
s += pattern_len;
|
|
|
|
errno = 0;
|
|
|
|
size = strtol(s, &endptr, 10);
|
|
|
|
if (endptr != s && errno == 0)
|
|
|
|
termio_font_size_set(ty->obj, size);
|
2016-05-21 05:40:41 -07:00
|
|
|
}
|
2017-05-28 13:49:39 -07:00
|
|
|
len--;
|
|
|
|
s++;
|
2016-05-21 05:40:41 -07:00
|
|
|
}
|
|
|
|
}
|
2014-08-17 13:20:40 -07:00
|
|
|
|
2015-01-12 14:11:12 -08:00
|
|
|
static void
|
2016-10-05 13:00:22 -07:00
|
|
|
_handle_xterm_777_command(Termpty *_ty EINA_UNUSED,
|
2015-02-14 03:08:50 -08:00
|
|
|
char *s
|
|
|
|
#if ((ELM_VERSION_MAJOR == 1) && (ELM_VERSION_MINOR < 8))
|
|
|
|
EINA_UNUSED
|
|
|
|
#endif
|
2016-10-05 13:00:22 -07:00
|
|
|
, int _len EINA_UNUSED)
|
2015-01-12 14:11:12 -08:00
|
|
|
{
|
|
|
|
#if (ELM_VERSION_MAJOR > 1) || (ELM_VERSION_MINOR >= 8)
|
|
|
|
char *cmd_end = NULL,
|
|
|
|
*title = NULL,
|
|
|
|
*title_end = NULL,
|
|
|
|
*message = NULL;
|
|
|
|
|
|
|
|
if (strncmp(s, "notify;", strlen("notify;")))
|
|
|
|
{
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("unrecognized xterm 777 command %s", s);
|
2015-01-12 14:11:12 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!elm_need_sys_notify())
|
|
|
|
{
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("no elementary system notification support");
|
2015-01-12 14:11:12 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
cmd_end = s + strlen("notify");
|
|
|
|
if (*cmd_end != ';')
|
|
|
|
return;
|
|
|
|
*cmd_end = '\0';
|
|
|
|
title = cmd_end + 1;
|
|
|
|
title_end = strchr(title, ';');
|
|
|
|
if (!title_end)
|
|
|
|
{
|
|
|
|
*cmd_end = ';';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*title_end = '\0';
|
|
|
|
message = title_end + 1;
|
|
|
|
|
|
|
|
elm_sys_notify_send(0, "dialog-information", title, message,
|
|
|
|
ELM_SYS_NOTIFY_URGENCY_NORMAL, -1,
|
|
|
|
NULL, NULL);
|
|
|
|
*cmd_end = ';';
|
|
|
|
*title_end = ';';
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-07-13 01:46:33 -07:00
|
|
|
static int
|
|
|
|
_handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
|
|
|
|
{
|
2014-03-05 13:23:13 -08:00
|
|
|
const Eina_Unicode *cc, *be;
|
2014-08-17 13:20:40 -07:00
|
|
|
Eina_Unicode buf[4096], *p;
|
2012-07-13 01:46:33 -07:00
|
|
|
char *s;
|
|
|
|
int len = 0;
|
2014-08-17 08:32:57 -07:00
|
|
|
int arg;
|
2014-03-05 13:23:13 -08:00
|
|
|
|
2012-09-28 04:12:15 -07:00
|
|
|
cc = c;
|
2014-08-17 13:20:40 -07:00
|
|
|
p = buf;
|
2014-03-05 13:23:13 -08:00
|
|
|
be = buf + sizeof(buf) / sizeof(buf[0]);
|
2014-08-17 13:20:40 -07:00
|
|
|
while ((cc < ce) && (*cc != ST) && (*cc != BEL) && (p < be))
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2012-10-04 16:18:54 -07:00
|
|
|
if ((cc < ce - 1) && (*cc == ESC) && (*(cc + 1) == '\\'))
|
|
|
|
{
|
|
|
|
cc++;
|
|
|
|
break;
|
|
|
|
}
|
2014-08-17 13:20:40 -07:00
|
|
|
*p = *cc;
|
|
|
|
p++;
|
2012-07-13 01:46:33 -07:00
|
|
|
cc++;
|
|
|
|
}
|
2014-08-17 13:20:40 -07:00
|
|
|
if (p == be)
|
2014-03-05 13:23:13 -08:00
|
|
|
{
|
|
|
|
ERR("xterm parsing overflowed, skipping the whole buffer (binary data?)");
|
|
|
|
return cc - c;
|
|
|
|
}
|
2014-08-17 13:20:40 -07:00
|
|
|
*p = 0;
|
|
|
|
p = buf;
|
2012-10-04 16:18:54 -07:00
|
|
|
if ((*cc == ST) || (*cc == BEL) || (*cc == '\\')) cc++;
|
2012-12-14 10:52:19 -08:00
|
|
|
else return 0;
|
2014-08-17 08:32:57 -07:00
|
|
|
|
2014-08-17 08:44:19 -07:00
|
|
|
#define TERMPTY_WRITE_STR(_S) \
|
|
|
|
termpty_write(ty, _S, strlen(_S))
|
|
|
|
|
2014-08-17 13:20:40 -07:00
|
|
|
arg = _xterm_arg_get(&p);
|
2014-08-17 08:32:57 -07:00
|
|
|
switch (arg)
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2014-08-17 08:32:57 -07:00
|
|
|
case -1:
|
|
|
|
goto err;
|
|
|
|
case 0:
|
2012-07-13 01:46:33 -07:00
|
|
|
// XXX: title + name - callback
|
2014-08-17 13:20:40 -07:00
|
|
|
if (!*p)
|
2014-08-17 08:32:57 -07:00
|
|
|
goto err;
|
2014-08-17 13:20:40 -07:00
|
|
|
if (*p == '?')
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2015-08-17 14:13:10 -07:00
|
|
|
/* returns empty string. See CVE-2003-0063 */
|
|
|
|
TERMPTY_WRITE_STR("\033]0;Terminology\007");
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-17 13:20:40 -07:00
|
|
|
s = eina_unicode_unicode_to_utf8(p, &len);
|
2014-08-17 08:44:19 -07:00
|
|
|
if (ty->prop.title) eina_stringshare_del(ty->prop.title);
|
|
|
|
if (ty->prop.icon) eina_stringshare_del(ty->prop.icon);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
ty->prop.title = eina_stringshare_add(s);
|
|
|
|
ty->prop.icon = eina_stringshare_add(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ty->prop.title = NULL;
|
|
|
|
ty->prop.icon = NULL;
|
|
|
|
}
|
2016-03-02 06:37:02 -08:00
|
|
|
if (ty->cb.set_title.func && !ty->prop.user_title)
|
|
|
|
ty->cb.set_title.func(ty->cb.set_title.data);
|
2014-08-17 08:44:19 -07:00
|
|
|
if (ty->cb.set_icon.func) ty->cb.set_icon.func(ty->cb.set_icon.data);
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
break;
|
2014-08-17 08:32:57 -07:00
|
|
|
case 1:
|
2014-08-17 08:44:19 -07:00
|
|
|
// XXX: icon name - callback
|
2014-08-17 13:20:40 -07:00
|
|
|
if (!*p)
|
2014-08-17 08:32:57 -07:00
|
|
|
goto err;
|
2014-08-17 13:20:40 -07:00
|
|
|
if (*p == '?')
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2015-08-17 14:13:10 -07:00
|
|
|
/* returns empty string. See CVE-2003-0063 */
|
|
|
|
TERMPTY_WRITE_STR("\033]1;Terminology\007");
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-17 13:20:40 -07:00
|
|
|
s = eina_unicode_unicode_to_utf8(p, &len);
|
2014-08-17 08:44:19 -07:00
|
|
|
if (ty->prop.icon) eina_stringshare_del(ty->prop.icon);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
ty->prop.icon = eina_stringshare_add(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ty->prop.icon = NULL;
|
|
|
|
}
|
|
|
|
if (ty->cb.set_icon.func) ty->cb.set_icon.func(ty->cb.set_icon.data);
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
break;
|
2014-08-17 08:32:57 -07:00
|
|
|
case 2:
|
2014-08-17 08:44:19 -07:00
|
|
|
// XXX: title - callback
|
2014-08-17 13:20:40 -07:00
|
|
|
if (!*p)
|
2014-08-17 08:32:57 -07:00
|
|
|
goto err;
|
2014-08-17 13:20:40 -07:00
|
|
|
if (*p == '?')
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2015-08-17 14:13:10 -07:00
|
|
|
/* returns empty string. See CVE-2003-0063 */
|
|
|
|
TERMPTY_WRITE_STR("\033]2;Terminology\007");
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-17 13:20:40 -07:00
|
|
|
s = eina_unicode_unicode_to_utf8(p, &len);
|
2014-08-17 08:44:19 -07:00
|
|
|
if (ty->prop.title) eina_stringshare_del(ty->prop.title);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
ty->prop.title = eina_stringshare_add(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ty->prop.title = NULL;
|
|
|
|
}
|
|
|
|
if (ty->cb.set_title.func) ty->cb.set_title.func(ty->cb.set_title.data);
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
break;
|
2014-08-17 08:32:57 -07:00
|
|
|
case 4:
|
2014-08-17 13:20:40 -07:00
|
|
|
if (!*p)
|
2014-08-17 08:32:57 -07:00
|
|
|
goto err;
|
2012-07-13 01:46:33 -07:00
|
|
|
// XXX: set palette entry. not supported.
|
2014-08-17 08:32:57 -07:00
|
|
|
WRN("set palette, not supported");
|
2012-12-14 10:52:19 -08:00
|
|
|
if ((cc - c) < 3) return 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
2014-08-17 13:20:40 -07:00
|
|
|
case 10:
|
|
|
|
if (!*p)
|
|
|
|
goto err;
|
|
|
|
if (*p == '?')
|
|
|
|
{
|
|
|
|
char bf[6];
|
|
|
|
Config *config = termio_config_get(ty->obj);
|
|
|
|
TERMPTY_WRITE_STR("\033]10;#");
|
|
|
|
snprintf(bf, sizeof(bf), "%.2X%.2X%.2X",
|
|
|
|
config->colors[0].r,
|
|
|
|
config->colors[0].g,
|
|
|
|
config->colors[0].b);
|
|
|
|
termpty_write(ty, bf, 6);
|
|
|
|
TERMPTY_WRITE_STR("\007");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned char r, g, b;
|
|
|
|
len = cc - c - (p - buf);
|
|
|
|
if (_xterm_parse_color(&p, &r, &g, &b, len) < 0)
|
|
|
|
goto err;
|
2015-11-14 12:25:39 -08:00
|
|
|
#ifndef ENABLE_FUZZING
|
2014-08-17 13:20:40 -07:00
|
|
|
evas_object_textgrid_palette_set(
|
|
|
|
termio_textgrid_get(ty->obj),
|
|
|
|
EVAS_TEXTGRID_PALETTE_STANDARD, 0,
|
|
|
|
r, g, b, 0xff);
|
2015-11-14 12:25:39 -08:00
|
|
|
#endif
|
2014-08-17 13:20:40 -07:00
|
|
|
}
|
|
|
|
break;
|
2016-05-21 05:40:41 -07:00
|
|
|
case 50:
|
|
|
|
DBG("xterm font support");
|
|
|
|
if (!*p)
|
|
|
|
goto err;
|
|
|
|
s = eina_unicode_unicode_to_utf8(p, &len);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
_handle_xterm_50_command(ty, s, len);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
break;
|
2015-01-12 14:11:12 -08:00
|
|
|
case 777:
|
|
|
|
DBG("xterm notification support");
|
|
|
|
s = eina_unicode_unicode_to_utf8(p, &len);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
_handle_xterm_777_command(ty, s, len);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
break;
|
2012-07-13 01:46:33 -07:00
|
|
|
default:
|
|
|
|
// many others
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("unhandled xterm esc %d", arg);
|
2012-07-13 01:46:33 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-08-17 08:44:19 -07:00
|
|
|
|
|
|
|
#undef TERMPTY_WRITE_STR
|
|
|
|
|
2012-07-13 01:46:33 -07:00
|
|
|
return cc - c;
|
2014-08-17 08:32:57 -07:00
|
|
|
err:
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("invalid xterm sequence");
|
2014-08-17 08:32:57 -07:00
|
|
|
return cc - c;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-03-13 18:58:43 -07:00
|
|
|
_handle_esc_terminology(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2013-03-17 07:52:13 -07:00
|
|
|
Eina_Unicode *cc;
|
2013-01-29 07:54:47 -08:00
|
|
|
Eina_Unicode *buf, bufsmall[1024], *b;
|
2015-08-23 11:57:49 -07:00
|
|
|
char *cmd;
|
|
|
|
int blen = 0;
|
|
|
|
Config *config;
|
|
|
|
|
|
|
|
config = termio_config_get(ty->obj);
|
2012-07-13 01:46:33 -07:00
|
|
|
|
2013-01-29 07:54:47 -08:00
|
|
|
cc = (Eina_Unicode *)c;
|
|
|
|
while ((cc < ce) && (*cc != 0x0))
|
|
|
|
{
|
|
|
|
blen++;
|
|
|
|
cc++;
|
|
|
|
}
|
|
|
|
buf = bufsmall;
|
2013-03-14 04:27:36 -07:00
|
|
|
if (blen > (int)((sizeof(bufsmall) / sizeof(Eina_Unicode)) - 40))
|
|
|
|
buf = malloc((blen * sizeof(Eina_Unicode)) + 40);
|
2012-07-13 01:46:33 -07:00
|
|
|
cc = (Eina_Unicode *)c;
|
|
|
|
b = buf;
|
2013-03-14 04:27:36 -07:00
|
|
|
while ((cc < ce) && (*cc != 0x0))
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
|
|
|
*b = *cc;
|
|
|
|
b++;
|
|
|
|
cc++;
|
|
|
|
}
|
2013-03-14 04:27:36 -07:00
|
|
|
if ((cc < ce) && (*cc == 0x0)) cc++;
|
2013-01-29 07:54:47 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (buf != bufsmall) free(buf);
|
2013-03-14 04:27:36 -07:00
|
|
|
return 0;
|
2013-01-29 07:54:47 -08:00
|
|
|
}
|
2013-03-13 18:58:43 -07:00
|
|
|
*b = 0;
|
2015-08-23 11:57:49 -07:00
|
|
|
|
2015-08-03 11:52:54 -07:00
|
|
|
// commands are stored in the buffer, 0 bytes not allowed (end marker)
|
2015-08-23 11:57:49 -07:00
|
|
|
cmd = eina_unicode_unicode_to_utf8(buf, NULL);
|
|
|
|
ty->cur_cmd = cmd;
|
|
|
|
if ((!config->ty_escapes) || (!_termpty_ext_handle(ty, cmd, buf)))
|
2012-07-13 01:47:14 -07:00
|
|
|
{
|
|
|
|
if (ty->cb.command.func) ty->cb.command.func(ty->cb.command.data);
|
|
|
|
}
|
2012-07-13 01:46:33 -07:00
|
|
|
ty->cur_cmd = NULL;
|
2015-08-23 11:57:49 -07:00
|
|
|
free(cmd);
|
|
|
|
|
2013-01-29 07:54:47 -08:00
|
|
|
if (buf != bufsmall) free(buf);
|
2012-07-13 01:46:33 -07:00
|
|
|
return cc - c;
|
|
|
|
}
|
|
|
|
|
2012-10-04 16:18:59 -07:00
|
|
|
static int
|
2016-10-05 13:00:22 -07:00
|
|
|
_handle_esc_dcs(Termpty *ty,
|
|
|
|
const Eina_Unicode *c,
|
|
|
|
const Eina_Unicode *ce)
|
2012-10-04 16:18:59 -07:00
|
|
|
{
|
2013-03-13 18:58:43 -07:00
|
|
|
const Eina_Unicode *cc, *be;
|
2012-10-04 16:18:59 -07:00
|
|
|
Eina_Unicode buf[4096], *b;
|
2013-06-19 01:18:42 -07:00
|
|
|
int len = 0;
|
2013-04-17 13:55:37 -07:00
|
|
|
|
2012-10-04 16:18:59 -07:00
|
|
|
cc = c;
|
|
|
|
b = buf;
|
2013-03-13 18:58:43 -07:00
|
|
|
be = buf + sizeof(buf) / sizeof(buf[0]);
|
2014-03-05 13:23:13 -08:00
|
|
|
while ((cc < ce) && (*cc != ST) && (b < be))
|
2012-10-04 16:18:59 -07:00
|
|
|
{
|
|
|
|
if ((cc < ce - 1) && (*cc == ESC) && (*(cc + 1) == '\\'))
|
|
|
|
{
|
|
|
|
cc++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*b = *cc;
|
|
|
|
b++;
|
|
|
|
cc++;
|
|
|
|
}
|
2013-03-13 18:58:43 -07:00
|
|
|
if (b == be)
|
2013-04-17 13:55:37 -07:00
|
|
|
{
|
2014-02-11 13:18:12 -08:00
|
|
|
ERR("dcs parsing overflowed, skipping the whole buffer (binary data?)");
|
|
|
|
len = cc - c;
|
2013-04-17 13:55:37 -07:00
|
|
|
goto end;
|
|
|
|
}
|
2012-10-04 16:18:59 -07:00
|
|
|
*b = 0;
|
|
|
|
if ((*cc == ST) || (*cc == '\\')) cc++;
|
2012-12-14 10:52:19 -08:00
|
|
|
else return 0;
|
2013-05-10 14:01:58 -07:00
|
|
|
len = cc - c;
|
2012-10-04 16:18:59 -07:00
|
|
|
switch (buf[0])
|
|
|
|
{
|
|
|
|
case '+':
|
2013-05-10 14:02:46 -07:00
|
|
|
if (len < 4)
|
|
|
|
goto end;
|
|
|
|
switch (buf[1])
|
|
|
|
{
|
|
|
|
case 'q':
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("unhandled dsc request to get termcap/terminfo");
|
2013-05-10 14:02:46 -07:00
|
|
|
/* TODO */
|
|
|
|
goto end;
|
|
|
|
break;
|
|
|
|
case 'p':
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("unhandled dsc request to set termcap/terminfo");
|
2013-05-10 14:02:46 -07:00
|
|
|
/* TODO */
|
|
|
|
goto end;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("invalid dsc request about termcap/terminfo");
|
|
|
|
goto end;
|
|
|
|
}
|
2012-10-04 16:18:59 -07:00
|
|
|
break;
|
2013-04-17 13:55:37 -07:00
|
|
|
case '$':
|
|
|
|
/* Request status string */
|
|
|
|
if (len > 1 && buf[1] != 'q')
|
|
|
|
{
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("invalid/unhandled dsc esc '$%s' (expected '$q')", _safechar(buf[1]));
|
2013-04-17 13:55:37 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (len < 4)
|
|
|
|
goto end;
|
|
|
|
switch (buf[2])
|
|
|
|
{
|
|
|
|
case '"':
|
|
|
|
if (buf[3] == 'p') /* DECSCL */
|
|
|
|
{
|
|
|
|
char bf[32];
|
|
|
|
snprintf(bf, sizeof(bf), "\033P1$r64;1\"p\033\\");
|
|
|
|
termpty_write(ty, bf, strlen(bf));
|
|
|
|
}
|
|
|
|
else if (buf[3] == 'q') /* DECSCA */
|
|
|
|
{
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("unhandled DECSCA '$qq'");
|
2013-05-10 14:02:46 -07:00
|
|
|
goto end;
|
2013-04-17 13:55:37 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("invalid/unhandled dsc esc '$q\"%s'", _safechar(buf[3]));
|
2013-04-17 13:55:37 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'm': /* SGR */
|
|
|
|
/* TODO: */
|
|
|
|
case 'r': /* DECSTBM */
|
|
|
|
/* TODO: */
|
|
|
|
default:
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("unhandled dsc request status string '$q%s'", _safechar(buf[2]));
|
2013-04-17 13:55:37 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
/* TODO */
|
|
|
|
break;
|
2012-10-04 16:18:59 -07:00
|
|
|
default:
|
|
|
|
// many others
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("Unhandled DCS escape '%s'", _safechar(buf[0]));
|
2012-10-04 16:18:59 -07:00
|
|
|
break;
|
|
|
|
}
|
2013-04-17 13:55:37 -07:00
|
|
|
end:
|
|
|
|
return len;
|
2012-10-04 16:18:59 -07:00
|
|
|
}
|
|
|
|
|
2012-07-13 01:46:33 -07:00
|
|
|
static int
|
|
|
|
_handle_esc(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
|
|
|
|
{
|
2012-12-14 10:52:19 -08:00
|
|
|
int len = ce - c;
|
|
|
|
|
|
|
|
if (len < 1) return 0;
|
2015-06-23 21:46:48 -07:00
|
|
|
DBG("ESC: '%s'", _safechar(c[0]));
|
2012-12-14 10:52:19 -08:00
|
|
|
switch (c[0])
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
|
|
|
case '[':
|
2012-12-14 10:52:19 -08:00
|
|
|
len = _handle_esc_csi(ty, c + 1, ce);
|
|
|
|
if (len == 0) return 0;
|
|
|
|
return 1 + len;
|
2012-07-13 01:46:33 -07:00
|
|
|
case ']':
|
2012-12-14 10:52:19 -08:00
|
|
|
len = _handle_esc_xterm(ty, c + 1, ce);
|
|
|
|
if (len == 0) return 0;
|
|
|
|
return 1 + len;
|
2012-07-13 01:46:33 -07:00
|
|
|
case '}':
|
2012-12-14 10:52:19 -08:00
|
|
|
len = _handle_esc_terminology(ty, c + 1, ce);
|
|
|
|
if (len == 0) return 0;
|
|
|
|
return 1 + len;
|
2012-10-04 16:18:59 -07:00
|
|
|
case 'P':
|
2012-12-14 10:52:19 -08:00
|
|
|
len = _handle_esc_dcs(ty, c + 1, ce);
|
|
|
|
if (len == 0) return 0;
|
|
|
|
return 1 + len;
|
2012-07-13 01:46:33 -07:00
|
|
|
case '=': // set alternate keypad mode
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.alt_kp = 1;
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
case '>': // set numeric keypad mode
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.alt_kp = 0;
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
case 'M': // move to prev line
|
2016-12-15 13:59:50 -08:00
|
|
|
DBG("move to prev line");
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
ty->cursor_state.cy--;
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_text_scroll_rev_test(ty, EINA_TRUE);
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
case 'D': // move to next line
|
2016-12-15 13:59:50 -08:00
|
|
|
DBG("move to next line");
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
ty->cursor_state.cy++;
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_text_scroll_test(ty, EINA_FALSE);
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
case 'E': // add \n\r
|
2016-12-15 13:59:50 -08:00
|
|
|
DBG("add \\n\\r");
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.wrapnext = 0;
|
|
|
|
ty->cursor_state.cx = 0;
|
|
|
|
ty->cursor_state.cy++;
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_text_scroll_test(ty, EINA_FALSE);
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
case 'Z': // same a 'ESC [ Pn c'
|
|
|
|
_term_txt_write(ty, "\033[?1;2C");
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
case 'c': // reset terminal to initial state
|
|
|
|
DBG("reset to init mode and clear");
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_reset_state(ty);
|
|
|
|
termpty_clear_screen(ty, TERMPTY_CLR_ALL);
|
2012-07-13 01:46:33 -07:00
|
|
|
if (ty->cb.cancel_sel.func)
|
|
|
|
ty->cb.cancel_sel.func(ty->cb.cancel_sel.data);
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
case '(': // charset 0
|
2012-12-14 10:52:19 -08:00
|
|
|
if (len < 2) return 0;
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.chset[0] = c[1];
|
|
|
|
ty->termstate.multibyte = 0;
|
|
|
|
ty->termstate.charsetch = c[1];
|
2012-12-14 10:52:19 -08:00
|
|
|
return 2;
|
2012-07-13 01:46:33 -07:00
|
|
|
case ')': // charset 1
|
2012-12-14 10:52:19 -08:00
|
|
|
if (len < 2) return 0;
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.chset[1] = c[1];
|
|
|
|
ty->termstate.multibyte = 0;
|
2012-12-14 10:52:19 -08:00
|
|
|
return 2;
|
2012-07-13 01:46:33 -07:00
|
|
|
case '*': // charset 2
|
2012-12-14 10:52:19 -08:00
|
|
|
if (len < 2) return 0;
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.chset[2] = c[1];
|
|
|
|
ty->termstate.multibyte = 0;
|
2012-12-14 10:52:19 -08:00
|
|
|
return 2;
|
2012-07-13 01:46:33 -07:00
|
|
|
case '+': // charset 3
|
2012-12-14 10:52:19 -08:00
|
|
|
if (len < 2) return 0;
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.chset[3] = c[1];
|
|
|
|
ty->termstate.multibyte = 0;
|
2012-12-14 10:52:19 -08:00
|
|
|
return 2;
|
2012-07-13 01:46:33 -07:00
|
|
|
case '$': // charset -2
|
2012-12-14 10:52:19 -08:00
|
|
|
if (len < 2) return 0;
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.chset[2] = c[1];
|
|
|
|
ty->termstate.multibyte = 1;
|
2012-12-14 10:52:19 -08:00
|
|
|
return 2;
|
2012-07-13 01:46:33 -07:00
|
|
|
case '#': // #8 == test mode -> fill screen with "E";
|
2012-12-14 10:52:19 -08:00
|
|
|
if (len < 2) return 0;
|
|
|
|
if (c[1] == '8')
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
2013-01-29 07:54:47 -08:00
|
|
|
int size;
|
2012-07-13 01:46:33 -07:00
|
|
|
Termcell *cells;
|
|
|
|
|
|
|
|
DBG("reset to init mode and clear then fill with E");
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_reset_state(ty);
|
|
|
|
termpty_clear_screen(ty, TERMPTY_CLR_ALL);
|
2012-07-13 01:46:33 -07:00
|
|
|
if (ty->cb.cancel_sel.func)
|
|
|
|
ty->cb.cancel_sel.func(ty->cb.cancel_sel.data);
|
|
|
|
cells = ty->screen;
|
|
|
|
size = ty->w * ty->h;
|
|
|
|
if (cells)
|
|
|
|
{
|
2013-01-29 07:54:47 -08:00
|
|
|
Termatt att;
|
2015-04-19 10:59:29 -07:00
|
|
|
|
2013-01-29 07:54:47 -08:00
|
|
|
memset((&att), 0, sizeof(att));
|
|
|
|
termpty_cell_codepoint_att_fill(ty, 'E', att, cells, size);
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
}
|
2012-12-14 10:52:19 -08:00
|
|
|
return 2;
|
2012-07-13 01:46:33 -07:00
|
|
|
case '@': // just consume this plus next char
|
2012-12-14 10:52:19 -08:00
|
|
|
if (len < 2) return 0;
|
|
|
|
return 2;
|
2012-07-13 01:46:33 -07:00
|
|
|
case '7': // save cursor pos
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_cursor_copy(ty, EINA_TRUE);
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
case '8': // restore cursor pos
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_cursor_copy(ty, EINA_FALSE);
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2015-01-10 09:48:48 -08:00
|
|
|
case 'H': // set tab at current column
|
2016-12-18 09:48:03 -08:00
|
|
|
DBG("Character Tabulation Set (HTS) at x:%d", ty->cursor_state.cx);
|
|
|
|
TAB_SET(ty, ty->cursor_state.cx);
|
2015-01-10 09:48:48 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
/*
|
|
|
|
case 'G': // query gfx mode
|
|
|
|
return 2;
|
|
|
|
case 'n': // single shift 2
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
case 'o': // single shift 3
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
*/
|
|
|
|
default:
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("Unhandled escape '%s' (0x%02x)", _safechar(c[0]), (unsigned int) c[0]);
|
2012-12-14 10:52:19 -08:00
|
|
|
return 1;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
2012-12-14 10:52:19 -08:00
|
|
|
return 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
|
2014-09-15 14:10:55 -07:00
|
|
|
/* XXX: ce is excluded */
|
2012-07-13 01:46:33 -07:00
|
|
|
int
|
2014-09-15 14:10:55 -07:00
|
|
|
termpty_handle_seq(Termpty *ty, Eina_Unicode *c, Eina_Unicode *ce)
|
2012-07-13 01:46:33 -07:00
|
|
|
{
|
|
|
|
Eina_Unicode *cc;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
printf(" B: ");
|
|
|
|
int j;
|
|
|
|
for (j = 0; c + j < ce && j < 100; j++)
|
|
|
|
{
|
|
|
|
if ((c[j] < ' ') || (c[j] >= 0x7f))
|
2012-09-28 04:12:04 -07:00
|
|
|
printf("\033[35m%08x\033[0m", c[j]);
|
2012-07-13 01:46:33 -07:00
|
|
|
else
|
2015-06-23 21:46:48 -07:00
|
|
|
printf("%s", _safechar(c[j]));
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
*/
|
|
|
|
if (c[0] < 0x20)
|
|
|
|
{
|
|
|
|
switch (c[0])
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
case 0x00: // NUL
|
|
|
|
return 1;
|
|
|
|
case 0x01: // SOH (start of heading)
|
|
|
|
return 1;
|
|
|
|
case 0x02: // STX (start of text)
|
|
|
|
return 1;
|
|
|
|
case 0x03: // ETX (end of text)
|
|
|
|
return 1;
|
|
|
|
case 0x04: // EOT (end of transmission)
|
|
|
|
return 1;
|
|
|
|
*/
|
2013-03-13 18:58:43 -07:00
|
|
|
/*
|
2012-07-13 01:46:33 -07:00
|
|
|
case 0x05: // ENQ (enquiry)
|
|
|
|
_term_txt_write(ty, "ABC\r\n");
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
return 1;
|
2013-03-13 18:58:43 -07:00
|
|
|
*/
|
2012-07-13 01:46:33 -07:00
|
|
|
/*
|
|
|
|
case 0x06: // ACK (acknowledge)
|
|
|
|
return 1;
|
|
|
|
*/
|
|
|
|
case 0x07: // BEL '\a' (bell)
|
|
|
|
case 0x08: // BS '\b' (backspace)
|
|
|
|
case 0x09: // HT '\t' (horizontal tab)
|
|
|
|
case 0x0a: // LF '\n' (new line)
|
|
|
|
case 0x0b: // VT '\v' (vertical tab)
|
|
|
|
case 0x0c: // FF '\f' (form feed)
|
|
|
|
case 0x0d: // CR '\r' (carriage ret)
|
2013-04-27 12:17:14 -07:00
|
|
|
_handle_cursor_control(ty, c);
|
2012-07-13 01:46:33 -07:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 0x0e: // SO (shift out) // Maps G1 character set into GL.
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
|
|
|
ty->termstate.charset = 1;
|
|
|
|
ty->termstate.charsetch = ty->termstate.chset[1];
|
2012-07-13 01:46:33 -07:00
|
|
|
return 1;
|
|
|
|
case 0x0f: // SI (shift in) // Maps G0 character set into GL.
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.charset = 0;
|
|
|
|
ty->termstate.had_cr = 0;
|
|
|
|
ty->termstate.charsetch = ty->termstate.chset[0];
|
2012-07-13 01:46:33 -07:00
|
|
|
return 1;
|
|
|
|
/*
|
|
|
|
case 0x10: // DLE (data link escape)
|
|
|
|
return 1;
|
|
|
|
case 0x11: // DC1 (device control 1)
|
|
|
|
return 1;
|
|
|
|
case 0x12: // DC2 (device control 2)
|
|
|
|
return 1;
|
|
|
|
case 0x13: // DC3 (device control 3)
|
|
|
|
return 1;
|
|
|
|
case 0x14: // DC4 (device control 4)
|
|
|
|
return 1;
|
|
|
|
case 0x15: // NAK (negative ack.)
|
|
|
|
return 1;
|
|
|
|
case 0x16: // SYN (synchronous idle)
|
|
|
|
return 1;
|
|
|
|
case 0x17: // ETB (end of trans. blk)
|
|
|
|
return 1;
|
|
|
|
case 0x18: // CAN (cancel)
|
|
|
|
return 1;
|
|
|
|
case 0x19: // EM (end of medium)
|
|
|
|
return 1;
|
|
|
|
case 0x1a: // SUB (substitute)
|
|
|
|
return 1;
|
|
|
|
*/
|
|
|
|
case 0x1b: // ESC (escape)
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
2012-12-14 10:52:19 -08:00
|
|
|
len = _handle_esc(ty, c + 1, ce);
|
|
|
|
if (len == 0) return 0;
|
|
|
|
return 1 + len;
|
2012-07-13 01:46:33 -07:00
|
|
|
/*
|
|
|
|
case 0x1c: // FS (file separator)
|
|
|
|
return 1;
|
|
|
|
case 0x1d: // GS (group separator)
|
|
|
|
return 1;
|
|
|
|
case 0x1e: // RS (record separator)
|
|
|
|
return 1;
|
|
|
|
case 0x1f: // US (unit separator)
|
|
|
|
return 1;
|
|
|
|
*/
|
|
|
|
default:
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
2013-05-03 19:44:20 -07:00
|
|
|
//ERR("unhandled char 0x%02x", c[0]);
|
2012-07-13 01:46:33 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c[0] == 0x7f) // DEL
|
|
|
|
{
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
2015-09-08 12:59:11 -07:00
|
|
|
WRN("Unhandled char 0x%02x [DEL]", (unsigned int) c[0]);
|
2012-07-13 01:46:33 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (c[0] == 0x9b) // ANSI ESC!!!
|
|
|
|
{
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
2013-05-03 19:44:20 -07:00
|
|
|
DBG("ANSI CSI!!!!!");
|
2012-12-14 10:52:19 -08:00
|
|
|
len = _handle_esc_csi(ty, c + 1, ce);
|
|
|
|
if (len == 0) return 0;
|
|
|
|
return 1 + len;
|
2012-07-13 01:46:33 -07:00
|
|
|
}
|
2013-01-28 19:34:50 -08:00
|
|
|
else if ((ty->block.expecting) && (ty->block.on))
|
2013-01-28 08:06:26 -08:00
|
|
|
{
|
2013-01-28 16:43:13 -08:00
|
|
|
Termexp *ex;
|
|
|
|
Eina_List *l;
|
|
|
|
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
2013-01-28 16:43:13 -08:00
|
|
|
EINA_LIST_FOREACH(ty->block.expecting, l, ex)
|
2013-01-28 08:06:26 -08:00
|
|
|
{
|
2013-01-28 16:43:13 -08:00
|
|
|
if (c[0] == ex->ch)
|
2013-01-28 08:06:26 -08:00
|
|
|
{
|
2013-01-28 16:43:13 -08:00
|
|
|
Eina_Unicode cp;
|
|
|
|
|
|
|
|
cp = (1 << 31) | ((ex->id & 0x1fff) << 18) |
|
|
|
|
((ex->x & 0x1ff) << 9) | (ex->y & 0x1ff);
|
|
|
|
ex->x++;
|
|
|
|
if (ex->x >= ex->w)
|
|
|
|
{
|
|
|
|
ex->x = 0;
|
|
|
|
ex->y++;
|
|
|
|
}
|
|
|
|
ex->left--;
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_text_append(ty, &cp, 1);
|
2013-01-28 16:43:13 -08:00
|
|
|
if (ex->left <= 0)
|
|
|
|
{
|
|
|
|
ty->block.expecting =
|
|
|
|
eina_list_remove_list(ty->block.expecting, l);
|
|
|
|
free(ex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ty->block.expecting =
|
|
|
|
eina_list_promote_list(ty->block.expecting, l);
|
|
|
|
return 1;
|
2013-01-28 08:06:26 -08:00
|
|
|
}
|
|
|
|
}
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_text_append(ty, c, 1);
|
2013-01-28 16:43:13 -08:00
|
|
|
return 1;
|
2013-01-28 08:06:26 -08:00
|
|
|
}
|
2013-05-03 19:44:20 -07:00
|
|
|
else
|
|
|
|
{
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
2013-05-03 19:44:20 -07:00
|
|
|
}
|
2015-02-23 13:20:18 -08:00
|
|
|
cc = (Eina_Unicode *)c;
|
2012-07-13 01:46:33 -07:00
|
|
|
DBG("txt: [");
|
|
|
|
while ((cc < ce) && (*cc >= 0x20) && (*cc != 0x7f))
|
|
|
|
{
|
2015-06-23 21:46:48 -07:00
|
|
|
DBG("%s", _safechar(*cc));
|
2012-07-13 01:46:33 -07:00
|
|
|
cc++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
DBG("]");
|
2015-06-01 13:52:07 -07:00
|
|
|
termpty_text_append(ty, c, len);
|
2015-04-19 10:59:29 -07:00
|
|
|
ty->termstate.had_cr = 0;
|
2012-07-13 01:46:33 -07:00
|
|
|
return len;
|
|
|
|
}
|