Skip to content

Commit

Permalink
Print forma diff to stdout (#1506)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jan 13, 2023
1 parent 3bf3be9 commit d15497e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,12 @@ impl Subcommand {
for op in diff.ops() {
for change in diff.iter_changes(op) {
let (symbol, color) = match change.tag() {
ChangeTag::Delete => ("-", config.color.stderr().diff_deleted()),
ChangeTag::Equal => (" ", config.color.stderr()),
ChangeTag::Insert => ("+", config.color.stderr().diff_added()),
ChangeTag::Delete => ("-", config.color.stdout().diff_deleted()),
ChangeTag::Equal => (" ", config.color.stdout()),
ChangeTag::Insert => ("+", config.color.stdout().diff_added()),
};

eprint!("{}{symbol}{change}{}", color.prefix(), color.suffix());
print!("{}{symbol}{change}{}", color.prefix(), color.suffix());
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions tests/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ test! {
name: check_found_diff,
justfile: "x:=``\n",
args: ("--unstable", "--fmt", "--check"),
stderr: "
stdout: "
-x:=``
+x := ``
",
stderr: "
error: Formatted justfile differs from original.
",
status: EXIT_FAILURE,
Expand All @@ -65,10 +67,12 @@ test! {
name: check_diff_color,
justfile: "x:=``\n",
args: ("--unstable", "--fmt", "--check", "--color", "always"),
stderr: "
stdout: "
\u{1b}[31m-x:=``
\u{1b}[0m\u{1b}[32m+x := ``
\u{1b}[0m\u{1b}[1;31merror\u{1b}[0m: \u{1b}[1mFormatted justfile differs from original.\u{1b}[0m
\u{1b}[0m",
stderr: "
\u{1b}[1;31merror\u{1b}[0m: \u{1b}[1mFormatted justfile differs from original.\u{1b}[0m
",
status: EXIT_FAILURE,
}
Expand Down

0 comments on commit d15497e

Please sign in to comment.