go-prompt/key_bind.go

60 lines
1.1 KiB
Go
Raw Normal View History

2017-08-13 04:09:45 +00:00
package prompt
2018-02-15 07:36:35 +00:00
// KeyBindFunc receives buffer and processed it.
2017-08-14 16:50:33 +00:00
type KeyBindFunc func(*Buffer)
2017-08-13 04:09:45 +00:00
2018-02-15 07:36:35 +00:00
// KeyBind represents which key should do what operation.
2017-08-13 04:09:45 +00:00
type KeyBind struct {
Key Key
Fn KeyBindFunc
}
// ASCIICodeBind represents which []byte should do what operation
type ASCIICodeBind struct {
ASCIICode []byte
Fn KeyBindFunc
}
2018-02-15 07:36:35 +00:00
// KeyBindMode to switch a key binding flexibly.
2017-08-13 04:33:51 +00:00
type KeyBindMode string
const (
2018-02-15 07:36:35 +00:00
// CommonKeyBind is a mode without any keyboard shortcut
2017-08-13 04:33:51 +00:00
CommonKeyBind KeyBindMode = "common"
2018-02-15 07:36:35 +00:00
// EmacsKeyBind is a mode to use emacs-like keyboard shortcut
EmacsKeyBind KeyBindMode = "emacs"
2017-08-13 04:33:51 +00:00
)
2017-08-14 16:50:33 +00:00
var commonKeyBindings = []KeyBind{
2017-08-13 04:09:45 +00:00
// Go to the End of the line
{
Key: End,
Fn: GoLineEnd,
2017-08-13 04:09:45 +00:00
},
// Go to the beginning of the line
{
Key: Home,
Fn: GoLineBeginning,
2017-08-13 04:09:45 +00:00
},
// Delete character under the cursor
{
Key: Delete,
Fn: DeleteChar,
2017-08-13 04:09:45 +00:00
},
// Backspace
{
Key: Backspace,
Fn: DeleteBeforeChar,
2017-08-13 04:09:45 +00:00
},
// Right allow: Forward one character
{
Key: Right,
Fn: GoRightChar,
2017-08-13 04:09:45 +00:00
},
// Left allow: Backward one character
{
Key: Left,
Fn: GoLeftChar,
2017-08-13 04:09:45 +00:00
},
}