feat: add pager support

Add support for printing the output of timelines, long statuses, etc to
an external pager of the user's choice.
This commit is contained in:
Dan Anglin 2024-06-09 15:58:10 +01:00
parent 9c8476fa97
commit db16e4aa16
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
15 changed files with 129 additions and 88 deletions

View file

@ -46,29 +46,30 @@ func main() {
func run() error { func run() error {
commandSummaries := map[string]string{ commandSummaries := map[string]string{
commandLogin: "login to an account on GoToSocial", commandLogin: "Login to an account on GoToSocial",
commandVersion: "print the application's version and build information", commandVersion: "Print the application's version and build information",
commandShow: "print details about a specified resource", commandShow: "Print details about a specified resource",
commandSwitch: "perform a switch operation (e.g. switch logged in accounts)", commandSwitch: "Perform a switch operation (e.g. switch logged in accounts)",
commandCreate: "create a specific resource", commandCreate: "Create a specific resource",
commandDelete: "delete a specific resource", commandDelete: "Delete a specific resource",
commandEdit: "edit a specific resource", commandEdit: "Edit a specific resource",
commandWhoami: "print the account that you are currently logged in to", commandWhoami: "Print the account that you are currently logged in to",
commandAdd: "add a resource to another resource", commandAdd: "Add a resource to another resource",
commandRemove: "remove a resource from another resource", commandRemove: "Remove a resource from another resource",
commandFollow: "follow a resource (e.g. an account)", commandFollow: "Follow a resource (e.g. an account)",
commandUnfollow: "unfollow a resource (e.g. an account)", commandUnfollow: "Unfollow a resource (e.g. an account)",
commandBlock: "block a resource (e.g. an account)", commandBlock: "Block a resource (e.g. an account)",
commandUnblock: "unblock a resource (e.g. an account)", commandUnblock: "Unblock a resource (e.g. an account)",
} }
topLevelFlags := executor.TopLevelFlags{ topLevelFlags := executor.TopLevelFlags{
ConfigDir: "", ConfigDir: "",
NoColor: nil, NoColor: nil,
Pager: "",
} }
flag.StringVar(&topLevelFlags.ConfigDir, "config-dir", "", "specify your config directory") flag.StringVar(&topLevelFlags.ConfigDir, "config-dir", "", "Specify your config directory")
flag.BoolFunc("no-color", "disable ANSI colour output when displaying text on screen", func(value string) error { flag.BoolFunc("no-color", "Disable ANSI colour output when displaying text on screen", func(value string) error {
boolVal, err := strconv.ParseBool(value) boolVal, err := strconv.ParseBool(value)
if err != nil { if err != nil {
return fmt.Errorf("unable to parse %q as a boolean: %w", value, err) return fmt.Errorf("unable to parse %q as a boolean: %w", value, err)
@ -79,6 +80,7 @@ func run() error {
return nil return nil
}) })
flag.StringVar(&topLevelFlags.Pager, "pager", "", "Specify your preferred pager to page through long outputs. This is disabled by default.")
flag.Usage = usageFunc(commandSummaries) flag.Usage = usageFunc(commandSummaries)

View file

@ -32,12 +32,12 @@ func NewAddExecutor(tlf TopLevelFlags, name, summary string) *AddExecutor {
topLevelFlags: tlf, topLevelFlags: tlf,
} }
addExe.StringVar(&addExe.resourceType, flagType, "", "specify the resource type to add (e.g. account, note)") addExe.StringVar(&addExe.resourceType, flagType, "", "Specify the resource type to add (e.g. account, note)")
addExe.StringVar(&addExe.toResourceType, flagTo, "", "specify the target resource type to add to (e.g. list, account, etc)") addExe.StringVar(&addExe.toResourceType, flagTo, "", "Specify the target resource type to add to (e.g. list, account, etc)")
addExe.StringVar(&addExe.listID, flagListID, "", "the ID of the list to add to") addExe.StringVar(&addExe.listID, flagListID, "", "The ID of the list to add to")
addExe.StringVar(&addExe.statusID, flagStatusID, "", "the ID of the status") addExe.StringVar(&addExe.statusID, flagStatusID, "", "The ID of the status")
addExe.Var(&addExe.accountNames, flagAccountName, "the name of the account") addExe.Var(&addExe.accountNames, flagAccountName, "The name of the account")
addExe.StringVar(&addExe.content, flagContent, "", "the content of the note") addExe.StringVar(&addExe.content, flagContent, "", "The content of the resource")
addExe.Usage = commandUsageFunc(name, summary, addExe.FlagSet) addExe.Usage = commandUsageFunc(name, summary, addExe.FlagSet)

View file

@ -28,8 +28,8 @@ func NewBlockExecutor(tlf TopLevelFlags, name, summary string, unblock bool) *Bl
unblock: unblock, unblock: unblock,
} }
blockExe.StringVar(&blockExe.resourceType, flagType, "", "specify the type of resource to block or unblock") blockExe.StringVar(&blockExe.resourceType, flagType, "", "Specify the type of resource to block or unblock")
blockExe.StringVar(&blockExe.accountName, flagAccountName, "", "specify the account name in full (username@domain)") blockExe.StringVar(&blockExe.accountName, flagAccountName, "", "Specify the account name in full (username@domain)")
blockExe.Usage = commandUsageFunc(name, summary, blockExe.FlagSet) blockExe.Usage = commandUsageFunc(name, summary, blockExe.FlagSet)

View file

@ -41,21 +41,21 @@ func NewCreateExecutor(tlf TopLevelFlags, name, summary string) *CreateExecutor
topLevelFlags: tlf, topLevelFlags: tlf,
} }
createExe.BoolVar(&createExe.boostable, flagEnableReposts, true, "specify if the status can be reposted/boosted by others") createExe.BoolVar(&createExe.boostable, flagEnableReposts, true, "Specify if the status can be reposted/boosted by others")
createExe.BoolVar(&createExe.federated, flagEnableFederation, true, "specify if the status can be federated beyond the local timelines") createExe.BoolVar(&createExe.federated, flagEnableFederation, true, "Specify if the status can be federated beyond the local timelines")
createExe.BoolVar(&createExe.likeable, flagEnableLikes, true, "specify if the status can be liked/favourited") createExe.BoolVar(&createExe.likeable, flagEnableLikes, true, "Specify if the status can be liked/favourited")
createExe.BoolVar(&createExe.replyable, flagEnableReplies, true, "specify if the status can be replied to") createExe.BoolVar(&createExe.replyable, flagEnableReplies, true, "Specify if the status can be replied to")
createExe.StringVar(&createExe.content, flagContent, "", "the content of the status to create") createExe.StringVar(&createExe.content, flagContent, "", "The content of the status to create")
createExe.StringVar(&createExe.contentType, flagContentType, "plain", "the type that the contents should be parsed from (valid values are plain and markdown)") createExe.StringVar(&createExe.contentType, flagContentType, "plain", "The type that the contents should be parsed from (valid values are plain and markdown)")
createExe.StringVar(&createExe.fromFile, flagFromFile, "", "the file path where to read the contents from") createExe.StringVar(&createExe.fromFile, flagFromFile, "", "The file path where to read the contents from")
createExe.StringVar(&createExe.language, flagLanguage, "", "the ISO 639 language code for this status") createExe.StringVar(&createExe.language, flagLanguage, "", "The ISO 639 language code for this status")
createExe.StringVar(&createExe.spoilerText, flagSpoilerText, "", "the text to display as the status' warning or subject") createExe.StringVar(&createExe.spoilerText, flagSpoilerText, "", "The text to display as the status' warning or subject")
createExe.StringVar(&createExe.visibility, flagVisibility, "", "the visibility of the posted status") createExe.StringVar(&createExe.visibility, flagVisibility, "", "The visibility of the posted status")
createExe.StringVar(&createExe.resourceType, flagType, "", "specify the type of resource to create") createExe.StringVar(&createExe.resourceType, flagType, "", "Specify the type of resource to create")
createExe.StringVar(&createExe.listTitle, flagListTitle, "", "specify the title of the list") createExe.StringVar(&createExe.listTitle, flagListTitle, "", "Specify the title of the list")
createExe.StringVar(&createExe.listRepliesPolicy, flagListRepliesPolicy, "list", "specify the policy of the replies for this list (valid values are followed, list and none)") createExe.StringVar(&createExe.listRepliesPolicy, flagListRepliesPolicy, "list", "Specify the policy of the replies for this list (valid values are followed, list and none)")
createExe.BoolFunc(flagSensitive, "specify if the status should be marked as sensitive", func(value string) error { createExe.BoolFunc(flagSensitive, "Specify if the status should be marked as sensitive", func(value string) error {
boolVal, err := strconv.ParseBool(value) boolVal, err := strconv.ParseBool(value)
if err != nil { if err != nil {
return fmt.Errorf("unable to parse %q as a boolean value: %w", value, err) return fmt.Errorf("unable to parse %q as a boolean value: %w", value, err)
@ -116,7 +116,7 @@ func (c *CreateExecutor) createList(gtsClient *client.Client) error {
} }
fmt.Println("Successfully created the following list:") fmt.Println("Successfully created the following list:")
utilities.Display(list, *c.topLevelFlags.NoColor) utilities.Display(list, *c.topLevelFlags.NoColor, c.topLevelFlags.Pager)
return nil return nil
} }
@ -197,7 +197,7 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
} }
fmt.Println("Successfully created the following status:") fmt.Println("Successfully created the following status:")
utilities.Display(status, *c.topLevelFlags.NoColor) utilities.Display(status, *c.topLevelFlags.NoColor, c.topLevelFlags.Pager)
return nil return nil
} }

