micro/internal/action/globals.go

49 lines
1.1 KiB
Go
Raw Normal View History

2019-01-02 03:36:12 +00:00
package action
2020-05-04 14:16:15 +00:00
import "github.com/zyedidia/micro/v2/internal/buffer"
2019-08-06 03:43:34 +00:00
2019-01-02 03:36:12 +00:00
var InfoBar *InfoPane
2019-08-06 03:43:34 +00:00
var LogBufPane *BufPane
2019-01-02 03:36:12 +00:00
2020-02-12 17:35:40 +00:00
// InitGlobals initializes the log buffer and the info bar
2019-01-02 03:36:12 +00:00
func InitGlobals() {
InfoBar = NewInfoBar()
2019-08-06 03:43:34 +00:00
buffer.LogBuf = buffer.NewBufferFromString("", "Log", buffer.BTLog)
2019-01-02 03:36:12 +00:00
}
2019-03-19 22:28:51 +00:00
2020-02-12 17:35:40 +00:00
// GetInfoBar returns the infobar pane
2019-03-19 22:28:51 +00:00
func GetInfoBar() *InfoPane {
return InfoBar
}
2019-08-06 03:43:34 +00:00
2020-02-12 17:35:40 +00:00
// WriteLog writes a string to the log buffer
2019-08-06 03:43:34 +00:00
func WriteLog(s string) {
buffer.WriteLog(s)
if LogBufPane != nil {
LogBufPane.CursorEnd()
v := LogBufPane.GetView()
endY := buffer.LogBuf.End().Y
if endY > v.StartLine+v.Height {
v.StartLine = buffer.LogBuf.End().Y - v.Height + 2
LogBufPane.SetView(v)
}
}
}
2020-02-12 17:35:40 +00:00
// OpenLogBuf opens the log buffer from the current bufpane
// If the current bufpane is a log buffer nothing happens,
// otherwise the log buffer is opened in a horizontal split
func (h *BufPane) OpenLogBuf() {
2019-08-06 03:43:34 +00:00
LogBufPane = h.HSplitBuf(buffer.LogBuf)
LogBufPane.CursorEnd()
v := LogBufPane.GetView()
endY := buffer.LogBuf.End().Y
if endY > v.StartLine+v.Height {
v.StartLine = buffer.LogBuf.End().Y - v.Height + 2
LogBufPane.SetView(v)
}
}