Minor infobar improvements

This commit is contained in:
Zachary Yedidia
2019-01-01 17:54:29 -05:00
parent afe24698ea
commit 78ce7a5f0f
2 changed files with 41 additions and 0 deletions

View File

@@ -48,6 +48,35 @@ func NewInfoWindow(b *info.Bar) *InfoWindow {
return iw
}
// func (i *InfoWindow) YesNoPrompt() (bool, bool) {
// for {
// i.Clear()
// i.Display()
// screen.Screen.ShowCursor(utf8.RuneCountInString(i.Msg), i.y)
// screen.Show()
// event := <-events
//
// switch e := event.(type) {
// case *tcell.EventKey:
// switch e.Key() {
// case tcell.KeyRune:
// if e.Rune() == 'y' || e.Rune() == 'Y' {
// i.HasPrompt = false
// return true, false
// } else if e.Rune() == 'n' || e.Rune() == 'N' {
// i.HasPrompt = false
// return false, false
// }
// case tcell.KeyCtrlC, tcell.KeyCtrlQ, tcell.KeyEscape:
// i.Clear()
// i.Reset()
// i.HasPrompt = false
// return false, true
// }
// }
// }
// }
func (i *InfoWindow) Relocate() bool { return false }
func (i *InfoWindow) GetView() *View { return i.View }
func (i *InfoWindow) SetView(v *View) {}

View File

@@ -69,6 +69,11 @@ func (i *Bar) Error(msg ...interface{}) {
}
func (i *Bar) Prompt(msg string, callback func(string, bool)) {
// If we get another prompt mid-prompt we cancel the one getting overwritten
if i.HasPrompt {
i.DonePrompt(true)
}
i.Msg = msg
i.HasPrompt = true
i.HasMessage, i.HasError = false, false
@@ -82,4 +87,11 @@ func (i *Bar) DonePrompt(canceled bool) {
} else {
i.PromptCallback(strings.TrimSpace(string(i.LineBytes(0))), false)
}
i.Replace(i.Start(), i.End(), "")
}
// Reset resets the messenger's cursor, message and response
func (i *Bar) Reset() {
i.Msg = ""
i.HasPrompt, i.HasMessage, i.HasError = false, false, false
}