View file

@ -25,8 +25,8 @@ func NewDeleteExecutor(tlf TopLevelFlags, name, summary string) *DeleteExecutor
topLevelFlags: tlf, topLevelFlags: tlf,
} }
deleteExe.StringVar(&deleteExe.resourceType, flagType, "", "specify the type of resource to delete") deleteExe.StringVar(&deleteExe.resourceType, flagType, "", "Specify the type of resource to delete")
deleteExe.StringVar(&deleteExe.listID, flagListID, "", "specify the ID of the list to delete") deleteExe.StringVar(&deleteExe.listID, flagListID, "", "Specify the ID of the list to delete")
deleteExe.Usage = commandUsageFunc(name, summary, deleteExe.FlagSet) deleteExe.Usage = commandUsageFunc(name, summary, deleteExe.FlagSet)

View file

@ -29,10 +29,10 @@ func NewEditExecutor(tlf TopLevelFlags, name, summary string) *EditExecutor {
topLevelFlags: tlf, topLevelFlags: tlf,
} }
editExe.StringVar(&editExe.resourceType, flagType, "", "specify the type of resource to update") editExe.StringVar(&editExe.resourceType, flagType, "", "Specify the type of resource to update")
editExe.StringVar(&editExe.listID, flagListID, "", "specify the ID of the list to update") editExe.StringVar(&editExe.listID, flagListID, "", "Specify the ID of the list to update")
editExe.StringVar(&editExe.listTitle, flagListTitle, "", "specify the title of the list") editExe.StringVar(&editExe.listTitle, flagListTitle, "", "Specify the title of the list")
editExe.StringVar(&editExe.listRepliesPolicy, flagListRepliesPolicy, "", "specify the policy of the replies for this list (valid values are followed, list and none)") editExe.StringVar(&editExe.listRepliesPolicy, flagListRepliesPolicy, "", "Specify the policy of the replies for this list (valid values are followed, list and none)")
editExe.Usage = commandUsageFunc(name, summary, editExe.FlagSet) editExe.Usage = commandUsageFunc(name, summary, editExe.FlagSet)
@ -90,7 +90,7 @@ func (e *EditExecutor) editList(gtsClient *client.Client) error {
} }
fmt.Println("Successfully updated the list.") fmt.Println("Successfully updated the list.")
utilities.Display(updatedList, *e.topLevelFlags.NoColor) utilities.Display(updatedList, *e.topLevelFlags.NoColor, e.topLevelFlags.Pager)
return nil return nil
} }

