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

#36 add -p --pager flag to page the output using pager crate #44

Merged
merged 4 commits into from
Mar 11, 2019
Merged

#36 add -p --pager flag to page the output using pager crate #44

merged 4 commits into from
Mar 11, 2019

Conversation

jdvr
Copy link
Contributor

@jdvr jdvr commented Aug 21, 2018

I just added the pager crate and a flag (-p --pager) to enable or disable it.

BTW, I have tested it with Rust 1.28.0 and it works well, maybe you can update.

I would need help for windows and macOS testers.

refs #36

@jdvr jdvr mentioned this pull request Aug 21, 2018
dbrgn
dbrgn previously requested changes Aug 21, 2018
Copy link
Collaborator

@dbrgn dbrgn left a comment

Choose a reason for hiding this comment

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

Oh, the pager crate looks really nice 🙂 Perfect fit for tealdeer, I think.

src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
@jdvr
Copy link
Contributor Author

jdvr commented Aug 27, 2018

@dbrgn is there any pending issue about this ?

@dbrgn dbrgn dismissed their stale review August 30, 2018 11:55

Implemented

@dbrgn
Copy link
Collaborator

dbrgn commented Aug 30, 2018

@dbrgn is there any pending issue about this ?

No, I just needed to find some free time to review 🙂

My main issue with this is currently that the default pager is more, which does not support arrow up/down keys. I think most tools default to less which is more user friendly in that regard.

In my opinion the pager crate should first probe for less, and if found, invoke it with the -r or -R option for color support. Only then it should fall back to more. But maybe more is part of POSIX and less isn't?

We could force less to be used by using Pager::with_pager("less -r").setup(), but then we lose the ability to set another pager with the PAGER env variable, as well as support for the NOPAGER env var... A pull request to pager with a way to override the default (but still allowing env vars) would probably be nice.

Furthermore, it doesn't seem to be supported on Windows:

https://gitlab.com/imp/pager-rs/issues/5

So we should probably exclude the pager functionality when building for Windows.

I'll test the PR on macOS next week.

Regarding defaults, I'm not sure yet whether paging should be the default behavior or not. Probably not, but we can add it to the configuration file once #43 has landed.

@jdvr
Copy link
Contributor Author

jdvr commented Sep 3, 2018

I will keep the -p while #43 is in progress and then we can use the configuration file and implement the use of PAGER env var on our own.

I mean, we can follow a priority to check if the output has to be paged:

  1. -p (page always)
  2. Enabled in configuration file

Once we know we have to page, check if any pager is configure (PAGER env var or config file), otherwise use less -r.

@dbrgn
Copy link
Collaborator

dbrgn commented Sep 4, 2018

I tested it on macOS. Seems to work generally, but without colors:

screen shot 2018-09-04 at 09 35 29

Reason is that more is an alias for less, which requires the -r option to render escape codes.

screen shot 2018-09-04 at 09 35 55

All the more reason to use less -r by default :)

@jdvr
Copy link
Contributor Author

jdvr commented Sep 7, 2018

yep, totally agree, let's change by less -r because it also will work well in most Linux distribution

@dbrgn
Copy link
Collaborator

dbrgn commented Sep 7, 2018

I opened an issue: https://gitlab.com/imp/pager-rs/issues/10

@dbrgn
Copy link
Collaborator

dbrgn commented Sep 18, 2018

It seems that the pager author is willing to add a way to override the default pager. Let's wait for that until we continue with this PR, I guess it should be a matter of weeks :)

@dbrgn
Copy link
Collaborator

dbrgn commented Oct 3, 2018

Released in pager 0.15! This should do:

Pager::with_default_pager("less -R").setup();

Also, in the meantime configfile support was merged 🙂

@jdvr
Copy link
Contributor Author

jdvr commented Oct 4, 2018

Thank you @dbrgn, I will update my PR today. I will also include an option for the configuration file as we commented previously on this thread.

@jdvr
Copy link
Contributor Author

jdvr commented Mar 4, 2019

Totally forgot about this 🙏. I will try to finish the task.

@jdvr
Copy link
Contributor Author

jdvr commented Mar 8, 2019

@dbrgn I have already tested this on Linux with several commands. I think is ready to be merge

Copy link
Collaborator

@dbrgn dbrgn left a comment

Choose a reason for hiding this comment

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

Some feedback 🙂

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
tests/config.toml Outdated Show resolved Hide resolved
@jdvr
Copy link
Contributor Author

jdvr commented Mar 11, 2019

Tanks for the feedback @dbrgn

I have updated the code.

@dbrgn
Copy link
Collaborator

dbrgn commented Mar 11, 2019

Thanks @jdvr!

For some reason the PR deletes the Cargo.lock file, but I can fix that in a manual merge.

@dbrgn dbrgn mentioned this pull request Mar 11, 2019
@dbrgn
Copy link
Collaborator

dbrgn commented Mar 11, 2019

Huh, what's wrong with Travis... The tests passed but the state wasn't updated.

@dbrgn dbrgn merged commit 7a809d8 into tealdeer-rs:master Mar 11, 2019
@jdvr
Copy link
Contributor Author

jdvr commented Mar 12, 2019

I am happy to see this merged after a lot of time 😁

@mystal
Copy link
Contributor

mystal commented Mar 16, 2019

Oh no, this broke Windows support :( pager-rs doesn't support Windows (yet): https://gitlab.com/imp/pager-rs/issues/5

@dbrgn
Copy link
Collaborator

dbrgn commented Mar 16, 2019

Oh, too bad 🤕 We need Windows CI, otherwise this might happen again in the future.

Maybe we could simply disable pager support on Windows?

@mystal
Copy link
Contributor

mystal commented Mar 17, 2019

Yeah, that's a good idea. I'll try to take a look next weekend when I should hopefully have some time.

Aside from that, pager support on Unix sounds great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants