show stdout buffer when it is small

This commit is contained in:
Jeff Carr 2025-02-09 01:40:57 -06:00
parent 010bd2a33f
commit b8b8a409ea
3 changed files with 17 additions and 4 deletions

View File

@ -31,18 +31,15 @@ func theStdout(g *gocui.Gui, v *gocui.View) error {
me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
me.stdout.outputOnTop = false
setThingsOnTop()
// me.baseGui.SetViewOnBottom("msg")
// setBottomBG()
} else {
me.stdout.outputOnTop = true
setThingsOnTop()
// me.baseGui.SetViewOnTop("msg")
}
return nil
}
func stdoutPgup(g *gocui.Gui, v *gocui.View) error {
me.stdout.pager -= 40
me.stdout.pager -= me.stdout.Height() - 2
if me.stdout.pager < 0 {
me.stdout.pager = 0
}

View File

@ -247,9 +247,13 @@ func refreshGocui() {
continue
}
if time.Since(lastRefresh) > 1000*time.Millisecond {
// artificially pause clock while dragging.
// this is a reminder to make this refresh code smarter
// after the switch to protocol buffers
if me.mouse.mouseUp {
// log.Info("refresh now on mouseUp")
// todo: add logic here to see if the application has changed anything
// me.baseGui.UpdateAsync(testRefresh) // probably don't need this
me.baseGui.Update(testRefresh)
if me.clock.tk != nil && !me.showHelp {
// also double check the gocui view exists

View File

@ -133,6 +133,13 @@ func (tk *guiWidget) relocateStdout(w int, h int) {
// of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must
// be called to clear the view's buffer.
func (w stdout) Height() int {
if w.tk == nil {
return 40
}
return w.tk.gocuiSize.Height() - 2
}
func (w stdout) Write(p []byte) (n int, err error) {
me.writeMutex.Lock()
defer me.writeMutex.Unlock()
@ -200,6 +207,11 @@ func (w *guiWidget) Write(p []byte) (n int, err error) {
func (tk *guiWidget) refreshStdout() {
if len(me.stdout.outputS) < me.stdout.h+me.stdout.pager {
// log.Info(fmt.Sprintf("buffer too small=%d len(%d)", me.stdout.pager, len(me.stdout.outputS)))
var cur []string
cur = append(cur, me.stdout.outputS...)
slices.Reverse(cur)
tk.v.Clear()
fmt.Fprintln(tk.v, strings.Join(cur, "\n"))
return
}