View file

@ -23,4 +23,5 @@ func (a *AccountNames) Set(value string) error {
type TopLevelFlags struct { type TopLevelFlags struct {
ConfigDir string ConfigDir string
NoColor *bool NoColor *bool
Pager string
} }

View file

@ -29,10 +29,10 @@ func NewFollowExecutor(tlf TopLevelFlags, name, summary string, unfollow bool) *
topLevelFlags: tlf, topLevelFlags: tlf,
} }
command.StringVar(&command.resourceType, flagType, "", "specify the type of resource to follow") command.StringVar(&command.resourceType, flagType, "", "Specify the type of resource to follow")
command.StringVar(&command.accountName, flagAccountName, "", "specify the account name in full (username@domain)") command.StringVar(&command.accountName, flagAccountName, "", "Specify the account name in full (username@domain)")
command.BoolVar(&command.showReposts, flagShowReposts, true, "show reposts from the account you want to follow") command.BoolVar(&command.showReposts, flagShowReposts, true, "Show reposts from the account you want to follow")
command.BoolVar(&command.notify, flagNotify, false, "get notifications when the account you want to follow posts a status") command.BoolVar(&command.notify, flagNotify, false, "Get notifications when the account you want to follow posts a status")
command.Usage = commandUsageFunc(name, summary, command.FlagSet) command.Usage = commandUsageFunc(name, summary, command.FlagSet)

