termptyesc: be able to set selection from escape codes

This commit is contained in:
Boris Faure 2023-08-20 16:02:45 +02:00
parent 112a5226a3
commit f1504e1c68
Signed by: borisfaure
GPG Key ID: EAA9CD729F522998
2 changed files with 99 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#if defined(BINARY_TYTEST)
#include "tytest.h"
#endif
#include "utils.h"
#undef CRITICAL
#undef ERR
@ -4310,6 +4311,68 @@ err:
ty->decoding_error = EINA_TRUE;
}
static Elm_Sel_Type
_elm_sel_type_from_osc52(Eina_Unicode c)
{
Elm_Sel_Type sel_type;
switch (c)
{
case 's':
sel_type = ELM_SEL_TYPE_SECONDARY;
break;
case 'c':
sel_type = ELM_SEL_TYPE_CLIPBOARD;
break;
case ';':
EINA_FALLTHROUGH;
case 'p':
EINA_FALLTHROUGH;
default:
sel_type = ELM_SEL_TYPE_PRIMARY;
break;
}
return sel_type;
}
static void
_handle_osc_selection(Termpty *ty, Eina_Unicode *p, int len)
{
Eina_Unicode *c;
Elm_Sel_Type sel_type;
if (!p || !*p || len <= 0)
goto err;
c = p;
while (*c != ';' && (c - p) < len)
c++;
if (*c != ';')
goto err;
c++;
if (*c == '?')
{
/* Report */
/* TODO */
goto err;
}
else
{
/* Set */
sel_type = _elm_sel_type_from_osc52(*p);
/* Decode base64 from the request */
p[len] = '\0';
char *out = ty_eina_unicode_base64_decode(c);
if (out)
{
termio_set_selection_text(ty->obj, sel_type, out);
free(out);
}
}
return;
err:
ty->decoding_error = EINA_TRUE;
}
static int
_handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
{
@ -4454,6 +4517,11 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
free(s);
}
break;
case 52:
DBG("Manipulate selection data");
if (ty->config->selection_escapes)
_handle_osc_selection(ty, p, cc - c - (p - buf));
break;
case 110:
DBG("Reset VT100 text foreground color");
break;

View File

@ -359,6 +359,37 @@ termio_bg_get(const Evas_Object *obj EINA_UNUSED)
return NULL;
}
static char *_sel_primary = NULL;
static char *_sel_secondary = NULL;
static char *_sel_clipboard = NULL;
void
termio_set_selection_text(Evas_Object *obj EINA_UNUSED,
Elm_Sel_Type type, const char *text)
{
switch (type)
{
case ELM_SEL_TYPE_PRIMARY:
free(_sel_primary);
if (text)
_sel_primary = strdup(text);
break;
case ELM_SEL_TYPE_SECONDARY:
free(_sel_secondary);
if (text)
_sel_secondary = strdup(text);
break;
case ELM_SEL_TYPE_CLIPBOARD:
free(_sel_clipboard);
if (text)
_sel_clipboard = strdup(text);
break;
default:
break;
}
}
#if defined(BINARY_TYTEST)
void
test_textgrid_palette_get(const Evas_Object *obj EINA_UNUSED,