use internal pager for man page as well

This commit is contained in:
2025-08-08 13:12:50 +02:00
parent 15c40583a2
commit fa93b16d02
3 changed files with 7 additions and 22 deletions

View File

@@ -620,5 +620,5 @@ func (c *Calc) PrintHelp() {
} }
} }
Pager(output) Pager("rpn help overview", output)
} }

19
main.go
View File

@@ -18,11 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package main package main
import ( import (
"bytes"
"fmt" "fmt"
"log"
"os" "os"
"os/exec"
"strings" "strings"
"github.com/chzyer/readline" "github.com/chzyer/readline"
@@ -192,19 +189,5 @@ func inputIsStdin() bool {
} }
func man() { func man() {
var buf bytes.Buffer Pager("rpn manual page", manpage)
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)
}
} }

View File

@@ -30,6 +30,7 @@ var (
type model struct { type model struct {
content string content string
title string
ready bool ready bool
viewport viewport.Model viewport viewport.Model
} }
@@ -86,7 +87,8 @@ func (m model) View() string {
} }
func (m model) headerView() 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))) line := strings.Repeat("─", max(0, m.viewport.Width-lipgloss.Width(title)))
return lipgloss.JoinHorizontal(lipgloss.Center, title, line) return lipgloss.JoinHorizontal(lipgloss.Center, title, line)
} }
@@ -104,9 +106,9 @@ func max(a, b int) int {
return b return b
} }
func Pager(message string) { func Pager(title, message string) {
p := tea.NewProgram( 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.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 tea.WithMouseCellMotion(), // turn on mouse support so we can track the mouse wheel
) )