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

Use ansi color codes when rendering unified text diff #13

Open
skuzzle opened this issue Jan 10, 2022 · 2 comments
Open

Use ansi color codes when rendering unified text diff #13

skuzzle opened this issue Jan 10, 2022 · 2 comments
Labels
component: diff-tool enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@skuzzle
Copy link
Owner

skuzzle commented Jan 10, 2022

We could use ANSI color codes to improve dispaly of the unified diff in console windows

@skuzzle skuzzle added the enhancement New feature or request label Jan 10, 2022
@skuzzle
Copy link
Owner Author

skuzzle commented Feb 16, 2022

First test did not prove so effective.

  1. Most environments (CI, IDE) do not render the text colorized but render the control chars instead
  2. We'd need to decide on which environments ANSI code should be rendered and we'd need to determine on which environment we're running
  3. Even when colors are rendered in a console, the diff mostly looks shitty

Usage of

<dependency>
    <groupId>com.diogonunes</groupId>
    <artifactId>JColor</artifactId>
    <version>5.2.0</version>
</dependency>

Is as simple as:

    public String getDisplayDiff(Diff diff) {
        if (isFailureDifference(diff)) {
            switch (diff.operation) {
            case DELETE:
                return Ansi.colorize("-" + einklammern(diff.text), Attribute.BOLD(), Attribute.BLACK_TEXT(),
                        Attribute.YELLOW_BACK());
            case INSERT:
                return Ansi.colorize("+" + einklammern(diff.text), Attribute.BOLD(), Attribute.BLACK_TEXT(),
                        Attribute.YELLOW_BACK());
            default:
                throw new IllegalStateException();
            }
        } else {
            return diff.text;
        }
    }

@skuzzle skuzzle added the help wanted Extra attention is needed label Feb 16, 2022
@skuzzle
Copy link
Owner Author

skuzzle commented Apr 28, 2023

Coming back to this after a while, this might still be a nice feature to have. Now that diff creation and rendering has been extracted into its own module we could provide some configuration options for colorized diff rendering

@skuzzle skuzzle added this to the 2.0.0 milestone Apr 28, 2023
@skuzzle skuzzle modified the milestones: 2.0.0, 2.1.0 Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: diff-tool enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant