Have CanClose use single letters for responses

Closes #184
This commit is contained in:
Zachary Yedidia
2016-08-29 10:10:16 -04:00
parent eda08a994a
commit fccec47ae5
3 changed files with 36 additions and 7 deletions

View File

@@ -124,6 +124,35 @@ func (m *Messenger) YesNoPrompt(prompt string) (bool, bool) {
}
}
// LetterPrompt gives the user a prompt and waits for a one letter response
func (m *Messenger) LetterPrompt(prompt string, responses ...rune) (rune, bool) {
m.Message(prompt)
_, h := screen.Size()
for {
m.Clear()
m.Display()
screen.ShowCursor(Count(m.message), h-1)
screen.Show()
event := <-events
switch e := event.(type) {
case *tcell.EventKey:
switch e.Key() {
case tcell.KeyRune:
for _, r := range responses {
if e.Rune() == r {
m.Reset()
return r, false
}
}
case tcell.KeyCtrlC, tcell.KeyCtrlQ, tcell.KeyEscape:
return ' ', true
}
}
}
}
type Completion int
const (