Implement output text binding

This commit is contained in:
Mildred Ki'Lya 2023-01-18 01:06:15 +01:00
parent b81b98d47c
commit e06cdb3d4d
4 changed files with 22 additions and 1 deletions

View file

@ -2254,6 +2254,7 @@ parse_section_text_bindings(struct context *ctx)
uint8_t *data = xmalloc(key_len + 1); uint8_t *data = xmalloc(key_len + 1);
size_t data_len = 0; size_t data_len = 0;
bool esc = false; bool esc = false;
int action = BIND_ACTION_TEXT_BINDING;
for (size_t i = 0; i < key_len; i++) { for (size_t i = 0; i < key_len; i++) {
if (key[i] == '\\') { if (key[i] == '\\') {
@ -2267,6 +2268,11 @@ parse_section_text_bindings(struct context *ctx)
} }
else if (esc) { else if (esc) {
if (i == 1 && key[i] == 'o') {
esc = false;
action = BIND_ACTION_OUTPUT_TEXT_BINDING;
continue;
}
if (key[i] != 'x') { if (key[i] != 'x') {
ctx->value = ""; ctx->value = "";
LOG_CONTEXTUAL_ERR("invalid escaped character: %c", key[i]); 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)) &conf->bindings.key, KEY_BINDING))
{ {
goto err; goto err;

View file

@ -986,6 +986,10 @@ specify a character:
- Bytes (e.g. ESC) are written as two-digit hexadecimal numbers, with - Bytes (e.g. ESC) are written as two-digit hexadecimal numbers, with
a *\\x* prefix: *\\x1b*. 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. Example: you would like to remap _Super+k_ to the _Up_ key.
The escape sequence for the Up key is _ESC [ A_ (without the 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* *\\x03 = Mod4+c*
Other example: you want to clear the terminal on _Ctrl+Shift+l_
*\o\x1bc = Control+Shift+l*
# SECTION: mouse-bindings # SECTION: mouse-bindings
This section lets you override the default mouse bindings. This section lets you override the default mouse bindings.

View file

@ -332,6 +332,12 @@ execute_binding(struct seat *seat, struct terminal *term,
return true; 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: case BIND_ACTION_TEXT_BINDING:
xassert(binding->aux->type == BINDING_AUX_TEXT); xassert(binding->aux->type == BINDING_AUX_TEXT);
term_to_slave(term, binding->aux->text.data, binding->aux->text.len); term_to_slave(term, binding->aux->text.data, binding->aux->text.len);

View file

@ -36,6 +36,7 @@ enum bind_action_normal {
BIND_ACTION_SHOW_URLS_LAUNCH, BIND_ACTION_SHOW_URLS_LAUNCH,
BIND_ACTION_SHOW_URLS_PERSISTENT, BIND_ACTION_SHOW_URLS_PERSISTENT,
BIND_ACTION_TEXT_BINDING, BIND_ACTION_TEXT_BINDING,
BIND_ACTION_OUTPUT_TEXT_BINDING,
BIND_ACTION_PROMPT_PREV, BIND_ACTION_PROMPT_PREV,
BIND_ACTION_PROMPT_NEXT, BIND_ACTION_PROMPT_NEXT,
BIND_ACTION_UNICODE_INPUT, BIND_ACTION_UNICODE_INPUT,