View file

@ -28,7 +28,7 @@ func NewLoginExecutor(tlf TopLevelFlags, name, summary string) *LoginExecutor {
instance: "", instance: "",
} }
command.StringVar(&command.instance, flagInstance, "", "specify the instance that you want to login to.") command.StringVar(&command.instance, flagInstance, "", "Specify the instance that you want to login to.")
command.Usage = commandUsageFunc(name, summary, command.FlagSet) command.Usage = commandUsageFunc(name, summary, command.FlagSet)

View file

@ -31,11 +31,11 @@ func NewRemoveExecutor(tlf TopLevelFlags, name, summary string) *RemoveExecutor
topLevelFlags: tlf, topLevelFlags: tlf,
} }
removeExe.StringVar(&removeExe.resourceType, flagType, "", "specify the resource type to remove (e.g. account, note)") removeExe.StringVar(&removeExe.resourceType, flagType, "", "Specify the resource type to remove (e.g. account, note)")
removeExe.StringVar(&removeExe.fromResourceType, flagFrom, "", "specify the resource type to remove from (e.g. list, account, etc)") removeExe.StringVar(&removeExe.fromResourceType, flagFrom, "", "Specify the resource type to remove from (e.g. list, account, etc)")
removeExe.StringVar(&removeExe.listID, flagListID, "", "the ID of the list to remove from") removeExe.StringVar(&removeExe.listID, flagListID, "", "The ID of the list to remove from")
removeExe.StringVar(&removeExe.statusID, flagStatusID, "", "the ID of the status") removeExe.StringVar(&removeExe.statusID, flagStatusID, "", "The ID of the status")
removeExe.Var(&removeExe.accountNames, flagAccountName, "the name of the account to remove from the resource") removeExe.Var(&removeExe.accountNames, flagAccountName, "The name of the account to remove from the resource")
removeExe.Usage = commandUsageFunc(name, summary, removeExe.FlagSet) removeExe.Usage = commandUsageFunc(name, summary, removeExe.FlagSet)

View file

