Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: key bindings for urxvt, add home/end combinations #396

Merged
merged 6 commits into from
Oct 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 137 additions & 66 deletions key.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,20 @@ const (
KeyCtrlDown
KeyCtrlRight
KeyCtrlLeft
KeyCtrlHome
KeyCtrlEnd
KeyShiftUp
KeyShiftDown
KeyShiftRight
KeyShiftLeft
KeyShiftHome
KeyShiftEnd
KeyCtrlShiftUp
KeyCtrlShiftDown
KeyCtrlShiftLeft
KeyCtrlShiftRight
KeyCtrlShiftHome
KeyCtrlShiftEnd
KeyF1
KeyF2
KeyF3
Expand Down Expand Up @@ -282,6 +288,12 @@ var keyNames = map[KeyType]string{
KeyShiftTab: "shift+tab",
KeyHome: "home",
KeyEnd: "end",
KeyCtrlHome: "ctrl+home",
KeyCtrlEnd: "ctrl+end",
KeyShiftHome: "shift+home",
KeyShiftEnd: "shift+end",
KeyCtrlShiftHome: "ctrl+shift+home",
KeyCtrlShiftEnd: "ctrl+shift+end",
KeyPgUp: "pgup",
KeyPgDown: "pgdown",
KeyDelete: "delete",
Expand Down Expand Up @@ -377,27 +389,57 @@ var sequences = map[string]Key{
"\x1b[1;8D": {Type: KeyCtrlShiftLeft, Alt: true},

// Miscellaneous keys
"\x1b[Z": {Type: KeyShiftTab},
"\x1b[2~": {Type: KeyInsert},
"\x1b[2;3~": {Type: KeyInsert, Alt: true},
"\x1b[Z": {Type: KeyShiftTab},

"\x1b[3~": {Type: KeyDelete},
"\x1b[3;3~": {Type: KeyDelete, Alt: true},
"\x1b[1~": {Type: KeyHome},
Copy link
Contributor

@muesli muesli Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're right and most every terminal seems to send \x1b[H for the home key, I do find references to this sequence being used for home as well. We should probably keep it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question/remark for KeyEnd, too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw, I added this after testing against home and receiving that value (same case for end). As long as there’s no collision, I’d also err on keeping it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On which terminal was that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be quite honest I don't remember anymore, though do I think it's worth investigating.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update this commit and keep the previous sequences for KeyHome and KeyEnd for now. If we can confirm they aren't used anywhere we can still remove them eventually.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, pushed my changes to your fork.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this works for me. thanks for the edit!

"\x1b[1;3H~": {Type: KeyHome, Alt: true},
"\x1b[4~": {Type: KeyEnd},
"\x1b[1;3F~": {Type: KeyEnd, Alt: true},
"\x1b\x1b[3~": {Type: KeyDelete, Alt: true}, // urxvt

"\x1b[5~": {Type: KeyPgUp},
"\x1b[5;3~": {Type: KeyPgUp, Alt: true},
"\x1b\x1b[5~": {Type: KeyPgUp, Alt: true}, // urxvt

"\x1b[6~": {Type: KeyPgDown},
"\x1b[6;3~": {Type: KeyPgDown, Alt: true},
"\x1b[7~": {Type: KeyHome}, // urxvt
"\x1b[8~": {Type: KeyEnd}, // urxvt
"\x1b\x1b[2~": {Type: KeyInsert, Alt: true}, // urxvt
"\x1b\x1b[3~": {Type: KeyDelete, Alt: true}, // urxvt
"\x1b\x1b[5~": {Type: KeyPgUp, Alt: true}, // urxvt
"\x1b\x1b[6~": {Type: KeyPgDown, Alt: true}, // urxvt
"\x1b\x1b[7~": {Type: KeyHome, Alt: true}, // urxvt
"\x1b\x1b[8~": {Type: KeyEnd, Alt: true}, // urxvt

"\x1b[1~": {Type: KeyHome},
"\x1b[H": {Type: KeyHome}, // xterm, lxterm
"\x1b[1;3H": {Type: KeyHome, Alt: true}, // xterm, lxterm
"\x1b[1;5H": {Type: KeyCtrlHome}, // xterm, lxterm
"\x1b[1;7H": {Type: KeyCtrlHome, Alt: true}, // xterm, lxterm
"\x1b[1;2H": {Type: KeyShiftHome}, // xterm, lxterm
"\x1b[1;4H": {Type: KeyShiftHome, Alt: true}, // xterm, lxterm
"\x1b[1;6H": {Type: KeyCtrlShiftHome}, // xterm, lxterm
"\x1b[1;8H": {Type: KeyCtrlShiftHome, Alt: true}, // xterm, lxterm

"\x1b[4~": {Type: KeyEnd},
"\x1b[F": {Type: KeyEnd}, // xterm, lxterm
"\x1b[1;3F": {Type: KeyEnd, Alt: true}, // xterm, lxterm
"\x1b[1;5F": {Type: KeyCtrlEnd}, // xterm, lxterm
"\x1b[1;7F": {Type: KeyCtrlEnd, Alt: true}, // xterm, lxterm
"\x1b[1;2F": {Type: KeyShiftEnd}, // xterm, lxterm
"\x1b[1;4F": {Type: KeyShiftEnd, Alt: true}, // xterm, lxterm
"\x1b[1;6F": {Type: KeyCtrlShiftEnd}, // xterm, lxterm
"\x1b[1;8F": {Type: KeyCtrlShiftEnd, Alt: true}, // xterm, lxterm

"\x1b[7~": {Type: KeyHome}, // urxvt
"\x1b\x1b[7~": {Type: KeyHome, Alt: true}, // urxvt
"\x1b[7^": {Type: KeyCtrlHome}, // urxvt
"\x1b\x1b[7^": {Type: KeyCtrlHome, Alt: true}, // urxvt
"\x1b[7$": {Type: KeyShiftHome}, // urxvt
"\x1b\x1b[7$": {Type: KeyShiftHome, Alt: true}, // urxvt
"\x1b[7@": {Type: KeyCtrlShiftHome}, // urxvt
"\x1b\x1b[7@": {Type: KeyCtrlShiftHome, Alt: true}, // urxvt

"\x1b[8~": {Type: KeyEnd}, // urxvt
"\x1b\x1b[8~": {Type: KeyEnd, Alt: true}, // urxvt
"\x1b[8^": {Type: KeyCtrlEnd}, // urxvt
"\x1b\x1b[8^": {Type: KeyCtrlEnd, Alt: true}, // urxvt
"\x1b[8$": {Type: KeyShiftEnd}, // urxvt
"\x1b\x1b[8$": {Type: KeyShiftEnd, Alt: true}, // urxvt
"\x1b[8@": {Type: KeyCtrlShiftEnd}, // urxvt
"\x1b\x1b[8@": {Type: KeyCtrlShiftEnd, Alt: true}, // urxvt

// Function keys, Linux console
"\x1b[[A": {Type: KeyF1}, // linux console
Expand All @@ -407,68 +449,97 @@ var sequences = map[string]Key{
"\x1b[[E": {Type: KeyF5}, // linux console

// Function keys, X11
"\x1bOP": {Type: KeyF1}, // vt100
"\x1bOQ": {Type: KeyF2}, // vt100
"\x1bOR": {Type: KeyF3}, // vt100
"\x1bOS": {Type: KeyF4}, // vt100
"\x1b[15~": {Type: KeyF5}, // also urxvt
"\x1b[17~": {Type: KeyF6}, // also urxvt
"\x1b[18~": {Type: KeyF7}, // also urxvt
"\x1b[19~": {Type: KeyF8}, // also urxvt
"\x1b[20~": {Type: KeyF9}, // also urxvt
"\x1b[21~": {Type: KeyF10}, // also urxvt
"\x1b[23~": {Type: KeyF11}, // also urxvt
"\x1b[24~": {Type: KeyF12}, // also urxvt
"\x1b[1;2P": {Type: KeyF13},
"\x1b[1;2Q": {Type: KeyF14},
"\x1b[1;2R": {Type: KeyF15},
"\x1b[1;2S": {Type: KeyF16},
"\x1bOP": {Type: KeyF1}, // vt100, xterm
"\x1bOQ": {Type: KeyF2}, // vt100, xterm
"\x1bOR": {Type: KeyF3}, // vt100, xterm
"\x1bOS": {Type: KeyF4}, // vt100, xterm

"\x1b[1;3P": {Type: KeyF1, Alt: true}, // vt100, xterm
"\x1b[1;3Q": {Type: KeyF2, Alt: true}, // vt100, xterm
"\x1b[1;3R": {Type: KeyF3, Alt: true}, // vt100, xterm
"\x1b[1;3S": {Type: KeyF4, Alt: true}, // vt100, xterm

"\x1b[11~": {Type: KeyF1}, // urxvt
"\x1b[12~": {Type: KeyF2}, // urxvt
"\x1b[13~": {Type: KeyF3}, // urxvt
"\x1b[14~": {Type: KeyF4}, // urxvt

"\x1b\x1b[11~": {Type: KeyF1, Alt: true}, // urxvt
"\x1b\x1b[12~": {Type: KeyF2, Alt: true}, // urxvt
"\x1b\x1b[13~": {Type: KeyF3, Alt: true}, // urxvt
"\x1b\x1b[14~": {Type: KeyF4, Alt: true}, // urxvt

"\x1b[15~": {Type: KeyF5}, // vt100, xterm, also urxvt

"\x1b[15;3~": {Type: KeyF5, Alt: true}, // vt100, xterm, also urxvt

"\x1b\x1b[15~": {Type: KeyF5, Alt: true}, // urxvt

"\x1b[17~": {Type: KeyF6}, // vt100, xterm, also urxvt
"\x1b[18~": {Type: KeyF7}, // vt100, xterm, also urxvt
"\x1b[19~": {Type: KeyF8}, // vt100, xterm, also urxvt
"\x1b[20~": {Type: KeyF9}, // vt100, xterm, also urxvt
"\x1b[21~": {Type: KeyF10}, // vt100, xterm, also urxvt

"\x1b\x1b[17~": {Type: KeyF6, Alt: true}, // urxvt
"\x1b\x1b[18~": {Type: KeyF7, Alt: true}, // urxvt
"\x1b\x1b[19~": {Type: KeyF8, Alt: true}, // urxvt
"\x1b\x1b[20~": {Type: KeyF9, Alt: true}, // urxvt
"\x1b\x1b[21~": {Type: KeyF10, Alt: true}, // urxvt

"\x1b[17;3~": {Type: KeyF6, Alt: true}, // vt100, xterm
"\x1b[18;3~": {Type: KeyF7, Alt: true}, // vt100, xterm
"\x1b[19;3~": {Type: KeyF8, Alt: true}, // vt100, xterm
"\x1b[20;3~": {Type: KeyF9, Alt: true}, // vt100, xterm
"\x1b[21;3~": {Type: KeyF10, Alt: true}, // vt100, xterm

"\x1b[23~": {Type: KeyF11}, // vt100, xterm, also urxvt
"\x1b[24~": {Type: KeyF12}, // vt100, xterm, also urxvt

"\x1b[23;3~": {Type: KeyF11, Alt: true}, // vt100, xterm
"\x1b[24;3~": {Type: KeyF12, Alt: true}, // vt100, xterm

"\x1b\x1b[23~": {Type: KeyF11, Alt: true}, // urxvt
"\x1b\x1b[24~": {Type: KeyF12, Alt: true}, // urxvt

"\x1b[1;2P": {Type: KeyF13},
"\x1b[1;2Q": {Type: KeyF14},

"\x1b[25~": {Type: KeyF13}, // vt100, xterm, also urxvt
"\x1b[26~": {Type: KeyF14}, // vt100, xterm, also urxvt

"\x1b[25;3~": {Type: KeyF13, Alt: true}, // vt100, xterm
"\x1b[26;3~": {Type: KeyF14, Alt: true}, // vt100, xterm

"\x1b\x1b[25~": {Type: KeyF13, Alt: true}, // urxvt
"\x1b\x1b[26~": {Type: KeyF14, Alt: true}, // urxvt

"\x1b[1;2R": {Type: KeyF15},
"\x1b[1;2S": {Type: KeyF16},

"\x1b[28~": {Type: KeyF15}, // vt100, xterm, also urxvt
"\x1b[29~": {Type: KeyF16}, // vt100, xterm, also urxvt

"\x1b[28;3~": {Type: KeyF15, Alt: true}, // vt100, xterm
"\x1b[29;3~": {Type: KeyF16, Alt: true}, // vt100, xterm

"\x1b\x1b[28~": {Type: KeyF15, Alt: true}, // urxvt
"\x1b\x1b[29~": {Type: KeyF16, Alt: true}, // urxvt

"\x1b[15;2~": {Type: KeyF17},
"\x1b[17;2~": {Type: KeyF18},
"\x1b[18;2~": {Type: KeyF19},
"\x1b[19;2~": {Type: KeyF20},

// Function keys with the alt modifier, X11
"\x1b[1;3P": {Type: KeyF1, Alt: true},
"\x1b[1;3Q": {Type: KeyF2, Alt: true},
"\x1b[1;3R": {Type: KeyF3, Alt: true},
"\x1b[1;3S": {Type: KeyF4, Alt: true},
"\x1b[15;3~": {Type: KeyF5, Alt: true},
"\x1b[17;3~": {Type: KeyF6, Alt: true},
"\x1b[18;3~": {Type: KeyF7, Alt: true},
"\x1b[19;3~": {Type: KeyF8, Alt: true},
"\x1b[20;3~": {Type: KeyF9, Alt: true},
"\x1b[21;3~": {Type: KeyF10, Alt: true},
"\x1b[23;3~": {Type: KeyF11, Alt: true},
"\x1b[24;3~": {Type: KeyF12, Alt: true},

// Function keys, urxvt
"\x1b[11~": {Type: KeyF1},
"\x1b[12~": {Type: KeyF2},
"\x1b[13~": {Type: KeyF3},
"\x1b[14~": {Type: KeyF4},
"\x1b[25~": {Type: KeyF13},
"\x1b[26~": {Type: KeyF14},
"\x1b[28~": {Type: KeyF15},
"\x1b[29~": {Type: KeyF16},
"\x1b[31~": {Type: KeyF17},
"\x1b[32~": {Type: KeyF18},
"\x1b[33~": {Type: KeyF19},
"\x1b[34~": {Type: KeyF20},

// Function keys with the alt modifier, urxvt
"\x1b\x1b[11~": {Type: KeyF1, Alt: true},
"\x1b\x1b[12~": {Type: KeyF2, Alt: true},
"\x1b\x1b[13~": {Type: KeyF3, Alt: true},
"\x1b\x1b[14~": {Type: KeyF4, Alt: true},
"\x1b\x1b[25~": {Type: KeyF13, Alt: true},
"\x1b\x1b[26~": {Type: KeyF14, Alt: true},
"\x1b\x1b[28~": {Type: KeyF15, Alt: true},
"\x1b\x1b[29~": {Type: KeyF16, Alt: true},
"\x1b\x1b[31~": {Type: KeyF17, Alt: true},
"\x1b\x1b[32~": {Type: KeyF18, Alt: true},
"\x1b\x1b[33~": {Type: KeyF19, Alt: true},
"\x1b\x1b[34~": {Type: KeyF20, Alt: true},
"\x1b\x1b[31~": {Type: KeyF17, Alt: true}, // urxvt
"\x1b\x1b[32~": {Type: KeyF18, Alt: true}, // urxvt
"\x1b\x1b[33~": {Type: KeyF19, Alt: true}, // urxvt
"\x1b\x1b[34~": {Type: KeyF20, Alt: true}, // urxvt
}

// Hex code mappings.
Expand Down