on master help sign in
run cargo fmt
commit80da0dc6194d94dbbc87185283d4e299b8101dfd authorsharkdp <davidpeter@web.de> dateWed 26 Sep 2018, 19:16 (8 years ago) parent64903bb
4 files changed+38−28
src/app.rs+27−21 src/printer.rs+2−1 src/style.rs+7−5 tests/tester.rs+2−1
src/app.rs+27−21
@@ -364,22 +364,24 @@ impl App {
364364 let paging_mode = match self.matches.value_of("paging") {
365365 Some("always") => PagingMode::Always,
366366 Some("never") => PagingMode::Never,
367− Some("auto") | _ => if files.contains(&InputFile::StdIn) {
368− // If we are reading from stdin, only enable paging if we write to an
369− // interactive terminal and if we do not *read* from an interactive
370− // terminal.
371− if self.interactive_output && !atty::is(Stream::Stdin) {
372− PagingMode::QuitIfOneScreen
373− } else {
374− PagingMode::Never
375− }
376− } else {
377− if self.interactive_output {
378− PagingMode::QuitIfOneScreen
367+ Some("auto") | _ => {
368+ if files.contains(&InputFile::StdIn) {
369+ // If we are reading from stdin, only enable paging if we write to an
370+ // interactive terminal and if we do not *read* from an interactive
371+ // terminal.
372+ if self.interactive_output && !atty::is(Stream::Stdin) {
373+ PagingMode::QuitIfOneScreen
374+ } else {
375+ PagingMode::Never
376+ }
379377 } else {
380− PagingMode::Never
378+ if self.interactive_output {
379+ PagingMode::QuitIfOneScreen
380+ } else {
381+ PagingMode::Never
382+ }
381383 }
382− },
384+ }
383385 };
384386
385387 Ok(Config {
@@ -393,11 +395,13 @@ impl App {
393395 match self.matches.value_of("wrap") {
394396 Some("character") => OutputWrap::Character,
395397 Some("never") => OutputWrap::None,
396− Some("auto") | _ => if output_components.plain() {
397− OutputWrap::None
398− } else {
399− OutputWrap::Character
400− },
398+ Some("auto") | _ => {
399+ if output_components.plain() {
400+ OutputWrap::None
401+ } else {
402+ OutputWrap::Character
403+ }
404+ }
401405 }
402406 },
403407 colored_output: match self.matches.value_of("color") {
@@ -450,8 +454,10 @@ impl App {
450454 } else {
451455 InputFile::Ordinary(filename)
452456 }
453− }).collect()
454− }).unwrap_or_else(|| vec![InputFile::StdIn])
457+ })
458+ .collect()
459+ })
460+ .unwrap_or_else(|| vec![InputFile::StdIn])
455461 }
456462
457463 fn output_components(&self) -> Result<OutputComponents> {
src/printer.rs+2−1
@@ -319,7 +319,8 @@ impl<'a> Printer for InteractivePrinter<'a> {
319319 .iter()
320320 .map(|ref d| d
321321 .generate(line_number, true, self)
322− .text).collect::<Vec<String>>()
322+ .text)
323+ .collect::<Vec<String>>()
323324 .join(" ")
324325 ))
325326 } else {
src/style.rs+7−5
@@ -23,11 +23,13 @@ pub enum OutputWrap {
2323impl OutputComponent {
2424 pub fn components(&self, interactive_terminal: bool) -> &'static [OutputComponent] {
2525 match *self {
26− OutputComponent::Auto => if interactive_terminal {
27− OutputComponent::Full.components(interactive_terminal)
28− } else {
29− OutputComponent::Plain.components(interactive_terminal)
30− },
26+ OutputComponent::Auto => {
27+ if interactive_terminal {
28+ OutputComponent::Full.components(interactive_terminal)
29+ } else {
30+ OutputComponent::Plain.components(interactive_terminal)
31+ }
32+ }
3133 OutputComponent::Changes => &[OutputComponent::Changes],
3234 OutputComponent::Grid => &[OutputComponent::Grid],
3335 OutputComponent::Header => &[OutputComponent::Header],
tests/tester.rs+2−1
@@ -50,7 +50,8 @@ impl BatTester {
5050 &format!("--wrap={}", if wrap { "character" } else { "never" }),
5151 &format!("--tabs={}", tab_width),
5252 &format!("--style={}", style),
53− ]).output()
53+ ])
54+ .output()
5455 .expect("bat failed");
5556
5657 // have to do the replace because the filename in the header changes based on the current working directory