Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve user control of paging #373

Merged
merged 5 commits into from
Sep 11, 2020

Conversation

jdbaldry
Copy link
Member

@jdbaldry jdbaldry commented Sep 4, 2020

This allows users to avoid a pager by emptying out the PAGER environment variable (setting PAGER=""), only defaulting to less with posix flags (not supported by busybox less) if PAGER is unset.

Closes #293

@jdbaldry
Copy link
Member Author

jdbaldry commented Sep 4, 2020

I haven't yet added a top level --no-pager option but would be willing to make that change if desirable. Presumably it would be a top level option that would globally disable paging for all subcommands.

@jdbaldry
Copy link
Member Author

jdbaldry commented Sep 4, 2020

I've preferred not breaking/changing the existing default pager behavior over supporting the simplest pager but that may be worth reconsidering if we think running in a busybox environment is more likely.

Also, I'm not sure how paging works on windows but this probably doesn't make the situation any worse. Possibly Windows has the more command (https://superuser.com/questions/426226/less-or-more-in-windows/426229) but I don't have any convenient environments in which to check this.

cmd/tk/util.go Outdated
}
} else {
fmt.Println(r)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't print an io.Reader, need to read first :)

Maybe put this the bottom of the func:

_, err := io.Copy(os.Stdout, r)
return err

Then also when the cmd fails, don't return but instead just do "nothing", so it automatically falls back to above code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! The proposed refactor sounds nice but changes the function signature for fPageln and potentially for pageln too. If that's cool, I'll go ahead and make this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with both fPageln and pageln returning errors, it should be up to the consumer to ignore them if applicable.

Also makes the control flow inside a bit simpler I guess

@jdbaldry jdbaldry force-pushed the resolve-293-tk-show-pager-improvements branch from fe659b7 to 1934e55 Compare September 11, 2020 07:58
@jdbaldry
Copy link
Member Author

Thanks for all the feedback @sh0rez. I think this is ready for a second pass now :)

Copy link
Member

@sh0rez sh0rez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!!

Have some nitpicks, feel free to ignore

Comment on lines 194 to 198
if err := pageln(pretty.String()); err != nil {
return err
}

return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's the last statement, no need for if-else, as returning err does the same thing

cmd/tk/util.go Outdated
Comment on lines 35 to 36
err := cmd.Run()
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be one line using if err := ...; err != nil

Signed-off-by: Jack Baldry <[email protected]>
@jdbaldry jdbaldry force-pushed the resolve-293-tk-show-pager-improvements branch from e1ddda0 to f25ffad Compare September 11, 2020 08:26
@jdbaldry jdbaldry merged commit 4164b77 into master Sep 11, 2020
@jdbaldry jdbaldry deleted the resolve-293-tk-show-pager-improvements branch September 11, 2020 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tk show pager improvements
2 participants