Support bat paging

This commit is contained in:
Antoine Martin 2021-03-16 11:21:44 +01:00
parent 5c8885959a
commit 8ea6e62b29
5 changed files with 21 additions and 2 deletions

7
Cargo.lock generated
View file

@ -86,6 +86,7 @@ dependencies = [
"semver",
"serde",
"serde_yaml",
"shell-words",
"syntect",
"unicode-width",
]
@ -757,6 +758,12 @@ dependencies = [
"yaml-rust",
]
[[package]]
name = "shell-words"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6fa3938c99da4914afedd13bf3d79bcb6c277d1b2c398d23257a304d9e1b074"
[[package]]
name = "snailquote"
version = "0.3.0"

View file

@ -27,7 +27,7 @@ toolchain_find = "0.2"
[dependencies.bat]
version = "0.18"
default-features = false
features = ["regex-fancy"]
features = ["regex-fancy", "paging"]
[dependencies.syn]
version = "1.0"

View file

@ -128,6 +128,13 @@ setting:
color = "always"
```
Enable paging of the output with the `pager` setting:
```toml
[expand]
pager = true
```
## Disclaimer
Be aware that macro expansion to text is a lossy process. This is a debugging

View file

@ -15,6 +15,8 @@ struct Sections {
pub struct Config {
pub theme: Option<String>,
pub color: Option<String>,
#[serde(default = "bool::default")]
pub pager: bool,
}
pub fn deserialize() -> Config {

View file

@ -27,7 +27,7 @@ use std::str::FromStr;
use atty::Stream::{Stderr, Stdout};
use bat::assets::HighlightingAssets;
use bat::PrettyPrinter;
use bat::{PagingMode, PrettyPrinter};
use quote::quote;
use structopt::StructOpt;
use termcolor::{Color::Green, ColorChoice, ColorSpec, StandardStream, WriteColor};
@ -250,6 +250,9 @@ fn cargo_expand() -> Result<i32> {
if let Some(theme) = theme {
pretty_printer.theme(theme);
}
if config.pager {
pretty_printer.paging_mode(PagingMode::QuitIfOneScreen);
}
// Ignore any errors.
let _ = pretty_printer.print();