stdout paging updates

This commit is contained in:
Jeff Carr 2025-02-06 20:59:15 -06:00
parent 5d1a3b2578
commit 0b265d2b72
2 changed files with 26 additions and 18 deletions

View File

@ -5,7 +5,6 @@ package main
import ( import (
"fmt" "fmt"
"slices"
"strings" "strings"
"syscall" "syscall"
@ -104,28 +103,20 @@ func theNotsure(g *gocui.Gui, v *gocui.View) error {
} }
func stdoutPgup(g *gocui.Gui, v *gocui.View) error { func stdoutPgup(g *gocui.Gui, v *gocui.View) error {
me.stdout.pager -= 40
if me.stdout.pager < 0 {
me.stdout.pager = 0 me.stdout.pager = 0
log.Info(fmt.Sprintf("try to page up in the stdout buffer here pager=%d len(%d)", me.stdout.pager, len(me.stdout.outputS))) }
tk := me.stdout.tk
tk.refreshStdout()
return nil return nil
} }
func stdoutPgdn(g *gocui.Gui, v *gocui.View) error { func stdoutPgdn(g *gocui.Gui, v *gocui.View) error {
me.stdout.pager += 10 me.stdout.pager += 10
log.Info(fmt.Sprintf("try to page down in the stdout buffer here pager=%d len(%d)", me.stdout.pager, len(me.stdout.outputS)))
tk := me.stdout.tk tk := me.stdout.tk
tk.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)))
return nil
}
var cur []string
// chop off the last lines in the buffer
chop := len(me.stdout.outputS) - (me.stdout.pager + me.stdout.h)
cur = append(cur, me.stdout.outputS[chop:chop+me.stdout.h]...)
slices.Reverse(cur)
tk.v.Clear()
fmt.Fprintln(tk.v, strings.Join(cur, "\n"))
return nil return nil
} }
@ -155,10 +146,11 @@ func tabCycleWindows(g *gocui.Gui, v *gocui.View) error {
} }
func theStdout(g *gocui.Gui, v *gocui.View) error { func theStdout(g *gocui.Gui, v *gocui.View) error {
me.stdout.pager = 0
if me.stdout.outputOnTop { if me.stdout.outputOnTop {
if me.stdout.outputOffscreen { if me.stdout.outputOffscreen {
me.stdout.outputOffscreen = false me.stdout.outputOffscreen = false
log.Info("set stdout off screen here") log.Info(fmt.Sprintf("set stdout off screen pager=%d len(%d)", me.stdout.pager, len(me.stdout.outputS)))
relocateStdoutOffscreen() relocateStdoutOffscreen()
return nil return nil
} else { } else {

View File

@ -175,3 +175,19 @@ func (w *guiWidget) Write(p []byte) (n int, err error) {
return len(p), nil return len(p), nil
} }
// lets the user page up and down through the stdout buffer
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)))
return
}
var cur []string
// chop off the last lines in the buffer
chop := len(me.stdout.outputS) - (me.stdout.pager + me.stdout.h)
cur = append(cur, me.stdout.outputS[chop:chop+me.stdout.h]...)
slices.Reverse(cur)
tk.v.Clear()
fmt.Fprintln(tk.v, strings.Join(cur, "\n"))
}