KeyMap Expansion
This commit is contained in:
18
cli.go
18
cli.go
@@ -171,12 +171,12 @@ func (w *Cli) WantW() int { return w.w }
|
||||
func (w *Cli) WantH() int { return w.h }
|
||||
|
||||
func (w *Cli) initKeyMap() {
|
||||
w.keyMap = NewKeyMap(map[tcell.Key]func() bool{
|
||||
tcell.KeyEsc: func() bool {
|
||||
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{
|
||||
tcell.KeyEsc: func(ev *tcell.EventKey) bool {
|
||||
w.SetActive(false)
|
||||
return true
|
||||
},
|
||||
tcell.KeyUp: func() bool {
|
||||
tcell.KeyUp: func(ev *tcell.EventKey) bool {
|
||||
if w.historyPosition < len(w.history)-1 {
|
||||
w.historyPosition++
|
||||
w.value = w.history[w.historyPosition]
|
||||
@@ -185,7 +185,7 @@ func (w *Cli) initKeyMap() {
|
||||
}
|
||||
return false
|
||||
},
|
||||
tcell.KeyDown: func() bool {
|
||||
tcell.KeyDown: func(ev *tcell.EventKey) bool {
|
||||
if w.historyPosition > -1 {
|
||||
w.historyPosition--
|
||||
if w.historyPosition == -1 {
|
||||
@@ -198,26 +198,26 @@ func (w *Cli) initKeyMap() {
|
||||
}
|
||||
return false
|
||||
},
|
||||
tcell.KeyLeft: func() bool {
|
||||
tcell.KeyLeft: func(ev *tcell.EventKey) bool {
|
||||
if w.cursor > 0 {
|
||||
w.cursor--
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
tcell.KeyRight: func() bool {
|
||||
tcell.KeyRight: func(ev *tcell.EventKey) bool {
|
||||
if w.cursor < len(w.value) {
|
||||
w.cursor++
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
tcell.KeyCtrlU: func() bool {
|
||||
tcell.KeyCtrlU: func(ev *tcell.EventKey) bool {
|
||||
w.value = w.value[w.cursor:]
|
||||
w.cursor = 0
|
||||
return true
|
||||
},
|
||||
tcell.KeyTab: func() bool {
|
||||
tcell.KeyTab: func(ev *tcell.EventKey) bool {
|
||||
// Auto-complete
|
||||
guess := w.findBestGuess()
|
||||
if guess != "" {
|
||||
@@ -227,7 +227,7 @@ func (w *Cli) initKeyMap() {
|
||||
}
|
||||
return false
|
||||
},
|
||||
tcell.KeyEnter: func() bool {
|
||||
tcell.KeyEnter: func(ev *tcell.EventKey) bool {
|
||||
cmds := strings.Split(w.value, " ")
|
||||
if v, ok := w.commandMap[cmds[0]]; ok {
|
||||
w.history = append(w.history, w.value)
|
||||
|
||||
Reference in New Issue
Block a user