This commit is contained in:
parent
d71e38f5db
commit
d5812297b2
16
actions.go
16
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
|
||||
}
|
||||
}
|
||||
|
||||
|
24
pager.go
Normal file
24
pager.go
Normal file
@ -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()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user