Skip to content

Commit

Permalink
Use termion backend for cursive
Browse files Browse the repository at this point in the history
With this patch, we replace cursive’s default ncurses backend with the
termion backend.  This has multiple reasons:
- The ncurses backend has safety issues, see [0].
- ncurses requires a pre-installed library and a C compiler, introducing
  additional build dependencies.  Termion is implemented in Rust only.
- ncurses does not work on Windows, while termion works in all terminals
  that support ANSI escape codes.

Per default, the termion backend does not buffer the output which may
cause flickering [1].  Therefore, we also use the
cursive_buffered_backend that buffers the output and fixes the
flickering problem.

[0] gyscos/cursive#488
[1] gyscos/cursive#142
  • Loading branch information
robinkrahl committed Oct 8, 2020
1 parent 568fb0a commit 8db34e3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 49 deletions.
65 changes: 39 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Expand Up @@ -19,7 +19,7 @@ exclude = [".builds/*", "tests/html/*", "tests/snapshots/*"]
ansi_term = "0.12.1"
anyhow = "1.0.31"
atty = "0.2.14"
cursive = "0.15.0"
cursive_buffered_backend = "0.4"
cursive-markup = "0.1"
html2text = "0.2.1"
kuchiki = "0.8.0"
Expand All @@ -36,6 +36,11 @@ url = "2.1.1"
webbrowser = "0.5.5"
xdg = "2.2.0"

[dependencies.cursive]
version = "0.15"
default-features = false
features = ["termion-backend"]

[dependencies.env_logger]
version = "0.7.1"
default-features = false
Expand Down
18 changes: 1 addition & 17 deletions INSTALL.md
Expand Up @@ -16,23 +16,7 @@ rusty-man packages are available for these distributions:

### Build Requirements

To compile rusty-man, you need Rust 1.40 or later. The `tui` backend requires
the ncurses library in the default search path and a C compiler.

If you don’t want to use ncurses, you can select another [`cursive`][] backend
by replacing this line in `Cargo.toml`:

```toml
cursive = "0.15.0"
```

with this:

```toml
cursive = { version = "0.15.0", default-features = false, feature = ["termion-backend"] }
```

[`cursive`]: https://lib.rs/cursive
To compile rusty-man, you need Rust 1.40 or later.

### Installing from Git

Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -72,10 +72,10 @@ information. rusty-man is also available as a package for these distributions:
- Arch Linux: [`rusty-man`][pkg-aur] in the Arch User Repository

rusty-man is developed for Unix-like systems. It should run on other platforms
too, but with some limitations: The `rich` viewer uses ANSI escape codes,
which are not supported on older Windows versions. The `tui` viewer requires
the ncurses library. If you have trouble running rusty-man on your platform or
if you want to help porting rusty-man to other platforms, please let me know.
too, but with some limitations: The `rich` and `tui` viewers uses ANSI escape
codes, which are not supported on older Windows versions. If you have trouble
running rusty-man on your platform or if you want to help porting rusty-man to
other platforms, please let me know.

## Integrations

Expand Down
10 changes: 9 additions & 1 deletion src/viewer/tui/mod.rs
Expand Up @@ -189,11 +189,19 @@ fn indent_view<V>(indent: impl Into<usize>, view: V) -> PaddedView<V> {
PaddedView::lrtb(indent.into(), 0, 0, 0, view)
}

fn create_backend() -> anyhow::Result<Box<dyn cursive::backend::Backend>> {
let termion =
cursive::backends::termion::Backend::init().context("Could not create termion backend")?;
let buffered = cursive_buffered_backend::BufferedBackend::new(termion);
Ok(Box::new(buffered))
}

fn create_cursive(
sources: Vec<Box<dyn source::Source>>,
args: args::ViewerArgs,
) -> anyhow::Result<cursive::Cursive> {
let mut cursive = cursive::default();
let mut cursive =
cursive::Cursive::try_new(create_backend).context("Could not create Cursive instance")?;

cursive.set_user_data(Context::new(sources, args)?);

Expand Down

0 comments on commit 8db34e3

Please sign in to comment.