Pager: expose cmd for getting terminal size + bind pgup/pgdown

This commit is contained in:
Christian Rocha 2020-05-13 22:06:35 -04:00
parent 251f944f12
commit 254c098066
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 7 additions and 3 deletions

View File

@ -66,7 +66,7 @@ func Init(initialContent string) func() (boba.Model, boba.Cmd) {
m.Standalone = true m.Standalone = true
m.Content(initialContent) m.Content(initialContent)
return func() (boba.Model, boba.Cmd) { return func() (boba.Model, boba.Cmd) {
return m, getTerminalSize return m, GetTerminalSize
} }
} }
@ -92,11 +92,15 @@ func Update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
} }
// Up one page // Up one page
case "pgup":
fallthrough
case "b": case "b":
m.Y = max(0, m.Y-m.Height) m.Y = max(0, m.Y-m.Height)
return m, nil return m, nil
// Down one page // Down one page
case "pgdown":
fallthrough
case "space": case "space":
fallthrough fallthrough
case "f": case "f":
@ -129,7 +133,7 @@ func Update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
// Re-render // Re-render
case "ctrl+l": case "ctrl+l":
return m, getTerminalSize return m, GetTerminalSize
} }
@ -176,7 +180,7 @@ func View(model boba.Model) string {
// CMD // CMD
func getTerminalSize() boba.Msg { func GetTerminalSize() boba.Msg {
w, h, err := terminal.GetSize(int(os.Stdout.Fd())) w, h, err := terminal.GetSize(int(os.Stdout.Fd()))
if err != nil { if err != nil {
return errMsg(err) return errMsg(err)