CAD97 / colored-diff

MIT License
17 stars 3 forks source link

Alternative font to highlight differences #2

Open sanmai-NL opened 6 years ago

sanmai-NL commented 6 years ago

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.

CAD97 commented 6 years ago

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.