From 1c9c2a19ed95b4d046938fd4669e118dc21e4bec Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Wed, 27 Feb 2019 23:46:04 +0100 Subject: [PATCH] termptyesc: handle window manipulations that resizes the terminal only for testing purpose --- src/bin/termptyesc.c | 74 +++++++++++++++++++++++++++++++++++++++----- src/bin/termptyext.c | 12 ++----- 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c index f6d43d1d..c60a1e01 100644 --- a/src/bin/termptyesc.c +++ b/src/bin/termptyesc.c @@ -3011,10 +3011,75 @@ _handle_esc_csi_decswbv(Termpty *ty, Eina_Unicode **ptr) } } +static void +_handle_resize_by_chars(Termpty *ty, Eina_Unicode **ptr) +{ + Eina_Unicode *b = *ptr; + int w, h; + + w = _csi_arg_get(ty, &b); + h = _csi_arg_get(ty, &b); + + if ((w == -CSI_ARG_ERROR) || (h == -CSI_ARG_ERROR)) + return; + if (w == -CSI_ARG_NO_VALUE) + { + w = ty->w; + } + if (h == -CSI_ARG_NO_VALUE) + { + h = ty->h; + } + if ((w == ty->w) && (h == ty->h)) + { + return; + } + DBG("Window manipulation: resize to %dx%d", w, h); + + /* ONLY FOR TESTING PURPOSE FTM */ +#if defined(ENABLE_TESTS) || defined(ENABLE_TEST_UI) + { +#if defined(ENABLE_TEST_UI) + Evas_Object *wn; + int step_w = 0, step_h = 0, base_w = 0, base_h = 0; + + wn = termio_win_get(ty->obj); + elm_win_size_base_get(wn, &base_w, &base_h); + elm_win_size_step_get(wn, &step_w, &step_h); + evas_object_resize(wn, + base_w + step_w * w, + base_h + step_h * h); +#endif + termpty_resize(ty, w, h); + } +#endif +} + +static void +_handle_window_manipulation(Termpty *ty, Eina_Unicode **ptr) +{ + Eina_Unicode *b = *ptr; + int arg = _csi_arg_get(ty, &b); + + if (arg == -CSI_ARG_ERROR) + return; + DBG("Window manipulation: %d", arg); + switch (arg) + { + case 8: + _handle_resize_by_chars(ty, &b); + break; + default: + // many others + WRN("unhandled window manipulation %d", arg); + ty->decoding_error = EINA_TRUE; + break; + } +} + static int _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) { - int arg; const Eina_Unicode *cc, *be; Eina_Unicode buf[4096], *b; @@ -3218,11 +3283,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) } else { - arg = _csi_arg_get(ty, &b); - if (arg == -CSI_ARG_ERROR) - goto error; - WRN("TODO: window operation %d not supported", arg); - ty->decoding_error = EINA_TRUE; + _handle_window_manipulation(ty, &b); } break; case 'u': // restore cursor pos @@ -3282,7 +3343,6 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) cc++; return cc - c; unhandled: -error: #if !defined(ENABLE_FUZZING) && !defined(ENABLE_TESTS) if (eina_log_domain_level_check(_termpty_log_dom, EINA_LOG_LEVEL_WARN)) { diff --git a/src/bin/termptyext.c b/src/bin/termptyext.c index 945bf057..96b3f5e4 100644 --- a/src/bin/termptyext.c +++ b/src/bin/termptyext.c @@ -19,14 +19,6 @@ #define INF(...) EINA_LOG_DOM_INFO(_termpty_log_dom, __VA_ARGS__) #define DBG(...) EINA_LOG_DOM_DBG(_termpty_log_dom, __VA_ARGS__) -#if defined(ENABLE_TESTS) - #define WITH_TESTS 1 -#else - #define WITH_TESTS 0 -#endif -// Uncomment following to enable testing escape codes within terminology -//#define WITH_TESTS 1 - //// extended terminology escape handling goes in here // // this is where escapes get handled *IF* the termpty layer needs to interpret @@ -59,7 +51,7 @@ _handle_op_a(Termpty *_ty EINA_UNUSED, return EINA_FALSE; } -#if WITH_TESTS +#if defined(ENABLE_TESTS) || defined(ENABLE_TEST_UI) static int _tytest_arg_get(const Eina_Unicode *buf, int *value) @@ -377,7 +369,7 @@ termpty_ext_handle(Termpty *ty, return _handle_op_a(ty, buf + 1, blen - 1); break; // room here for more major opcode chars like 'b', 'c' etc. -#if WITH_TESTS +#if defined(ENABLE_TESTS) || defined(ENABLE_TEST_UI) case 't': tytest_handle_escape_codes(ty, buf + 1); return EINA_TRUE;