ruff
ruff copied to clipboard
Colorize `format --diff` output
Discussed in https://github.com/astral-sh/ruff/discussions/9983
We should colorize the diff output (added and removed lines).
The relevant code is in https://github.com/astral-sh/ruff/blob/a7d1f7e1ec6d2d4443eaec4bee5faebd97f95c66/crates/ruff_linter/src/source_kind.rs#L103-L111
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.
Def a good first issue!
Hey @MichaReiser, I'm interested on working on this
Edit: But I've also noticed you tagged OP in the original discussion
@senadev42 nice. I think the original OP doesn't mind if the feature gets implemented by someone else. I assign the issue to you. Let me know if you need any help.
Note: We use https://docs.rs/colored/latest/colored/ for colonizing the CLI output.
Just catching up with this now. Thanks for moving it to an issue. I would like to see this implemented and am more than happy for @senadev42 to work on it.
@senadev42 is there something I can help you with or would you prefer if someone else takes a look at it?
@MichaReiser Oh I've just been unexpectedly busy lately but I'm picking away at it, just kind of slowly since I assumed it wasn't an urgent/critical task.
I can let go if it is though, since I'm using this as an opportunity to dip my toes into rust.
@senadev42 it's not urgent. I just wanted to make sure you've all you need :)
Hey @MichaReiser
So I've made a draft PR at #10110 and I'd like some help interpreting why and how some of the tests are failing
Closed by https://github.com/astral-sh/ruff/pull/10110