@ -35,17 +35,17 @@ func NewShowExecutor(tlf TopLevelFlags, name, summary string) *ShowExecutor {
topLevelFlags: tlf, topLevelFlags: tlf,
} }
showExe.BoolVar(&showExe.myAccount, flagMyAccount, false, "set to true to lookup your account") showExe.BoolVar(&showExe.myAccount, flagMyAccount, false, "Set to true to lookup your account")
showExe.BoolVar(&showExe.skipAccountRelationship, flagSkipRelationship, false, "set to true to skip showing your relationship to the specified account") showExe.BoolVar(&showExe.skipAccountRelationship, flagSkipRelationship, false, "Set to true to skip showing your relationship to the specified account")
showExe.BoolVar(&showExe.showUserPreferences, flagShowPreferences, false, "show your preferences") showExe.BoolVar(&showExe.showUserPreferences, flagShowPreferences, false, "Show your preferences")
showExe.BoolVar(&showExe.showInBrowser, flagBrowser, false, "set to true to view in the browser") showExe.BoolVar(&showExe.showInBrowser, flagBrowser, false, "Set to true to view in the browser")
showExe.StringVar(&showExe.resourceType, flagType, "", "specify the type of resource to display") showExe.StringVar(&showExe.resourceType, flagType, "", "Specify the type of resource to display")
showExe.StringVar(&showExe.accountName, flagAccountName, "", "specify the account name in full (username@domain)") showExe.StringVar(&showExe.accountName, flagAccountName, "", "Specify the account name in full (username@domain)")
showExe.StringVar(&showExe.statusID, flagStatusID, "", "specify the ID of the status to display") showExe.StringVar(&showExe.statusID, flagStatusID, "", "Specify the ID of the status to display")
showExe.StringVar(&showExe.timelineCategory, flagTimelineCategory, model.TimelineCategoryHome, "specify the timeline category to view") showExe.StringVar(&showExe.timelineCategory, flagTimelineCategory, model.TimelineCategoryHome, "Specify the timeline category to view")
showExe.StringVar(&showExe.listID, flagListID, "", "specify the ID of the list to display") showExe.StringVar(&showExe.listID, flagListID, "", "Specify the ID of the list to display")
showExe.StringVar(&showExe.tag, flagTag, "", "specify the name of the tag to use") showExe.StringVar(&showExe.tag, flagTag, "", "Specify the name of the tag to use")
showExe.IntVar(&showExe.limit, flagLimit, 20, "specify the limit of items to display") showExe.IntVar(&showExe.limit, flagLimit, 20, "Specify the limit of items to display")
showExe.Usage = commandUsageFunc(name, summary, showExe.FlagSet) showExe.Usage = commandUsageFunc(name, summary, showExe.FlagSet)
@ -90,7 +90,7 @@ func (s *ShowExecutor) showInstance(gtsClient *client.Client) error {
return fmt.Errorf("unable to retrieve the instance details: %w", err) return fmt.Errorf("unable to retrieve the instance details: %w", err)
} }
utilities.Display(instance, *s.topLevelFlags.NoColor) utilities.Display(instance, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
return nil return nil
} }
@ -123,7 +123,7 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
return nil return nil
} }
utilities.Display(account, *s.topLevelFlags.NoColor) utilities.Display(account, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
if !s.myAccount && !s.skipAccountRelationship { if !s.myAccount && !s.skipAccountRelationship {
relationship, err := gtsClient.GetAccountRelationship(account.ID) relationship, err := gtsClient.GetAccountRelationship(account.ID)
@ -131,7 +131,7 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
return fmt.Errorf("unable to retrieve the relationship to this account: %w", err) return fmt.Errorf("unable to retrieve the relationship to this account: %w", err)
} }
utilities.Display(relationship, *s.topLevelFlags.NoColor) utilities.Display(relationship, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
} }
if s.myAccount && s.showUserPreferences { if s.myAccount && s.showUserPreferences {
@ -140,7 +140,7 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
return fmt.Errorf("unable to retrieve the user preferences: %w", err) return fmt.Errorf("unable to retrieve the user preferences: %w", err)
} }
utilities.Display(preferences, *s.topLevelFlags.NoColor) utilities.Display(preferences, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
} }
return nil return nil
@ -162,7 +162,7 @@ func (s *ShowExecutor) showStatus(gtsClient *client.Client) error {
return nil return nil
} }
utilities.Display(status, *s.topLevelFlags.NoColor) utilities.Display(status, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
return nil return nil
} }
@ -211,7 +211,7 @@ func (s *ShowExecutor) showTimeline(gtsClient *client.Client) error {
return nil return nil
} }
utilities.Display(timeline, *s.topLevelFlags.NoColor) utilities.Display(timeline, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
return nil return nil
} }
@ -240,7 +240,7 @@ func (s *ShowExecutor) showList(gtsClient *client.Client) error {
list.Accounts = accountMap list.Accounts = accountMap
} }
utilities.Display(list, *s.topLevelFlags.NoColor) utilities.Display(list, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
return nil return nil
} }
@ -257,7 +257,7 @@ func (s *ShowExecutor) showLists(gtsClient *client.Client) error {
return nil return nil
} }
utilities.Display(lists, *s.topLevelFlags.NoColor) utilities.Display(lists, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
return nil return nil
} }
@ -274,7 +274,7 @@ func (s *ShowExecutor) showFollowers(gtsClient *client.Client) error {
} }
if len(followers.Accounts) > 0 { if len(followers.Accounts) > 0 {
utilities.Display(followers, *s.topLevelFlags.NoColor) utilities.Display(followers, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
} else { } else {
fmt.Println("There are no followers for this account or the list is hidden.") fmt.Println("There are no followers for this account or the list is hidden.")
} }
@ -294,7 +294,7 @@ func (s *ShowExecutor) showFollowing(gtsClient *client.Client) error {
} }
if len(following.Accounts) > 0 { if len(following.Accounts) > 0 {
utilities.Display(following, *s.topLevelFlags.NoColor) utilities.Display(following, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
} else { } else {
fmt.Println("This account is not following anyone or the list is hidden.") fmt.Println("This account is not following anyone or the list is hidden.")
} }
@ -309,7 +309,7 @@ func (s *ShowExecutor) showBlocked(gtsClient *client.Client) error {
} }
if len(blocked.Accounts) > 0 { if len(blocked.Accounts) > 0 {
utilities.Display(blocked, *s.topLevelFlags.NoColor) utilities.Display(blocked, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
} else { } else {
fmt.Println("You have no blocked accounts.") fmt.Println("You have no blocked accounts.")
} }
@ -324,7 +324,7 @@ func (s *ShowExecutor) showBookmarks(gtsClient *client.Client) error {
} }
if len(bookmarks.Statuses) > 0 { if len(bookmarks.Statuses) > 0 {
utilities.Display(bookmarks, *s.topLevelFlags.NoColor) utilities.Display(bookmarks, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
} else { } else {
fmt.Println("You have no bookmarks.") fmt.Println("You have no bookmarks.")
} }
@ -339,7 +339,7 @@ func (s *ShowExecutor) showLiked(gtsClient *client.Client) error {
} }
if len(liked.Statuses) > 0 { if len(liked.Statuses) > 0 {
utilities.Display(liked, *s.topLevelFlags.NoColor) utilities.Display(liked, *s.topLevelFlags.NoColor, s.topLevelFlags.Pager)
} else { } else {
fmt.Printf("You have no %s statuses.\n", s.resourceType) fmt.Printf("You have no %s statuses.\n", s.resourceType)
} }

