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

Provide a library interface #11

Merged
merged 7 commits into from
Jan 5, 2020
Merged

Provide a library interface #11

merged 7 commits into from
Jan 5, 2020

Conversation

quark-zju
Copy link
Contributor

This PR did some cleanups and extracts sp's key features as a simple library. Applications using the library interface can avoid forking and use native Rust streams (impl Read) instead of non-portable RawFds. An example was added to demostrate how it works.

Remove some warnings.
termwiz 0.5 switched to anyhow.
If terminfo is None, sp only renders to a single line with garbage content.
Detect that and refuse to run.

The problematic environment that I encountered has:
- TERM=xterm
- TERMINFO_DIRS=/usr/share/terminfo-backports
- TERMINFO is not set
- /usr/share/terminfo/x/xterm exists
- /usr/share/terminfo-backports/x/xterm-256color exists

The Rust `terminfo` crate does not search `/usr/share/terminfo` while ncurses
does. From `man curses`, it _seems_ `/usr/share/terminfo` shouldn't be
searched, if hard-coded.
This adds a bit more flexibility.
This adds a bit flexibility and improves portability.
Expose key features (pager with streams) via the `Pager` struct. This allows
applications to setup the pager using native Rust streams (ex. impl Read),
and start a pager without forking.

The `lib.rs` is copied from `main.rs`. I didn't figure out a way to make git
realize it is a copy without using merge commits.
The example is similar to streams_example.sh, but written in pure Rust.
@quark-zju quark-zju force-pushed the as-library branch 2 times, most recently from 012ceb1 to bc04a2a Compare January 5, 2020 04:05
@markbt
Copy link
Owner

markbt commented Jan 5, 2020

Looks great! I'll make sp and spp use the library, too, which should avoid the code duplication.

@markbt markbt merged commit dd5f35c into markbt:master Jan 5, 2020
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.

None yet

2 participants