diff options
author | Pig Fang <g-plane@hotmail.com> | 2020-09-18 09:48:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-17 21:48:08 -0400 |
commit | e4188f7dfb95ad16750874dd2cdd4a80b48b1ecc (patch) | |
tree | cf53dddea6037814b257f1590a8d89759228fe66 /cli | |
parent | d245ececb6c3eed9d6a01b877cfbbf7642454fc3 (diff) |
fix(cli/fmt): make fmt output more readable (#7534)
Diffstat (limited to 'cli')
-rw-r--r-- | cli/colors.rs | 6 | ||||
-rw-r--r-- | cli/diff.rs | 14 |
2 files changed, 13 insertions, 7 deletions
diff --git a/cli/colors.rs b/cli/colors.rs index a324d928d..3a1616d97 100644 --- a/cli/colors.rs +++ b/cli/colors.rs @@ -85,6 +85,12 @@ pub fn white_on_green(s: &str) -> impl fmt::Display { style(&s, style_spec) } +pub fn black_on_green(s: &str) -> impl fmt::Display { + let mut style_spec = ColorSpec::new(); + style_spec.set_bg(Some(Green)).set_fg(Some(Black)); + style(&s, style_spec) +} + pub fn yellow(s: &str) -> impl fmt::Display { let mut style_spec = ColorSpec::new(); style_spec.set_fg(Some(Yellow)); diff --git a/cli/diff.rs b/cli/diff.rs index 50ba7c633..7510ebfa9 100644 --- a/cli/diff.rs +++ b/cli/diff.rs @@ -14,7 +14,7 @@ fn fmt_add_text(x: &str) -> String { } fn fmt_add_text_highlight(x: &str) -> String { - format!("{}", colors::white_on_green(x)) + format!("{}", colors::black_on_green(x)) } fn fmt_rem() -> String { @@ -41,9 +41,9 @@ fn write_line_diff( for (i, s) in split { write!( diff, - "{:0width$}{} ", + "{:width$}{} ", *orig_line + i, - colors::gray("|"), + colors::gray(" |"), width = line_number_width )?; write!(diff, "{}", fmt_rem())?; @@ -55,9 +55,9 @@ fn write_line_diff( for (i, s) in split { write!( diff, - "{:0width$}{} ", + "{:width$}{} ", *edit_line + i, - colors::gray("|"), + colors::gray(" |"), width = line_number_width )?; write!(diff, "{}", fmt_add())?; @@ -160,13 +160,13 @@ fn test_diff() { colors::strip_ansi_codes( &diff(simple_console_log_unfmt, simple_console_log_fmt).unwrap() ), - "1| -console.log('Hello World')\n1| +console.log(\"Hello World\");\n" + "1 | -console.log('Hello World')\n1 | +console.log(\"Hello World\");\n" ); let line_number_unfmt = "\n\n\n\nconsole.log(\n'Hello World'\n)"; let line_number_fmt = "console.log(\n\"Hello World\"\n);"; assert_eq!( colors::strip_ansi_codes(&diff(line_number_unfmt, line_number_fmt).unwrap()), - "1| -\n2| -\n3| -\n4| -\n5| -console.log(\n1| +console.log(\n6| -'Hello World'\n2| +\"Hello World\"\n7| -)\n3| +);\n" + "1 | -\n2 | -\n3 | -\n4 | -\n5 | -console.log(\n1 | +console.log(\n6 | -'Hello World'\n2 | +\"Hello World\"\n7 | -)\n3 | +);\n" ) } |