Bind keys to custom escape sequences #325

Open
opened 12 months ago by dnkl · 3 comments
dnkl commented 12 months ago
Owner

Someone asked on #foot-terminal if foot has support for customizing the escape sequence key combinations emit:

09:32 trobjo  Hello, really nice terminal. Is it planned to add custom keybindings. Not to interact with foot but the shell. For example, in alacritty, I have set Ctrl-, to emit Ctrl-C (easier on Dvorak).
09:34 trobjo  I like having readline keybindings everywhere, but I do not like the default layout. So I have remapped almost all the keys to align more with my text editor (uses ErgoEmacs bindings).

I'm not sure whether this is something foot should allow or not?

If we decide to add it, I think it could be done fairly easy, by re-using the syntax from the pipe-* actions:

escape-sequence=[\E[\x01\x02~] Control+x

We'd have to decide on exact syntax for the escape sequence, but most of the infrastructure for parsing the configuration, storing the meta-data (the escape sequence) for the key bindings and so on already exists.

Someone asked on [#foot-terminal](https://freenode.logbot.info/foot-terminal/20210130#c6721839) if foot has support for customizing the escape sequence key combinations emit: ``` 09:32 trobjo Hello, really nice terminal. Is it planned to add custom keybindings. Not to interact with foot but the shell. For example, in alacritty, I have set Ctrl-, to emit Ctrl-C (easier on Dvorak). 09:34 trobjo I like having readline keybindings everywhere, but I do not like the default layout. So I have remapped almost all the keys to align more with my text editor (uses ErgoEmacs bindings). ``` I'm not sure whether this is something foot should allow or not? **If** we decide to add it, I think it could be done fairly easy, by re-using the syntax from the `pipe-*` actions: ``` escape-sequence=[\E[\x01\x02~] Control+x ``` We'd have to decide on exact syntax for the escape sequence, but most of the infrastructure for parsing the configuration, storing the meta-data (the escape sequence) for the key bindings and so on already exists.
dnkl added the
enhancement
label 12 months ago
dnkl added the
question
label 12 months ago
Collaborator

I can't really see the point in this, when there are so many other (arguably more appropriate) ways to do it. For example; a custom XKB keymap or just changing the bindings in the shell/app.

escape-sequence=[\E[\x01\x02~] Control+x

I know this was just meant as an example, but it kind of highlights how adding such a general-purpose feature like this could cause problems. Allowing people to set up keys to emit invalid CSI sequences would be ok for libraries like readline, where they just use string matching for bindings, but it wouldn't work very well in apps that do proper parsing. I suppose that would be a self-inflicted problem, but personally I think this is a misfeature and would be inviting all kinds of future bug reports for very little benefit.

I can't really see the point in this, when there are so many other (arguably more appropriate) ways to do it. For example; a custom XKB keymap or just changing the bindings in the shell/app. > ``` > escape-sequence=[\E[\x01\x02~] Control+x > ``` I know this was just meant as an example, but it kind of highlights how adding such a general-purpose feature like this could cause problems. Allowing people to set up keys to emit invalid CSI sequences would be ok for libraries like readline, where they just use string matching for bindings, but it wouldn't work very well in apps that do proper parsing. I suppose that would be a self-inflicted problem, but personally I think this is a misfeature and would be inviting all kinds of future bug reports for very little benefit.
Poster
Owner

For example; a custom XKB keymap

This was my initial thought too...

> For example; a custom XKB keymap This was my initial thought too...
dnkl added
what do you think?
and removed
question
labels 11 months ago

Think being able to remap escape sequence is essential for those who have uniq key mappings. I switched my ctrl and super from XKB to mimic the MacOs shortcut due to muscle memory (e.g. ctrl-v -> cmd-v) and its easier to reach. However in the terminal I want to switch back, what I did on other terminals (kitty/alacritty/st) is mapping ctrl+key sequence to super+key so I have exactly the same behavior as I am using macos terminals. attached is kitty config to achive what I just described. I think this is the only thing that prevent ppl like me from using this terminal emulator.

map ctrl+c       copy_to_clipboard
map ctrl+v        paste_from_clipboard
map super+question send_text all 7
map super+/ send_text all \037
map super+6 send_text all \036
map super+] send_text all \035
map super+backslash send_text all \034
map super+[ send_text all \033
map super+z send_text all \032
map super+y send_text all \031
map super+x send_text all \030
map super+w send_text all \027
map super+v send_text all \026
map super+u send_text all \025
map super+t send_text all \024
map super+s send_text all \023
map super+r send_text all \022
map super+q send_text all \021
map super+p send_text all \020
map super+o send_text all \017
map super+n send_text all \016
map super+m send_text all \015
map super+l send_text all \014
map super+k send_text all \013
map super+j send_text all \012
map super+i send_text all \011
map super+h send_text all \010
map super+g send_text all \007
map super+f send_text all \006
map super+e send_text all \005
map super+d send_text all \004
map super+c send_text all \003
map super+b send_text all \002
map super+a send_text all \001
map super+at send_text all \000
Think being able to remap escape sequence is essential for those who have uniq key mappings. I switched my `ctrl` and `super` from `XKB` to mimic the MacOs shortcut due to muscle memory (e.g. ctrl-v -> cmd-v) and its easier to reach. However in the terminal I want to switch back, what I did on other terminals (kitty/alacritty/st) is mapping `ctrl+key` sequence to `super+key` so I have exactly the same behavior as I am using macos terminals. attached is kitty config to achive what I just described. I think this is the only thing that prevent ppl like me from using this terminal emulator. ``` map ctrl+c copy_to_clipboard map ctrl+v paste_from_clipboard map super+question send_text all 7 map super+/ send_text all \037 map super+6 send_text all \036 map super+] send_text all \035 map super+backslash send_text all \034 map super+[ send_text all \033 map super+z send_text all \032 map super+y send_text all \031 map super+x send_text all \030 map super+w send_text all \027 map super+v send_text all \026 map super+u send_text all \025 map super+t send_text all \024 map super+s send_text all \023 map super+r send_text all \022 map super+q send_text all \021 map super+p send_text all \020 map super+o send_text all \017 map super+n send_text all \016 map super+m send_text all \015 map super+l send_text all \014 map super+k send_text all \013 map super+j send_text all \012 map super+i send_text all \011 map super+h send_text all \010 map super+g send_text all \007 map super+f send_text all \006 map super+e send_text all \005 map super+d send_text all \004 map super+c send_text all \003 map super+b send_text all \002 map super+a send_text all \001 map super+at send_text all \000 ```
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.