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

The interplay between Backspace and CtrlH is complex (on Windows) and not documented #495

Closed
vovcacik opened this issue Oct 12, 2021 · 3 comments

Comments

@vovcacik
Copy link

When user needs to distinguish between physically hitting backspace key and ctrl+h combo, the key events coming from tcell are hard to reason about. It is complex enough to make test cases for all combinations.

// redacted tests for brevity
type giveKey struct {
	Type tcell.Key
	Char rune
	Mods tcell.ModMask
}
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModNone},                    // actual "Backspace" keystroke
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModAlt},                     // actual "Alt+Backspace" keystroke
giveKey{tcell.KeyDEL,   rune(tcell.KeyDEL),   tcell.ModCtrl},                    // actual "Ctrl+Backspace" keystroke
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModShift},                   // actual "Shift+Backspace" keystroke
giveKey{tcell.KeyCtrlH, 0,                    tcell.ModCtrl | tcell.ModAlt},     // actual "Ctrl+Alt+Backspace" keystroke
giveKey{tcell.KeyCtrlH, 0,                    tcell.ModCtrl | tcell.ModShift},   // actual "Ctrl+Shift+Backspace" keystroke
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModShift | tcell.ModAlt},    // actual "Shift+Alt+Backspace" keystroke
                                                                                 // actual "Ctrl+Shift+Alt+Backspace" keystroke
giveKey{tcell.KeyCtrlH, 0,                    tcell.ModCtrl | tcell.ModAlt | tcell.ModShift},
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl},                    // actual "Ctrl+H" keystroke
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl | tcell.ModShift},   // actual "Ctrl+Shift+H" keystroke

https://github.com/junegunn/fzf/blob/5fc78e4584eface9f2055ee7c31c2ae8c5cedc87/src/tui/tcell_test.go#L113-L123

@gdamore
Copy link
Owner

gdamore commented Oct 12, 2021

So it turn out that there is a reason this is hard to reason about -- generally the underlying terminals (outside of Windows which is a special case) send CTRL-H as Backspace (or Delete, which is another confusing thing).

On Windows we get to know precisely which keys you pressed, but we also want the code to portable to other platforms. However, because with Windows we get the modifier keys we do actually send the modifiers we get.

@vovcacik
Copy link
Author

Especially seeing tcell.KeyDEL on windows was strange, I think the OS itself doesn't use the 0x7F.

I noticed few other issues related to mysteries of backspace, so I wanted to file this issues as a memo. Feel free to close it.

@gdamore
Copy link
Owner

gdamore commented Oct 12, 2021

Ok. Will do so. There is not a lot we can with some of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants