diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2018-04-20 14:02:44 +1200 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2018-04-20 14:02:44 +1200 |
| commit | 5194984812bf38d73094da36e1932f503958effc (patch) | |
| tree | d4f4eb8ba082a15e367d72b737385fa9c80c3bea /src/rustfmt_diff.rs | |
| parent | 7a886e8fe5f3551b9614c8131709267256eaa229 (diff) | |
Add a verbose-diff option
And don't print end of line characters by default in diffs cc #2536
Diffstat (limited to 'src/rustfmt_diff.rs')
| -rw-r--r-- | src/rustfmt_diff.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/rustfmt_diff.rs b/src/rustfmt_diff.rs index d5c97b95560..426f7da96a2 100644 --- a/src/rustfmt_diff.rs +++ b/src/rustfmt_diff.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use config::Color; +use config::{Color, Config}; use diff; use std::collections::VecDeque; use std::io; @@ -149,10 +149,13 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma results } -pub fn print_diff<F>(diff: Vec<Mismatch>, get_section_title: F, color: Color) +pub fn print_diff<F>(diff: Vec<Mismatch>, get_section_title: F, config: &Config) where F: Fn(u32) -> String, { + let color = config.color(); + let line_terminator = if config.verbose_diff() { "⏎" } else { "" }; + let mut writer = OutputWriter::new(color); for mismatch in diff { @@ -161,13 +164,17 @@ where for line in mismatch.lines { match line { - DiffLine::Context(ref str) => writer.writeln(&format!(" {}⏎", str), None), - DiffLine::Expected(ref str) => { - writer.writeln(&format!("+{}⏎", str), Some(term::color::GREEN)) - } - DiffLine::Resulting(ref str) => { - writer.writeln(&format!("-{}⏎", str), Some(term::color::RED)) + DiffLine::Context(ref str) => { + writer.writeln(&format!(" {}{}", str, line_terminator), None) } + DiffLine::Expected(ref str) => writer.writeln( + &format!("+{}{}", str, line_terminator), + Some(term::color::GREEN), + ), + DiffLine::Resulting(ref str) => writer.writeln( + &format!("-{}{}", str, line_terminator), + Some(term::color::RED), + ), } } } |
