Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative font to highlight differences #2

Open
sanmai-NL opened this issue Oct 20, 2018 · 1 comment
Open

Alternative font to highlight differences #2

sanmai-NL opened this issue Oct 20, 2018 · 1 comment

Comments

@sanmai-NL
Copy link

sanmai-NL commented Oct 20, 2018

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
Copy link
Owner

CAD97 commented Oct 21, 2018

Current styles:

colored-diff/src/lib.rs

Lines 10 to 21 in 42ba173

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants