diff --git a/eventBindings.go b/eventBindings.go index eaf8d92..16d5549 100644 --- a/eventBindings.go +++ b/eventBindings.go @@ -5,7 +5,6 @@ package main import ( "fmt" - "slices" "strings" "syscall" @@ -104,28 +103,20 @@ func theNotsure(g *gocui.Gui, v *gocui.View) error { } func stdoutPgup(g *gocui.Gui, v *gocui.View) error { - 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))) + me.stdout.pager -= 40 + if me.stdout.pager < 0 { + me.stdout.pager = 0 + } + tk := me.stdout.tk + tk.refreshStdout() return nil } func stdoutPgdn(g *gocui.Gui, v *gocui.View) error { 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 - - 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")) + tk.refreshStdout() return nil } @@ -155,10 +146,11 @@ func tabCycleWindows(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.outputOffscreen { 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() return nil } else { diff --git a/stdoutShow.go b/stdoutShow.go index 61f2246..24f1e66 100644 --- a/stdoutShow.go +++ b/stdoutShow.go @@ -175,3 +175,19 @@ func (w *guiWidget) Write(p []byte) (n int, err error) { 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")) +}