mirror of
https://github.com/RGBCube/serenity
synced 2025-05-29 13:25:10 +00:00
diff: Only color output when stdout is a tty
If we're redirecting the output somewhere, we likely don't want to have ANSI codes in the middle of our diff output.
This commit is contained in:
parent
6f423ed26e
commit
07419b8931
1 changed files with 14 additions and 4 deletions
|
@ -61,13 +61,23 @@ int main(int argc, char** argv)
|
||||||
if (num_added > 1)
|
if (num_added > 1)
|
||||||
sb.appendff(",{}", target_start + num_added - 1);
|
sb.appendff(",{}", target_start + num_added - 1);
|
||||||
|
|
||||||
|
bool color_output = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
outln("Hunk: {}", sb.build());
|
outln("Hunk: {}", sb.build());
|
||||||
for (const auto& line : hunk.removed_lines)
|
for (const auto& line : hunk.removed_lines) {
|
||||||
|
if (color_output)
|
||||||
outln("\033[31;1m< {}\033[0m", line);
|
outln("\033[31;1m< {}\033[0m", line);
|
||||||
|
else
|
||||||
|
outln("< {}", line);
|
||||||
|
}
|
||||||
if (num_added > 0 && num_removed > 0)
|
if (num_added > 0 && num_removed > 0)
|
||||||
outln("---");
|
outln("---");
|
||||||
for (const auto& line : hunk.added_lines)
|
for (const auto& line : hunk.added_lines) {
|
||||||
|
if (color_output)
|
||||||
outln("\033[32;1m> {}\033[0m", line);
|
outln("\033[32;1m> {}\033[0m", line);
|
||||||
|
else
|
||||||
|
outln("> {}", line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return hunks.is_empty() ? 0 : 1;
|
return hunks.is_empty() ? 0 : 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue