From fa93b16d026b77d98bbc38812d5d9503c7a05f89 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Fri, 8 Aug 2025 13:12:50 +0200 Subject: [PATCH] use internal pager for man page as well --- calc.go | 2 +- main.go | 19 +------------------ pager.go | 8 +++++--- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/calc.go b/calc.go index dd00f56..bd1a205 100644 --- a/calc.go +++ b/calc.go @@ -620,5 +620,5 @@ func (c *Calc) PrintHelp() { } } - Pager(output) + Pager("rpn help overview", output) } diff --git a/main.go b/main.go index 28f3f58..2fc3c75 100644 --- a/main.go +++ b/main.go @@ -18,11 +18,8 @@ along with this program. If not, see . package main import ( - "bytes" "fmt" - "log" "os" - "os/exec" "strings" "github.com/chzyer/readline" @@ -192,19 +189,5 @@ func inputIsStdin() bool { } func man() { - var buf bytes.Buffer - - man := exec.Command("less", "-") - - buf.WriteString(manpage) - - man.Stdout = os.Stdout - man.Stdin = &buf - man.Stderr = os.Stderr - - err := man.Run() - - if err != nil { - log.Fatal(err) - } + Pager("rpn manual page", manpage) } diff --git a/pager.go b/pager.go index 42b4367..e9e1ed0 100644 --- a/pager.go +++ b/pager.go @@ -30,6 +30,7 @@ var ( type model struct { content string + title string ready bool viewport viewport.Model } @@ -86,7 +87,8 @@ func (m model) View() string { } func (m model) headerView() string { - title := titleStyle.Render("RPN Help Overview") + // title := titleStyle.Render("RPN Help Overview") + title := titleStyle.Render(m.title) line := strings.Repeat("─", max(0, m.viewport.Width-lipgloss.Width(title))) return lipgloss.JoinHorizontal(lipgloss.Center, title, line) } @@ -104,9 +106,9 @@ func max(a, b int) int { return b } -func Pager(message string) { +func Pager(title, message string) { p := tea.NewProgram( - model{content: message}, + model{content: message, title: title}, tea.WithAltScreen(), // use the full size of the terminal in its "alternate screen buffer" tea.WithMouseCellMotion(), // turn on mouse support so we can track the mouse wheel )