7 "github.com/zyedidia/micro/cmd/micro/buffer"
10 // The InfoBuf displays messages and other info at the bottom of the screen.
11 // It is respresented as a buffer and a message with a style.
21 // This map stores the history for all the different kinds of uses Prompt has
22 // It's a map of history type -> history array
23 History map[string][]string
26 // Is the current message a message from the gutter
29 PromptCallback func(resp string, canceled bool)
32 func NewBuffer() *InfoBuf {
34 ib.History = make(map[string][]string)
36 ib.Buffer = buffer.NewBufferFromString("", "infobar", buffer.BTInfo)
41 // Message sends a message to the user
42 func (i *InfoBuf) Message(msg ...interface{}) {
43 // only display a new message if there isn't an active prompt
44 // this is to prevent overwriting an existing prompt to the user
45 if i.HasPrompt == false {
46 displayMessage := fmt.Sprint(msg...)
47 // if there is no active prompt then style and display the message as normal
48 i.Msg = displayMessage
53 // Error sends an error message to the user
54 func (i *InfoBuf) Error(msg ...interface{}) {
55 // only display a new message if there isn't an active prompt
56 // this is to prevent overwriting an existing prompt to the user
57 if i.HasPrompt == false {
58 // if there is no active prompt then style and display the message as normal
59 i.Msg = fmt.Sprint(msg...)
60 i.HasMessage, i.HasError = false, true
65 func (i *InfoBuf) Prompt(prompt string, msg string, callback func(string, bool)) {
66 // If we get another prompt mid-prompt we cancel the one getting overwritten
73 i.HasMessage, i.HasError = false, false
74 i.PromptCallback = callback
75 i.Buffer.Insert(i.Buffer.Start(), msg)
78 func (i *InfoBuf) DonePrompt(canceled bool) {
81 i.PromptCallback("", true)
83 i.PromptCallback(strings.TrimSpace(string(i.LineBytes(0))), false)
85 i.Replace(i.Start(), i.End(), "")
88 // Reset resets the messenger's cursor, message and response
89 func (i *InfoBuf) Reset() {
91 i.HasPrompt, i.HasMessage, i.HasError = false, false, false