handle queries on some xterm escape codes

This commit is contained in:
Boris Faure 2014-08-17 17:44:19 +02:00
parent 61050bd7cc
commit 5dfb63a14a
1 changed files with 69 additions and 27 deletions

View File

@ -1096,6 +1096,9 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
if ((*cc == ST) || (*cc == BEL) || (*cc == '\\')) cc++; if ((*cc == ST) || (*cc == BEL) || (*cc == '\\')) cc++;
else return 0; else return 0;
#define TERMPTY_WRITE_STR(_S) \
termpty_write(ty, _S, strlen(_S))
arg = _xterm_arg_get(&b); arg = _xterm_arg_get(&b);
switch (arg) switch (arg)
{ {
@ -1105,56 +1108,92 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
// XXX: title + name - callback // XXX: title + name - callback
if (!*b) if (!*b)
goto err; goto err;
s = eina_unicode_unicode_to_utf8(b, &len); if (*b == '?')
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); TERMPTY_WRITE_STR("\033]0;");
ty->prop.icon = eina_stringshare_add(s); if (ty->prop.title)
free(s); {
TERMPTY_WRITE_STR(ty->prop.title);
}
TERMPTY_WRITE_STR("\007");
} }
else else
{ {
ty->prop.title = NULL; s = eina_unicode_unicode_to_utf8(b, &len);
ty->prop.icon = NULL; 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;
}
if (ty->cb.set_title.func) ty->cb.set_title.func(ty->cb.set_title.data);
if (ty->cb.set_icon.func) ty->cb.set_icon.func(ty->cb.set_icon.data);
} }
if (ty->cb.set_title.func) ty->cb.set_title.func(ty->cb.set_title.data);
if (ty->cb.set_icon.func) ty->cb.set_icon.func(ty->cb.set_icon.data);
break; break;
case 1: case 1:
// XXX: icon name - callback
if (!*b) if (!*b)
goto err; goto err;
// XXX: icon name - callback if (*b == '?')
s = eina_unicode_unicode_to_utf8(b, &len);
if (ty->prop.icon) eina_stringshare_del(ty->prop.icon);
if (s)
{ {
ty->prop.icon = eina_stringshare_add(s); TERMPTY_WRITE_STR("\033]0;");
free(s); if (ty->prop.icon)
{
TERMPTY_WRITE_STR(ty->prop.icon);
}
TERMPTY_WRITE_STR("\007");
} }
else else
{ {
ty->prop.icon = NULL; s = eina_unicode_unicode_to_utf8(b, &len);
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);
} }
if (ty->cb.set_icon.func) ty->cb.set_icon.func(ty->cb.set_icon.data);
break; break;
case 2: case 2:
// XXX: title - callback
if (!*b) if (!*b)
goto err; goto err;
// XXX: title - callback if (*b == '?')
s = eina_unicode_unicode_to_utf8(b, &len);
if (ty->prop.title) eina_stringshare_del(ty->prop.title);
if (s)
{ {
ty->prop.title = eina_stringshare_add(s); TERMPTY_WRITE_STR("\033]0;");
free(s); if (ty->prop.title)
{
TERMPTY_WRITE_STR(ty->prop.title);
}
TERMPTY_WRITE_STR("\007");
} }
else else
{ {
ty->prop.title = NULL; s = eina_unicode_unicode_to_utf8(b, &len);
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);
} }
if (ty->cb.set_title.func) ty->cb.set_title.func(ty->cb.set_title.data);
break; break;
case 4: case 4:
if (!*b) if (!*b)
@ -1168,6 +1207,9 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
ERR("unhandled xterm esc %d", arg); ERR("unhandled xterm esc %d", arg);
break; break;
} }
#undef TERMPTY_WRITE_STR
return cc - c; return cc - c;
err: err:
ERR("invalid xterm sequence"); ERR("invalid xterm sequence");