mirror of
https://github.com/sharkdp/bat.git
synced 2024-12-23 06:48:53 +01:00
Add option to disable automatic paging
This commit is contained in:
parent
c253821a5e
commit
ec606e5dcc
22
src/main.rs
22
src/main.rs
@ -65,8 +65,8 @@ struct Options<'a> {
|
|||||||
true_color: bool,
|
true_color: bool,
|
||||||
style: OptionsStyle,
|
style: OptionsStyle,
|
||||||
language: Option<&'a str>,
|
language: Option<&'a str>,
|
||||||
interactive_terminal: bool,
|
|
||||||
colored_output: bool,
|
colored_output: bool,
|
||||||
|
paging: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum OutputType<'a> {
|
enum OutputType<'a> {
|
||||||
@ -318,8 +318,8 @@ fn get_git_diff(filename: &str) -> Option<LineChanges> {
|
|||||||
Some(line_changes)
|
Some(line_changes)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_output_type(stdout: &Stdout, interactive_terminal: bool) -> OutputType {
|
fn get_output_type(stdout: &Stdout, paging: bool) -> OutputType {
|
||||||
if interactive_terminal {
|
if paging {
|
||||||
match OutputType::pager() {
|
match OutputType::pager() {
|
||||||
Ok(pager) => pager,
|
Ok(pager) => pager,
|
||||||
Err(_) => OutputType::stdout(&stdout),
|
Err(_) => OutputType::stdout(&stdout),
|
||||||
@ -495,6 +495,14 @@ fn run() -> Result<()> {
|
|||||||
.default_value("auto")
|
.default_value("auto")
|
||||||
.help("When to use colors"),
|
.help("When to use colors"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("paging")
|
||||||
|
.long("paging")
|
||||||
|
.takes_value(true)
|
||||||
|
.possible_values(&["auto", "never", "always"])
|
||||||
|
.default_value("auto")
|
||||||
|
.help("When to use the pager")
|
||||||
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("init-cache")
|
SubCommand::with_name("init-cache")
|
||||||
.about("Load syntax definitions and themes into cache"),
|
.about("Load syntax definitions and themes into cache"),
|
||||||
@ -522,12 +530,16 @@ fn run() -> Result<()> {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
language: app_matches.value_of("language"),
|
language: app_matches.value_of("language"),
|
||||||
interactive_terminal,
|
|
||||||
colored_output: match app_matches.value_of("color") {
|
colored_output: match app_matches.value_of("color") {
|
||||||
Some("always") => true,
|
Some("always") => true,
|
||||||
Some("never") => false,
|
Some("never") => false,
|
||||||
_ => interactive_terminal,
|
_ => interactive_terminal,
|
||||||
},
|
},
|
||||||
|
paging: match app_matches.value_of("paging") {
|
||||||
|
Some("always") => true,
|
||||||
|
Some("never") => false,
|
||||||
|
Some("auto") | _ => interactive_terminal,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let assets =
|
let assets =
|
||||||
@ -542,7 +554,7 @@ fn run() -> Result<()> {
|
|||||||
|
|
||||||
if let Some(files) = app_matches.values_of("FILE") {
|
if let Some(files) = app_matches.values_of("FILE") {
|
||||||
let stdout = io::stdout();
|
let stdout = io::stdout();
|
||||||
let mut output_type = get_output_type(&stdout, options.interactive_terminal);
|
let mut output_type = get_output_type(&stdout, options.paging);
|
||||||
let handle = output_type.handle()?;
|
let handle = output_type.handle()?;
|
||||||
for file in files {
|
for file in files {
|
||||||
let line_changes = get_git_diff(&file.to_string());
|
let line_changes = get_git_diff(&file.to_string());
|
||||||
|
Loading…
Reference in New Issue
Block a user