|
|
@ -16,7 +16,7 @@ use errors::*;
|
|
|
|
use line_range::LineRange;
|
|
|
|
use line_range::LineRange;
|
|
|
|
use style::{OutputComponent, OutputComponents, OutputWrap};
|
|
|
|
use style::{OutputComponent, OutputComponents, OutputWrap};
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
pub enum PagingMode {
|
|
|
|
pub enum PagingMode {
|
|
|
|
Always,
|
|
|
|
Always,
|
|
|
|
QuitIfOneScreen,
|
|
|
|
QuitIfOneScreen,
|
|
|
@ -353,6 +353,27 @@ impl App {
|
|
|
|
let files = self.files();
|
|
|
|
let files = self.files();
|
|
|
|
let output_components = self.output_components()?;
|
|
|
|
let output_components = self.output_components()?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let paging_mode = match self.matches.value_of("paging") {
|
|
|
|
|
|
|
|
Some("always") => PagingMode::Always,
|
|
|
|
|
|
|
|
Some("never") => PagingMode::Never,
|
|
|
|
|
|
|
|
Some("auto") | _ => if files.contains(&InputFile::StdIn) {
|
|
|
|
|
|
|
|
// If we are reading from stdin, only enable paging if we write to an
|
|
|
|
|
|
|
|
// interactive terminal and if we do not *read* from an interactive
|
|
|
|
|
|
|
|
// terminal.
|
|
|
|
|
|
|
|
if self.interactive_output && !atty::is(Stream::Stdin) {
|
|
|
|
|
|
|
|
PagingMode::QuitIfOneScreen
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
PagingMode::Never
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if self.interactive_output {
|
|
|
|
|
|
|
|
PagingMode::QuitIfOneScreen
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
PagingMode::Never
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Ok(Config {
|
|
|
|
Ok(Config {
|
|
|
|
true_color: is_truecolor_terminal(),
|
|
|
|
true_color: is_truecolor_terminal(),
|
|
|
|
language: self.matches.value_of("language"),
|
|
|
|
language: self.matches.value_of("language"),
|
|
|
@ -376,26 +397,7 @@ impl App {
|
|
|
|
Some("never") => false,
|
|
|
|
Some("never") => false,
|
|
|
|
Some("auto") | _ => self.interactive_output,
|
|
|
|
Some("auto") | _ => self.interactive_output,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
paging_mode: match self.matches.value_of("paging") {
|
|
|
|
paging_mode,
|
|
|
|
Some("always") => PagingMode::Always,
|
|
|
|
|
|
|
|
Some("never") => PagingMode::Never,
|
|
|
|
|
|
|
|
Some("auto") | _ => if files.contains(&InputFile::StdIn) {
|
|
|
|
|
|
|
|
// If we are reading from stdin, only enable paging if we write to an
|
|
|
|
|
|
|
|
// interactive terminal and if we do not *read* from an interactive
|
|
|
|
|
|
|
|
// terminal.
|
|
|
|
|
|
|
|
if self.interactive_output && !atty::is(Stream::Stdin) {
|
|
|
|
|
|
|
|
PagingMode::QuitIfOneScreen
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
PagingMode::Never
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if self.interactive_output {
|
|
|
|
|
|
|
|
PagingMode::QuitIfOneScreen
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
PagingMode::Never
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
term_width: self
|
|
|
|
term_width: self
|
|
|
|
.matches
|
|
|
|
.matches
|
|
|
|
.value_of("terminal-width")
|
|
|
|
.value_of("terminal-width")
|
|
|
@ -410,7 +412,13 @@ impl App {
|
|
|
|
.value_of("tabs")
|
|
|
|
.value_of("tabs")
|
|
|
|
.and_then(|w| w.parse().ok())
|
|
|
|
.and_then(|w| w.parse().ok())
|
|
|
|
.or_else(|| env::var("BAT_TABS").ok().and_then(|w| w.parse().ok()))
|
|
|
|
.or_else(|| env::var("BAT_TABS").ok().and_then(|w| w.parse().ok()))
|
|
|
|
.unwrap_or(8),
|
|
|
|
.unwrap_or(
|
|
|
|
|
|
|
|
if output_components.plain() && paging_mode == PagingMode::Never {
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
theme: self
|
|
|
|
theme: self
|
|
|
|
.matches
|
|
|
|
.matches
|
|
|
|
.value_of("theme")
|
|
|
|
.value_of("theme")
|
|
|
|