diff --git a/cmd/micro/display/infowindow.go b/cmd/micro/display/infowindow.go index 3fbd0ef4..a03fdc9e 100644 --- a/cmd/micro/display/infowindow.go +++ b/cmd/micro/display/infowindow.go @@ -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) {} diff --git a/cmd/micro/info/infobar.go b/cmd/micro/info/infobar.go index 6a068efe..fb46ea6a 100644 --- a/cmd/micro/info/infobar.go +++ b/cmd/micro/info/infobar.go @@ -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 }