-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
cliRelated to the command-line interfaceRelated to the command-line interfacegood first issueGood for newcomersGood for newcomershelp wantedContributions especially welcomeContributions especially welcome
Description
Discussed in #9983
We should colorize the diff output (added and removed lines).
The relevant code is in
ruff/crates/ruff_linter/src/source_kind.rs
Lines 103 to 111 in a7d1f7e
unified_diff.header(&fs::relativize_path(path), &fs::relativize_path(path)); | |
} | |
unified_diff.to_writer(&mut *writer)?; | |
writer.write_all(b"\n")?; | |
writer.flush()?; | |
Ok(()) |
We probably would need to extract the to_writer
function and change it so that we set the right color depending on if it's an addition or deletion:
let mut header = self.header.as_ref();
for hunk in self.iter_hunks() {
if let Some((old_file, new_file)) = header.take() {
writeln!(w, "--- {}", old_file)?; // <-- add color here
writeln!(w, "+++ {}", new_file)?;
}
write!(w, "{}", hunk)?;
}
Ok(())
Originally posted by ssenior45 February 14, 2024
If I run ruff check
on a file then the output is colored which leads me to believe that my terminal is configured to display colored output from the tool correctly.
However when I run ruff format --diff
the output is not colored. Is this expected? If so is there anything that can be done about it?
Thanks in advance.
Metadata
Metadata
Assignees
Labels
cliRelated to the command-line interfaceRelated to the command-line interfacegood first issueGood for newcomersGood for newcomershelp wantedContributions especially welcomeContributions especially welcome