diff --git a/actions.go b/actions.go index 519c0c7..9b21b4f 100644 --- a/actions.go +++ b/actions.go @@ -311,7 +311,11 @@ func ActionViewDescription(_ []string) { printError("Failed to get issue", err) return } - println(issue.Fields.Description) + err = ShowPaged(issue.Fields.Description) + if err != nil { + printError("Failed to show description", err) + return + } } func ActionViewComments(_ []string) { @@ -327,12 +331,18 @@ func ActionViewComments(_ []string) { if len(issue.Fields.Comments.Comments) == 0 { println("This issue has no comments") } + content := "" for i, comment := range issue.Fields.Comments.Comments { if i != 0 { println() } - fmt.Printf("%s at %s:\n", red(comment.Author.DisplayName), blue(comment.Created)) - fmt.Printf(" %s\n", comment.Body) + content += fmt.Sprintf("%s at %s:\n", red(comment.Author.DisplayName), blue(comment.Created)) + content += fmt.Sprintf(" %s\n", comment.Body) + } + err = ShowPaged(content) + if err != nil { + printError("Failed to show comments", err) + return } } diff --git a/pager.go b/pager.go new file mode 100644 index 0000000..1c210eb --- /dev/null +++ b/pager.go @@ -0,0 +1,24 @@ +package main + +import ( + "os" + "os/exec" + "strings" +) + +func GetPager() (string, []string) { + pager, hasPager := os.LookupEnv("PAGER") + if hasPager { + return pager, nil + } + return "less", []string{"--RAW-CONTROL-CHARS"} +} + +func ShowPaged(content string) error { + pager, args := GetPager() + cmd := exec.Command(pager, args...) + cmd.Stdin = strings.NewReader(content) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() +}