View file

@ -25,8 +25,8 @@ func NewSwitchExecutor(tlf TopLevelFlags, name, summary string) *SwitchExecutor
topLevelFlags: tlf, topLevelFlags: tlf,
} }
switchExe.StringVar(&switchExe.toResourceType, flagTo, "", "the account to switch to") switchExe.StringVar(&switchExe.toResourceType, flagTo, "", "The account to switch to")
switchExe.StringVar(&switchExe.accountName, flagAccountName, "", "the name of the account to switch to") switchExe.StringVar(&switchExe.accountName, flagAccountName, "", "The name of the account to switch to")
switchExe.Usage = commandUsageFunc(name, summary, switchExe.FlagSet) switchExe.Usage = commandUsageFunc(name, summary, switchExe.FlagSet)

View file

@ -30,7 +30,7 @@ func NewVersionExecutor(name, summary, binaryVersion, buildTime, goVersion, gitC
showFullVersion: false, showFullVersion: false,
} }
command.BoolVar(&command.showFullVersion, "full", false, "prints the full build information") command.BoolVar(&command.showFullVersion, "Full", false, "prints the full build information")
command.Usage = commandUsageFunc(name, summary, command.FlagSet) command.Usage = commandUsageFunc(name, summary, command.FlagSet)

View file

@ -209,7 +209,7 @@ type StatusList struct {
func (s StatusList) Display(noColor bool) string { func (s StatusList) Display(noColor bool) string {
var builder strings.Builder var builder strings.Builder
separator := "────────────────────────────────────────────────────────────────────────────────" separator := strings.Repeat("─", 80)
builder.WriteString(utilities.HeaderFormat(noColor, s.Name) + "\n") builder.WriteString(utilities.HeaderFormat(noColor, s.Name) + "\n")

View file

@ -4,12 +4,50 @@
package utilities package utilities
import "os" import (
"fmt"
"os"
"os/exec"
"strings"
)
type Displayer interface { type Displayer interface {
Display(noColor bool) string Display(noColor bool) string
} }
func Display(d Displayer, noColor bool) { func Display(displayer Displayer, noColor bool, pagerCommand string) {
os.Stdout.WriteString(d.Display(noColor) + "\n") if pagerCommand == "" {
os.Stdout.WriteString(displayer.Display(noColor) + "\n")
return
}
split := strings.Split(pagerCommand, " ")
pager := new(exec.Cmd)
if len(split) == 1 {
pager = exec.Command(split[0]) //nolint:gosec
} else {
pager = exec.Command(split[0], split[1:]...) //nolint:gosec
}
pipe, err := pager.StdinPipe()
if err != nil {
os.Stdout.WriteString(displayer.Display(noColor) + "\n")
return
}
pager.Stdout = os.Stdout
pager.Stderr = os.Stderr
_ = pager.Start()
defer func() {
_ = pipe.Close()
_ = pager.Wait()
}()
fmt.Fprintln(pipe, displayer.Display(noColor)+"\n")
} }