feat: Supports vim like j/k keybind with item selection of --init

This commit is contained in:
tsuyoshiwada 2018-02-28 23:09:54 +09:00
parent dd838e8675
commit 790a2e6574
6 changed files with 14 additions and 11 deletions

6
Gopkg.lock generated
View file

@ -74,8 +74,8 @@
"core",
"terminal"
]
revision = "0aa8b6a162b391fe2d95648b7677d1d6ac2090a6"
version = "v1.4.1"
revision = "9f89d9dd66613216993dc300f9f3dbae9c3c9bda"
version = "v1.4.2"
[[projects]]
name = "gopkg.in/kyokomi/emoji.v1"
@ -92,6 +92,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "0be1d1c2f1a9b1c1f1d63ad065141425b62687efb378f6657b088ddf993c3882"
inputs-digest = "da532fb70b3049dffe6ae9f73b3f0a742452639096a325ac5d2400be6ad0559e"
solver-name = "gps-cdcl"
solver-version = 1

View file

@ -29,7 +29,7 @@
[[constraint]]
name = "gopkg.in/AlecAivazis/survey.v1"
version = "1.4.1"
version = "1.4.2"
[[constraint]]
name = "gopkg.in/kyokomi/emoji.v1"

View file

@ -61,7 +61,7 @@ var MultiSelectQuestionTemplate = `
// OnChange is called on every keypress.
func (m *MultiSelect) OnChange(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool) {
if key == terminal.KeyArrowUp {
if key == terminal.KeyArrowUp || key == 'k' {
// if we are at the top of the list
if m.selectedIndex == 0 {
// go to the bottom
@ -70,7 +70,7 @@ func (m *MultiSelect) OnChange(line []rune, pos int, key rune) (newLine []rune,
// decrement the selected index
m.selectedIndex--
}
} else if key == terminal.KeyArrowDown {
} else if key == terminal.KeyArrowDown || key == 'j' {
// if we are at the bottom of the list
if m.selectedIndex == len(m.Options)-1 {
// start at the top

View file

@ -61,8 +61,8 @@ func (s *Select) OnChange(line []rune, pos int, key rune) (newLine []rune, newPo
// if the user pressed the enter key
if key == terminal.KeyEnter {
return []rune(s.Options[s.selectedIndex]), 0, true
// if the user pressed the up arrow
} else if key == terminal.KeyArrowUp {
// if the user pressed the up arrow or 'k' to emulate vim
} else if key == terminal.KeyArrowUp || key == 'k' {
s.useDefault = false
// if we are at the top of the list
@ -73,8 +73,8 @@ func (s *Select) OnChange(line []rune, pos int, key rune) (newLine []rune, newPo
// otherwise we are not at the top of the list so decrement the selected index
s.selectedIndex--
}
// if the user pressed down and there is room to move
} else if key == terminal.KeyArrowDown {
// if the user pressed down or 'j' to emulate vim
} else if key == terminal.KeyArrowDown || key == 'j' {
s.useDefault = false
// if we are at the bottom of the list
if s.selectedIndex == len(s.Options)-1 {

View file

View file

@ -8,8 +8,11 @@ import (
// Required does not allow an empty value
func Required(val interface{}) error {
// the reflect value of the result
value := reflect.ValueOf(val)
// if the value passed in is the zero value of the appropriate type
if isZero(reflect.ValueOf(val)) {
if isZero(value) && value.Kind() != reflect.Bool {
return errors.New("Value is required")
}
return nil