Implemented basic system

This commit is contained in:
2018-04-02 15:40:10 +01:00
parent 080d61728c
commit 3a482ca3f7
11 changed files with 135 additions and 30 deletions

View File

@@ -43,6 +43,9 @@ type Select struct {
// Searcher can be implemented to teach the select how to search for items.
Searcher list.Searcher
// Starts the prompt in search mode.
StartInSearchMode bool
label string
list *list.List
@@ -150,11 +153,11 @@ func (s *Select) innerRun(starting int, top rune) (int, string, error) {
var searchInput []rune
canSearch := s.Searcher != nil
searchMode := false
searchMode := s.StartInSearchMode
c.SetListener(func(line []rune, pos int, key rune) ([]rune, int, bool) {
switch {
case key == readline.CharEnter:
case key == KeyEnter:
return nil, 0, true
case key == s.Keys.Next.Code || (key == 'j' && !searchMode):
s.list.Next()
@@ -172,7 +175,7 @@ func (s *Select) innerRun(starting int, top rune) (int, string, error) {
} else {
searchMode = true
}
case key == readline.CharBackspace:
case key == KeyBackspace:
if !canSearch || !searchMode {
break
}
@@ -442,10 +445,10 @@ func (s *Select) setKeys() {
return
}
s.Keys = &SelectKeys{
Prev: Key{Code: readline.CharPrev, Display: "↑"},
Next: Key{Code: readline.CharNext, Display: "↓"},
PageUp: Key{Code: readline.CharBackward, Display: "←"},
PageDown: Key{Code: readline.CharForward, Display: "→"},
Prev: Key{Code: KeyPrev, Display: "↑"},
Next: Key{Code: KeyNext, Display: "↓"},
PageUp: Key{Code: KeyBackward, Display: "←"},
PageDown: Key{Code: KeyForward, Display: "→"},
Search: Key{Code: '/', Display: "/"},
}
}