colored-diff icon indicating copy to clipboard operation
colored-diff copied to clipboard

Alternative font to highlight differences

Open sanmai-NL opened this issue 7 years ago • 1 comments

pretty-assertions presents differences between characters by also making differing characters boldface (1), whereas colored_diff::PrettyDifference changes the background color behind those characters (2). The former is more readable and its readability is far less dependent on terminal color scheme.

My proposal is to implement presentation 1 in colored_diff::PrettyDifference.

sanmai-NL avatar Oct 20 '18 18:10 sanmai-NL

Current styles:

https://github.com/CAD97/colored-diff/blob/42ba173859f3d011b5370d14ed2f893539aed112/src/lib.rs#L10-L21

pretty-assertions uses the following (extracted from https://github.com/colin-kiegel/rust-pretty-assertions/blob/965f11b5b56a03a9c7d2d4844b5afdfc8a956f03/src/format_changeset.rs):

fn red(s: &str) -> ANSIString {
    Colour::Red.paint(s)
}
fn on_red(s: &str) -> ANSIString {
    Colour::Red.on(Colour::Fixed(52)).bold().paint(s)
}
fn green(s: &str) -> ANSIString {
    Colour::Green.paint(s)
}
fn on_green(s: &str) -> ANSIString {
    Colour::Green.on(Colour::Fixed(22)).bold().paint(s)
}

I'm not sure what the reason is, but, in my IDE's embedded terminal, I get the following output:

White.on(Red)/White.on(Green): image Red.on(52)/Green.on(22): image

Thus why I likely chose this styling. For completeness, the difference example uses (the equivalent of) White.on(Green).

If I'm not mistaken, you're asking for the following styling, which is not what the current version of pretty-differences uses:

fn red(s: &str) -> ANSIGenericString<str> {
    Colour::Red.paint(s)
}
fn on_red(s: &str) -> ANSIGenericString<str> {
    Colour::Red.bold().paint(s)
}
fn green(s: &str) -> ANSIGenericString<str> {
    Colour::Green.paint(s)
}
fn on_green(s: &str) -> ANSIGenericString<str> {
    Colour::Green.bold().paint(s)
}

which looks like this in my IDE terminal: image

If ansi_term uses the coming minimal const fn support of Rust to make manipulating Colour/Style const, I'll probably add a generic parameter to specify a styling set for a difference. Until then, I'm not sure what much I can do different to work ideally on more terminals.

CAD97 avatar Oct 21 '18 01:10 CAD97