mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-25 01:03:46 +01:00
Changed default to be Plain in case of loop_through
This commit is contained in:
parent
2ba681315c
commit
1f4d6f0a89
@ -93,7 +93,16 @@ impl App {
|
||||
}
|
||||
|
||||
pub fn config(&self, inputs: &[Input]) -> Result<Config> {
|
||||
let style_components = self.style_components()?;
|
||||
let loop_through = !(self.interactive_output
|
||||
|| self.matches.get_one::<String>("color").map(|s| s.as_str()) == Some("always")
|
||||
|| self
|
||||
.matches
|
||||
.get_one::<String>("decorations")
|
||||
.map(|s| s.as_str())
|
||||
== Some("always")
|
||||
|| self.matches.get_flag("force-colorization"));
|
||||
|
||||
let style_components = self.style_components(loop_through)?;
|
||||
|
||||
let paging_mode = match self.matches.get_one::<String>("paging").map(|s| s.as_str()) {
|
||||
Some("always") => PagingMode::Always,
|
||||
@ -222,14 +231,7 @@ impl App {
|
||||
},
|
||||
paging_mode,
|
||||
term_width: maybe_term_width.unwrap_or(Term::stdout().size().1 as usize),
|
||||
loop_through: !(self.interactive_output
|
||||
|| self.matches.get_one::<String>("color").map(|s| s.as_str()) == Some("always")
|
||||
|| self
|
||||
.matches
|
||||
.get_one::<String>("decorations")
|
||||
.map(|s| s.as_str())
|
||||
== Some("always")
|
||||
|| self.matches.get_flag("force-colorization")),
|
||||
loop_through: loop_through,
|
||||
tab_width: self
|
||||
.matches
|
||||
.get_one::<String>("tabs")
|
||||
@ -353,7 +355,7 @@ impl App {
|
||||
Ok(file_input)
|
||||
}
|
||||
|
||||
fn style_components(&self) -> Result<StyleComponents> {
|
||||
fn style_components(&self, loop_through: bool) -> Result<StyleComponents> {
|
||||
let matches = &self.matches;
|
||||
let mut styled_components = StyleComponents(
|
||||
if matches.get_one::<String>("decorations").map(|s| s.as_str()) == Some("never") {
|
||||
@ -374,7 +376,7 @@ impl App {
|
||||
})
|
||||
.unwrap_or_else(|| vec![StyleComponent::Default])
|
||||
.into_iter()
|
||||
.map(|style| style.components(self.interactive_output))
|
||||
.map(|style| style.components(self.interactive_output, loop_through))
|
||||
.fold(HashSet::new(), |mut acc, components| {
|
||||
acc.extend(components.iter().cloned());
|
||||
acc
|
||||
|
@ -365,7 +365,9 @@ fn run() -> Result<bool> {
|
||||
let languages: String = get_languages(&config, cache_dir)?;
|
||||
let inputs: Vec<Input> = vec![Input::from_reader(Box::new(languages.as_bytes()))];
|
||||
let plain_config = Config {
|
||||
style_components: StyleComponents::new(StyleComponent::Plain.components(false)),
|
||||
style_components: StyleComponents::new(
|
||||
StyleComponent::Plain.components(false, config.loop_through),
|
||||
),
|
||||
paging_mode: PagingMode::QuitIfOneScreen,
|
||||
..Default::default()
|
||||
};
|
||||
|
@ -15,7 +15,6 @@ use crate::output::OutputType;
|
||||
#[cfg(feature = "paging")]
|
||||
use crate::paging::PagingMode;
|
||||
use crate::printer::{InteractivePrinter, OutputHandle, Printer, SimplePrinter};
|
||||
use crate::style::{StyleComponent, StyleComponents};
|
||||
|
||||
use clircle::{Clircle, Identifier};
|
||||
|
||||
@ -175,19 +174,8 @@ impl<'b> Controller<'b> {
|
||||
None
|
||||
};
|
||||
|
||||
let mut config = self.config.clone();
|
||||
|
||||
if self.config.loop_through {
|
||||
config = Config {
|
||||
style_components: StyleComponents(
|
||||
[StyleComponent::Plain].iter().cloned().collect(),
|
||||
),
|
||||
..self.config.clone()
|
||||
};
|
||||
}
|
||||
|
||||
let mut printer: Box<dyn Printer> = if self.config.loop_through {
|
||||
Box::new(SimplePrinter::new(&config))
|
||||
Box::new(SimplePrinter::new(self.config))
|
||||
} else {
|
||||
Box::new(InteractivePrinter::new(
|
||||
self.config,
|
||||
|
36
src/style.rs
36
src/style.rs
@ -22,13 +22,17 @@ pub enum StyleComponent {
|
||||
}
|
||||
|
||||
impl StyleComponent {
|
||||
pub fn components(self, interactive_terminal: bool) -> &'static [StyleComponent] {
|
||||
pub fn components(
|
||||
self,
|
||||
interactive_terminal: bool,
|
||||
loop_through: bool,
|
||||
) -> &'static [StyleComponent] {
|
||||
match self {
|
||||
StyleComponent::Auto => {
|
||||
if interactive_terminal {
|
||||
StyleComponent::Default.components(interactive_terminal)
|
||||
StyleComponent::Default.components(interactive_terminal, loop_through)
|
||||
} else {
|
||||
StyleComponent::Plain.components(interactive_terminal)
|
||||
StyleComponent::Plain.components(interactive_terminal, loop_through)
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "git")]
|
||||
@ -49,14 +53,24 @@ impl StyleComponent {
|
||||
StyleComponent::LineNumbers,
|
||||
StyleComponent::Snip,
|
||||
],
|
||||
StyleComponent::Default => &[
|
||||
#[cfg(feature = "git")]
|
||||
StyleComponent::Changes,
|
||||
StyleComponent::Grid,
|
||||
StyleComponent::HeaderFilename,
|
||||
StyleComponent::LineNumbers,
|
||||
StyleComponent::Snip,
|
||||
],
|
||||
StyleComponent::Default => {
|
||||
if loop_through {
|
||||
return &[
|
||||
#[cfg(feature = "git")]
|
||||
StyleComponent::Changes,
|
||||
StyleComponent::Plain,
|
||||
];
|
||||
} else {
|
||||
return &[
|
||||
#[cfg(feature = "git")]
|
||||
StyleComponent::Changes,
|
||||
StyleComponent::Grid,
|
||||
StyleComponent::HeaderFilename,
|
||||
StyleComponent::LineNumbers,
|
||||
StyleComponent::Snip,
|
||||
];
|
||||
}
|
||||
}
|
||||
StyleComponent::Plain => &[],
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ fn basic() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 hello world\n")
|
||||
.stdout("hello world\n")
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ fn stdin() {
|
||||
.write_stdin("foo\nbar\n")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 foo\n 2 bar\n");
|
||||
.stdout("foo\nbar\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -68,7 +68,7 @@ fn concatenate() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 hello world\n 1 hello world\n");
|
||||
.stdout("hello world\nhello world\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -80,7 +80,7 @@ fn concatenate_stdin() {
|
||||
.write_stdin("stdin\n")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 hello world\n 1 stdin\n 1 hello world\n");
|
||||
.stdout("hello world\nstdin\nhello world\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -90,7 +90,7 @@ fn concatenate_empty_first() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 hello world\n");
|
||||
.stdout("hello world\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -100,7 +100,7 @@ fn concatenate_empty_last() {
|
||||
.arg("empty.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 hello world\n");
|
||||
.stdout("hello world\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -121,7 +121,7 @@ fn concatenate_empty_between() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 hello world\n 1 hello world\n");
|
||||
.stdout("hello world\nhello world\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -132,7 +132,7 @@ fn concatenate_empty_first_and_last() {
|
||||
.arg("empty.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 hello world\n");
|
||||
.stdout("hello world\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -142,7 +142,7 @@ fn concatenate_single_line() {
|
||||
.arg("single-line.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 Single Line 1 Single Line");
|
||||
.stdout("Single LineSingle Line");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -153,7 +153,7 @@ fn concatenate_single_line_empty() {
|
||||
.arg("single-line.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 Single Line 1 Single Line");
|
||||
.stdout("Single LineSingle Line");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -174,7 +174,7 @@ fn line_range_2_3() {
|
||||
.arg("--line-range=2:3")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 2 line 2\n 3 line 3\n");
|
||||
.stdout("line 2\nline 3\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -184,7 +184,7 @@ fn line_range_first_two() {
|
||||
.arg("--line-range=:2")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 line 1\n 2 line 2\n");
|
||||
.stdout("line 1\nline 2\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -194,7 +194,7 @@ fn line_range_last_3() {
|
||||
.arg("--line-range=2:")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 2 line 2\n 3 line 3\n 4 line 4\n");
|
||||
.stdout("line 2\nline 3\nline 4\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -205,7 +205,7 @@ fn line_range_multiple() {
|
||||
.arg("--line-range=4:4")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 line 1\n 2 line 2\n 4 line 4\n");
|
||||
.stdout("line 1\nline 2\nline 4\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -215,7 +215,7 @@ fn squeeze_blank() {
|
||||
.arg("--squeeze-blank")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 line 1\n 2 \n 5 line 5\n 6 \n 20 line 20\n 21 line 21\n 22 \n 24 line 24\n 25 \n 26 line 26\n 27 \n 30 line 30\n");
|
||||
.stdout("line 1\n\nline 5\n\nline 20\nline 21\n\nline 24\n\nline 26\n\nline 30\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -238,7 +238,7 @@ fn squeeze_limit() {
|
||||
.arg("--squeeze-limit=2")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 line 1\n 2 \n 3 \n 5 line 5\n 6 \n 7 \n 20 line 20\n 21 line 21\n 22 \n 23 \n 24 line 24\n 25 \n 26 line 26\n 27 \n 28 \n 30 line 30\n");
|
||||
.stdout("line 1\n\n\nline 5\n\n\nline 20\nline 21\n\n\nline 24\n\nline 26\n\n\nline 30\n");
|
||||
|
||||
bat()
|
||||
.arg("empty_lines.txt")
|
||||
@ -246,7 +246,7 @@ fn squeeze_limit() {
|
||||
.arg("--squeeze-limit=5")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 line 1\n 2 \n 3 \n 4 \n 5 line 5\n 6 \n 7 \n 8 \n 9 \n 10 \n 20 line 20\n 21 line 21\n 22 \n 23 \n 24 line 24\n 25 \n 26 line 26\n 27 \n 28 \n 29 \n 30 line 30\n");
|
||||
.stdout("line 1\n\n\n\nline 5\n\n\n\n\n\nline 20\nline 21\n\n\nline 24\n\nline 26\n\n\n\nline 30\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -693,7 +693,7 @@ fn do_not_exit_directory() {
|
||||
.arg("sub_directory")
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.stdout(" 1 hello world\n")
|
||||
.stdout("hello world\n")
|
||||
.failure();
|
||||
}
|
||||
|
||||
@ -752,7 +752,7 @@ fn pager_disable() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::eq(" 1 hello world\n").normalize());
|
||||
.stdout(predicate::eq("hello world\n").normalize());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -833,7 +833,7 @@ fn env_var_pager_value_bat() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::eq(" 1 hello world\n").normalize());
|
||||
.stdout(predicate::eq("hello world\n").normalize());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -871,7 +871,7 @@ fn pager_most_from_pager_env_var() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::eq(" 1 hello world\n").normalize());
|
||||
.stdout(predicate::eq("hello world\n").normalize());
|
||||
});
|
||||
}
|
||||
|
||||
@ -917,7 +917,7 @@ fn pager_most_with_arg() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::eq(" 1 hello world\n").normalize());
|
||||
.stdout(predicate::eq("hello world\n").normalize());
|
||||
});
|
||||
}
|
||||
|
||||
@ -932,7 +932,7 @@ fn pager_more() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::eq(" 1 hello world\n").normalize());
|
||||
.stdout(predicate::eq("hello world\n").normalize());
|
||||
});
|
||||
}
|
||||
|
||||
@ -944,7 +944,7 @@ fn alias_pager_disable() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::eq(" 1 hello world\n").normalize());
|
||||
.stdout(predicate::eq("hello world\n").normalize());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -971,7 +971,7 @@ fn disable_pager_if_disable_paging_flag_comes_after_paging() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::eq(" 1 hello world\n").normalize());
|
||||
.stdout(predicate::eq("hello world\n").normalize());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1043,7 +1043,7 @@ fn basic_set_terminal_title() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("\u{1b}]0;bat: test.txt\x07 1 hello world\n")
|
||||
.stdout("\u{1b}]0;bat: test.txt\x07hello world\n")
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
@ -1294,7 +1294,7 @@ fn can_print_file_named_cache() {
|
||||
.arg("cache")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 test\n")
|
||||
.stdout("test\n")
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
@ -1305,7 +1305,7 @@ fn can_print_file_named_cache_with_additional_argument() {
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 test\n 1 hello world\n")
|
||||
.stdout("test\nhello world\n")
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
@ -1315,7 +1315,7 @@ fn can_print_file_starting_with_cache() {
|
||||
.arg("cache.c")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(" 1 test\n")
|
||||
.stdout("test\n")
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
@ -2666,3 +2666,16 @@ fn highlighting_independant_from_map_syntax_case() {
|
||||
.stdout(expected)
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn piped_output_with_lines() {
|
||||
let expected = " 1 hello\n 2 world\n";
|
||||
|
||||
bat()
|
||||
.arg("-n")
|
||||
.write_stdin("hello\nworld\n")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(expected)
|
||||
.stderr("");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user