rewrite changing of background/foreground colors from escape codes
This commit is contained in:
parent
8fc11cd0e6
commit
196973fcd3
101
src/bin/termio.c
101
src/bin/termio.c
|
@ -76,7 +76,47 @@ termio_theme_set(Evas_Object *obj, Evas_Object *theme)
|
|||
{
|
||||
Termio *sd = evas_object_smart_data_get(obj);
|
||||
EINA_SAFETY_ON_NULL_RETURN(sd);
|
||||
if (theme) sd->theme = theme;
|
||||
EINA_SAFETY_ON_NULL_RETURN(sd->grid.obj);
|
||||
EINA_SAFETY_ON_NULL_RETURN(theme);
|
||||
|
||||
sd->theme = theme;
|
||||
|
||||
termio_color_class_get(obj, "BG",
|
||||
&sd->saved_bg.r,
|
||||
&sd->saved_bg.g,
|
||||
&sd->saved_bg.b,
|
||||
&sd->saved_bg.a);
|
||||
evas_object_textgrid_palette_get(
|
||||
sd->grid.obj,
|
||||
EVAS_TEXTGRID_PALETTE_STANDARD, 0,
|
||||
&sd->saved_fg.r,
|
||||
&sd->saved_fg.g,
|
||||
&sd->saved_fg.b,
|
||||
&sd->saved_fg.a);
|
||||
}
|
||||
|
||||
void
|
||||
termio_reset_main_colors(Evas_Object *termio)
|
||||
{
|
||||
if (termio)
|
||||
{
|
||||
Termio *sd = evas_object_smart_data_get(termio);
|
||||
EINA_SAFETY_ON_NULL_RETURN(sd);
|
||||
EINA_SAFETY_ON_NULL_RETURN(sd->grid.obj);
|
||||
|
||||
termio_color_class_set(termio, "BG",
|
||||
sd->saved_bg.r,
|
||||
sd->saved_bg.g,
|
||||
sd->saved_bg.b,
|
||||
sd->saved_bg.a);
|
||||
evas_object_textgrid_palette_set(
|
||||
sd->grid.obj,
|
||||
EVAS_TEXTGRID_PALETTE_STANDARD, 0,
|
||||
sd->saved_fg.r,
|
||||
sd->saved_fg.g,
|
||||
sd->saved_fg.b,
|
||||
sd->saved_fg.a);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -4144,3 +4184,62 @@ termio_key_down(Evas_Object *termio,
|
|||
edje_object_signal_emit(sd->cursor.obj, "key,down", "terminology");
|
||||
ev->event_flags = EVAS_EVENT_FLAG_ON_HOLD;
|
||||
}
|
||||
|
||||
int
|
||||
termio_color_class_get(Evas_Object *termio, const char *key,
|
||||
int *r, int *g, int *b, int *a)
|
||||
{
|
||||
Termio *sd = evas_object_smart_data_get(termio);
|
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(sd, -1);
|
||||
|
||||
if (sd->term)
|
||||
{
|
||||
Evas_Object *bg = term_bg_get(sd->term);
|
||||
if (!edje_object_color_class_get(bg, key,
|
||||
r,
|
||||
g,
|
||||
b,
|
||||
a,
|
||||
NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL))
|
||||
{
|
||||
ERR("color class '%s' not found in theme", key);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ERR("term not found");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
termio_color_class_set(Evas_Object *termio, const char *key,
|
||||
int r, int g, int b, int a)
|
||||
{
|
||||
Termio *sd = evas_object_smart_data_get(termio);
|
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(sd, -1);
|
||||
|
||||
if (sd->term)
|
||||
{
|
||||
Evas_Object *bg = term_bg_get(sd->term);
|
||||
if (!edje_object_color_class_set(bg, key,
|
||||
r, g, b, a,
|
||||
r, g, b, a,
|
||||
r, g, b, a))
|
||||
{
|
||||
ERR("can not set color class '%s'", key);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ERR("term not found");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -82,4 +82,12 @@ void
|
|||
termio_block_activate(Evas_Object *obj, Termblock *blk);
|
||||
const char *
|
||||
term_preedit_str_get(Term *term);
|
||||
int
|
||||
termio_color_class_get(Evas_Object *termio, const char *key,
|
||||
int *r, int *g, int *b, int *a);
|
||||
int
|
||||
termio_color_class_set(Evas_Object *termio, const char *key,
|
||||
int r, int g, int b, int a);
|
||||
void
|
||||
termio_reset_main_colors(Evas_Object *termio);
|
||||
#endif
|
||||
|
|
|
@ -59,6 +59,12 @@ struct _Termio
|
|||
unsigned long long total, size;
|
||||
Eina_Bool active : 1;
|
||||
} sendfile;
|
||||
struct {
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
int a;
|
||||
} saved_bg, saved_fg;
|
||||
Evas_Object *ctxpopup;
|
||||
int zoom_fontsize_start;
|
||||
int scroll;
|
||||
|
|
|
@ -1778,34 +1778,3 @@ term_link_free(Termpty *ty, Term_Link *link)
|
|||
/* Remove from bitmap */
|
||||
hl_bitmap_clear_bit(ty, id);
|
||||
}
|
||||
#if !defined(BINARY_TYFUZZ) && !defined(BINARY_TYTEST)
|
||||
int
|
||||
termpty_color_class_get(Termpty *ty, const char *key,
|
||||
int *r, int *g, int *b, int *a)
|
||||
{
|
||||
Term *term;
|
||||
|
||||
term = termio_term_get(ty->obj);
|
||||
if (term)
|
||||
{
|
||||
Evas_Object *bg = term_bg_get(term);
|
||||
if (!edje_object_color_class_get(bg, key,
|
||||
r,
|
||||
g,
|
||||
b,
|
||||
a,
|
||||
NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL))
|
||||
{
|
||||
ERR("color class BG not found in theme");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ERR("term not found");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -3880,20 +3880,61 @@ _handle_xterm_777_command(Termpty *ty,
|
|||
}
|
||||
|
||||
static void
|
||||
_handle_xterm_11_command(Termpty *ty, Eina_Unicode *p)
|
||||
_handle_xterm_10_command(Termpty *ty, Eina_Unicode *p, int len)
|
||||
{
|
||||
if (!p || !*p)
|
||||
goto err;
|
||||
if (*p == '?')
|
||||
{
|
||||
int r, g, b;
|
||||
char bf[7];
|
||||
#if !defined(BINARY_TYFUZZ) && !defined(BINARY_TYTEST)
|
||||
evas_object_textgrid_palette_get(
|
||||
termio_textgrid_get(ty->obj),
|
||||
EVAS_TEXTGRID_PALETTE_STANDARD, 0,
|
||||
&r, &g, &b, NULL);
|
||||
#else
|
||||
Config *config = termio_config_get(ty->obj);
|
||||
r = config->colors[0].r;
|
||||
g = config->colors[0].g;
|
||||
b = config->colors[0].b;
|
||||
#endif
|
||||
TERMPTY_WRITE_STR("\033]10;#");
|
||||
snprintf(bf, sizeof(bf), "%.2X%.2X%.2X", r, g, b);
|
||||
termpty_write(ty, bf, 6);
|
||||
TERMPTY_WRITE_STR("\007");
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char r, g, b;
|
||||
if (_xterm_parse_color(ty, &p, &r, &g, &b, len) < 0)
|
||||
goto err;
|
||||
#if !defined(BINARY_TYFUZZ) && !defined(BINARY_TYTEST)
|
||||
evas_object_textgrid_palette_set(
|
||||
termio_textgrid_get(ty->obj),
|
||||
EVAS_TEXTGRID_PALETTE_STANDARD, 0,
|
||||
r, g, b, 0xff);
|
||||
#endif
|
||||
}
|
||||
return;
|
||||
err:
|
||||
ty->decoding_error = EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_handle_xterm_11_command(Termpty *ty, Eina_Unicode *p, int len)
|
||||
{
|
||||
|
||||
if (!*p || !*p)
|
||||
goto err;
|
||||
|
||||
if (*p == '?')
|
||||
{
|
||||
int r = 0, g = 0, b = 0;
|
||||
char buf[32];
|
||||
size_t l;
|
||||
|
||||
if (!*p)
|
||||
goto err;
|
||||
|
||||
/* only support query mode for the moment */
|
||||
if (*p != '?')
|
||||
goto err;
|
||||
|
||||
if (termpty_color_class_get(ty, "BG", &r, &g, &b, NULL) != 0)
|
||||
if (termio_color_class_get(ty->obj, "BG", &r, &g, &b, NULL) != 0)
|
||||
{
|
||||
ERR("error getting color class 'BG'");
|
||||
}
|
||||
|
@ -3902,6 +3943,14 @@ _handle_xterm_11_command(Termpty *ty, Eina_Unicode *p)
|
|||
r, r, g, g, b, b);
|
||||
termpty_write(ty, buf, l);
|
||||
TERMPTY_WRITE_STR("\033\\");
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char r, g, b;
|
||||
if (_xterm_parse_color(ty, &p, &r, &g, &b, len) < 0)
|
||||
goto err;
|
||||
termio_color_class_set(ty->obj, "BG", r, g, b, 0xff);
|
||||
}
|
||||
|
||||
return;
|
||||
err:
|
||||
|
@ -4026,38 +4075,12 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
|||
_handle_hyperlink(ty, s, len);
|
||||
break;
|
||||
case 10:
|
||||
if (!p || !*p)
|
||||
goto err;
|
||||
if (*p == '?')
|
||||
{
|
||||
char bf[7];
|
||||
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(ty, &p, &r, &g, &b, len) < 0)
|
||||
goto err;
|
||||
#if !defined(BINARY_TYFUZZ) && !defined(BINARY_TYTEST)
|
||||
evas_object_textgrid_palette_set(
|
||||
termio_textgrid_get(ty->obj),
|
||||
EVAS_TEXTGRID_PALETTE_STANDARD, 0,
|
||||
r, g, b, 0xff);
|
||||
#endif
|
||||
}
|
||||
_handle_xterm_10_command(ty, p, cc - c - (p - buf));
|
||||
break;
|
||||
case 11:
|
||||
if (!p || !*p)
|
||||
goto err;
|
||||
_handle_xterm_11_command(ty, p);
|
||||
_handle_xterm_11_command(ty, p, cc - c - (p - buf));
|
||||
break;
|
||||
case 50:
|
||||
DBG("xterm font support");
|
||||
|
|
|
@ -455,6 +455,7 @@ termpty_soft_reset_state(Termpty *ty)
|
|||
ty->mouse_ext = MOUSE_EXT_NONE;
|
||||
ty->bracketed_paste = 0;
|
||||
|
||||
termio_reset_main_colors(ty->obj);
|
||||
termpty_clear_tabs_on_screen(ty);
|
||||
for (i = 0; i < ty->w; i += TAB_WIDTH)
|
||||
{
|
||||
|
|
|
@ -43,6 +43,10 @@ static Termio _sd = {
|
|||
.pty = &_ty,
|
||||
.config = NULL,
|
||||
};
|
||||
static int _bg_r = 131;
|
||||
static int _bg_g = 132;
|
||||
static int _bg_b = 133;
|
||||
static int _bg_a = 134;
|
||||
static const char *_cursor_shape = "undefined";
|
||||
#if defined(BINARY_TYTEST)
|
||||
static Evas_Textgrid_Cell *_cells;
|
||||
|
@ -270,23 +274,46 @@ termio_set_cursor_shape(Evas_Object *obj EINA_UNUSED,
|
|||
|
||||
|
||||
int
|
||||
termpty_color_class_get(Termpty *ty EINA_UNUSED, const char *key,
|
||||
termio_color_class_get(Evas_Object *termio EINA_UNUSED, const char *key,
|
||||
int *r, int *g, int *b, int *a)
|
||||
{
|
||||
if (strncmp(key, "BG", strlen("BG")) == 0)
|
||||
{
|
||||
if (r)
|
||||
*r = 131;
|
||||
*r = _bg_r;
|
||||
if (g)
|
||||
*g = 132;
|
||||
*g = _bg_g;
|
||||
if (b)
|
||||
*b = 133;
|
||||
*b = _bg_b;
|
||||
if (a)
|
||||
*a = 134;
|
||||
*a = _bg_a;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
int
|
||||
termio_color_class_set(Evas_Object *termio EINA_UNUSED, const char *key,
|
||||
int r, int g, int b, int a)
|
||||
{
|
||||
if (strncmp(key, "BG", strlen("BG")) == 0)
|
||||
{
|
||||
_bg_r = r;
|
||||
_bg_g = g;
|
||||
_bg_b = b;
|
||||
_bg_a = a;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
termio_reset_main_colors(Evas_Object *termio EINA_UNUSED)
|
||||
{
|
||||
_bg_r = 131;
|
||||
_bg_g = 132;
|
||||
_bg_b = 133;
|
||||
_bg_a = 134;
|
||||
}
|
||||
|
||||
Evas_Object *
|
||||
termio_textgrid_get(const Evas_Object *obj EINA_UNUSED)
|
||||
|
|
Loading…
Reference in New Issue