on master help sign in
run cargo fmt
80da0dcsharkdp
src/app.rs+27−21
@@ -364,22 +364,24 @@ impl App {
364 let paging_mode = match self.matches.value_of("paging") {
364 let paging_mode = match self.matches.value_of("paging") {
365 Some("always") => PagingMode::Always,
365 Some("always") => PagingMode::Always,
366 Some("never") => PagingMode::Never,
366 Some("never") => PagingMode::Never,
367+ Some("auto") | _ => {
367− Some("auto") | _ => if files.contains(&InputFile::StdIn) {
368+ if files.contains(&InputFile::StdIn) {
368− // If we are reading from stdin, only enable paging if we write to an
369+ // 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+ // interactive terminal and if we do not *read* from an interactive
370− // terminal.
371+ // terminal.
371− if self.interactive_output && !atty::is(Stream::Stdin) {
372+ if self.interactive_output && !atty::is(Stream::Stdin) {
372− PagingMode::QuitIfOneScreen
373+ PagingMode::QuitIfOneScreen
373− } else {
374+ } else {
374− PagingMode::Never
375+ PagingMode::Never
375− }
376+ }
376− } else {
377− if self.interactive_output {
378− PagingMode::QuitIfOneScreen
379 } else {
377 } else {
378+ if self.interactive_output {
379+ PagingMode::QuitIfOneScreen
380+ } else {
380− PagingMode::Never
381+ PagingMode::Never
382+ }
381 }
383 }
382− },
384+ }
383 };
385 };
384
386
385 Ok(Config {
387 Ok(Config {
@@ -393,11 +395,13 @@ impl App {
393 match self.matches.value_of("wrap") {
395 match self.matches.value_of("wrap") {
394 Some("character") => OutputWrap::Character,
396 Some("character") => OutputWrap::Character,
395 Some("never") => OutputWrap::None,
397 Some("never") => OutputWrap::None,
398+ Some("auto") | _ => {
396− Some("auto") | _ => if output_components.plain() {
399+ if output_components.plain() {
397− OutputWrap::None
400+ OutputWrap::None
398− } else {
401+ } else {
399− OutputWrap::Character
402+ OutputWrap::Character
403+ }
400− },
404+ }
401 }
405 }
402 },
406 },
403 colored_output: match self.matches.value_of("color") {
407 colored_output: match self.matches.value_of("color") {
@@ -450,8 +454,10 @@ impl App {
450 } else {
454 } else {
451 InputFile::Ordinary(filename)
455 InputFile::Ordinary(filename)
452 }
456 }
457+ })
453− }).collect()
458+ .collect()
459+ })
454− }).unwrap_or_else(|| vec![InputFile::StdIn])
460+ .unwrap_or_else(|| vec![InputFile::StdIn])
455 }
461 }
456
462
457 fn output_components(&self) -> Result<OutputComponents> {
463 fn output_components(&self) -> Result<OutputComponents> {
src/printer.rs+2−1
@@ -319,7 +319,8 @@ impl<'a> Printer for InteractivePrinter<'a> {
319 .iter()
319 .iter()
320 .map(|ref d| d
320 .map(|ref d| d
321 .generate(line_number, true, self)
321 .generate(line_number, true, self)
322+ .text)
322− .text).collect::<Vec<String>>()
323+ .collect::<Vec<String>>()
323 .join(" ")
324 .join(" ")
324 ))
325 ))
325 } else {
326 } else {
src/style.rs+7−5
@@ -23,11 +23,13 @@ pub enum OutputWrap {
23impl OutputComponent {
23impl OutputComponent {
24 pub fn components(&self, interactive_terminal: bool) -> &'static [OutputComponent] {
24 pub fn components(&self, interactive_terminal: bool) -> &'static [OutputComponent] {
25 match *self {
25 match *self {
26+ OutputComponent::Auto => {
26− OutputComponent::Auto => if interactive_terminal {
27+ if interactive_terminal {
27− OutputComponent::Full.components(interactive_terminal)
28+ OutputComponent::Full.components(interactive_terminal)
28− } else {
29+ } else {
29− OutputComponent::Plain.components(interactive_terminal)
30+ OutputComponent::Plain.components(interactive_terminal)
31+ }
30− },
32+ }
31 OutputComponent::Changes => &[OutputComponent::Changes],
33 OutputComponent::Changes => &[OutputComponent::Changes],
32 OutputComponent::Grid => &[OutputComponent::Grid],
34 OutputComponent::Grid => &[OutputComponent::Grid],
33 OutputComponent::Header => &[OutputComponent::Header],
35 OutputComponent::Header => &[OutputComponent::Header],
tests/tester.rs+2−1
@@ -50,7 +50,8 @@ impl BatTester {
50 &format!("--wrap={}", if wrap { "character" } else { "never" }),
50 &format!("--wrap={}", if wrap { "character" } else { "never" }),
51 &format!("--tabs={}", tab_width),
51 &format!("--tabs={}", tab_width),
52 &format!("--style={}", style),
52 &format!("--style={}", style),
53+ ])
53− ]).output()
54+ .output()
54 .expect("bat failed");
55 .expect("bat failed");
55
56
56 // have to do the replace because the filename in the header changes based on the current working directory
57 // have to do the replace because the filename in the header changes based on the current working directory