From ac7038d9d40dcf2e3b958f50b816555259a99226 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Mon, 20 Dec 2021 12:15:11 +0100 Subject: [PATCH] [terminal] Cache ui.double_esc --- src/config/options.c | 11 +++++++++++ src/terminal/kbd.c | 12 ++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/config/options.c b/src/config/options.c index c789b635..a43fbe0c 100644 --- a/src/config/options.c +++ b/src/config/options.c @@ -34,6 +34,7 @@ #include "util/string.h" #include "viewer/text/draw.h" +extern int ui_double_esc; /* TODO? In the past, covered by shadow and legends, remembered only by the * ELinks Elders now, options were in hashes (it was not for a long time, after @@ -864,6 +865,13 @@ change_hook_ui(struct session *ses, struct option *current, struct option *chang return 0; } +static int +change_hook_ui_double_esc(struct session *ses, struct option *current, struct option *changed) +{ + ui_double_esc = changed->value.number; + return 0; +} + /** Make option templates visible or invisible in the option manager. * This is called once on startup, and then each time the value of the * "config.show_template" option is changed. @@ -936,6 +944,7 @@ static const struct change_hook_info change_hooks[] = { { "document.html", change_hook_html }, { "document.plain", change_hook_html }, { "terminal", change_hook_terminal }, + { "ui.double_esc", change_hook_ui_double_esc }, { "ui.language", change_hook_language }, { "ui", change_hook_ui }, { NULL, NULL }, @@ -956,6 +965,8 @@ init_options(void) register_autocreated_options(); register_change_hooks(change_hooks); + + ui_double_esc = get_opt_bool("ui.double_esc", NULL); } /*! @relates option */ diff --git a/src/terminal/kbd.c b/src/terminal/kbd.c index 83cd579c..8a5d8f5d 100644 --- a/src/terminal/kbd.c +++ b/src/terminal/kbd.c @@ -771,6 +771,14 @@ get_esc_code(unsigned char *str, int len, char *final_byte, #include /* isprint() isspace() */ #endif +int ui_double_esc; + +static inline int +get_ui_double_esc(void) +{ + return ui_double_esc; +} + /** Decode a control sequence that begins with CSI (CONTROL SEQUENCE * INTRODUCER) encoded as ESC [, and set @a *ev accordingly. * (ECMA-48 also allows 0x9B as a single-byte CSI, but we don't @@ -789,7 +797,7 @@ decode_terminal_escape_sequence(struct itrm *itrm, struct interlink_event *ev) int v; int el; - if (itrm->in.queue.len == 2 && itrm->in.queue.data[1] == ASCII_ESC && get_opt_bool("ui.double_esc", NULL)) { + if (itrm->in.queue.len == 2 && itrm->in.queue.data[1] == ASCII_ESC && get_ui_double_esc()) { kbd.key = KBD_ESC; set_kbd_interlink_event(ev, kbd.key, kbd.modifier); return 2; @@ -1141,7 +1149,7 @@ process_queue(struct itrm *itrm) * beginning of e.g. ESC ESC 0x5B 0x41, * which we should parse as Esc Up. */ if (itrm->in.queue.len < 3) { - if (get_opt_bool("ui.double_esc", NULL)) { + if (get_ui_double_esc()) { el = decode_terminal_escape_sequence(itrm, &ev); } else { /* Need more data to figure it out. */