tui-go
tui-go copied to clipboard
Add support for Emacs style key sequences
For example, the key sequence, Ctrl+X followed by Ctrl+C.
Here's some API proposals (are there more?):
// Proposal 1
ui.SetKeybinding([]string{"Ctrl+X", "Ctrl+C"}, func() { ui.Quit() })
// Proposal 2
ui.SetKeybinding(func() { ui.Quit() }, "Ctrl+X", "Ctrl+C")
// Proposal 3
ui.SetKeybinding(tui.KeySequence("Ctrl+X", "Ctrl+C"), func() { ui.Quit() })
Imho the proposal 2 with using of variable parameters is the most clean!
Stopping by as a curious Vim user:
How close do the presses have to be to be considered the same event? Where is that timeout set (UI?)
Or is it just a prefix tree, where falling off resets:
ui.SetKeybinding(tui.KeySequence("Ctrl+X", "Ctrl+C"), func { ui.Quit() })
ui.SetKeybinding("Z", func { fmt.Println("You pressed Z!") })
digraph G {
start -> v [label="Ctrl+X"] ;
start -> PRINT [label="Z"];
v -> QUIT [label="Ctrl+C"];
v -> start [label="ε"];
}