From e06cdb3d4de14eb508d1f48422b8c8030b9629b2 Mon Sep 17 00:00:00 2001 From: Mildred Ki'Lya Date: Wed, 18 Jan 2023 01:06:15 +0100 Subject: [PATCH] Implement output text binding --- config.c | 8 +++++++- doc/foot.ini.5.scd | 8 ++++++++ input.c | 6 ++++++ key-binding.h | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index d77b50b8..89c21863 100644 --- a/config.c +++ b/config.c @@ -2254,6 +2254,7 @@ parse_section_text_bindings(struct context *ctx) uint8_t *data = xmalloc(key_len + 1); size_t data_len = 0; bool esc = false; + int action = BIND_ACTION_TEXT_BINDING; for (size_t i = 0; i < key_len; i++) { if (key[i] == '\\') { @@ -2267,6 +2268,11 @@ parse_section_text_bindings(struct context *ctx) } else if (esc) { + if (i == 1 && key[i] == 'o') { + esc = false; + action = BIND_ACTION_OUTPUT_TEXT_BINDING; + continue; + } if (key[i] != 'x') { ctx->value = ""; LOG_CONTEXTUAL_ERR("invalid escaped character: %c", key[i]); @@ -2305,7 +2311,7 @@ parse_section_text_bindings(struct context *ctx) }, }; - if (!value_to_key_combos(ctx, BIND_ACTION_TEXT_BINDING, &aux, + if (!value_to_key_combos(ctx, action, &aux, &conf->bindings.key, KEY_BINDING)) { goto err; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 07a3cb94..4f487481 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -986,6 +986,10 @@ specify a character: - Bytes (e.g. ESC) are written as two-digit hexadecimal numbers, with a *\\x* prefix: *\\x1b*. +If the text starts with the special escape sequence *\\o* then the text is not +sent to the slave process input, but is processed by the terminal as if it was +sent by the slave process. + Example: you would like to remap _Super+k_ to the _Up_ key. The escape sequence for the Up key is _ESC [ A_ (without the @@ -998,6 +1002,10 @@ Another example: to remap _Super+c_ to _Control+c_: *\\x03 = Mod4+c* +Other example: you want to clear the terminal on _Ctrl+Shift+l_ + +*\o\x1bc = Control+Shift+l* + # SECTION: mouse-bindings This section lets you override the default mouse bindings. diff --git a/input.c b/input.c index 0a3773bc..74a57b49 100644 --- a/input.c +++ b/input.c @@ -332,6 +332,12 @@ execute_binding(struct seat *seat, struct terminal *term, return true; } + case BIND_ACTION_OUTPUT_TEXT_BINDING: + xassert(binding->aux->type == BINDING_AUX_TEXT); + vt_from_slave(term, binding->aux->text.data, binding->aux->text.len); + render_refresh(term); + return true; + case BIND_ACTION_TEXT_BINDING: xassert(binding->aux->type == BINDING_AUX_TEXT); term_to_slave(term, binding->aux->text.data, binding->aux->text.len); diff --git a/key-binding.h b/key-binding.h index f607644f..92c986cf 100644 --- a/key-binding.h +++ b/key-binding.h @@ -36,6 +36,7 @@ enum bind_action_normal { BIND_ACTION_SHOW_URLS_LAUNCH, BIND_ACTION_SHOW_URLS_PERSISTENT, BIND_ACTION_TEXT_BINDING, + BIND_ACTION_OUTPUT_TEXT_BINDING, BIND_ACTION_PROMPT_PREV, BIND_ACTION_PROMPT_NEXT, BIND_ACTION_UNICODE_INPUT,