package ee.shy.core.diff;

import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.AnsiConsole;

import java.util.List;

public class Util {

    /**
     * This is necessary because Util class must not be initialized.
     */
    private Util () {}

    /**
     * Take lines as parameter and output them with colors.
     * Green color indicating additions.
     * Red color indicating removed lines.
     * @param diffLines unified diff lines
     */
    public static void outputDiff(List<String> diffLines) {
        AnsiConsole.systemInstall();
        for (String row : diffLines) {
            if (row.length() >= 1) {
                switch (row.charAt(0)) {
                    case '@':
                        System.out.println(Ansi.ansi().fg(Ansi.Color.CYAN).a(row).reset());
                        break;
                    case '+':
                        System.out.println(Ansi.ansi().fg(Ansi.Color.GREEN).a(row).reset());
                        break;
                    case '-':
                        System.out.println(Ansi.ansi().fg(Ansi.Color.RED).a(row).reset());
                        break;
                    default:
                        System.out.println(row);
                        break;
                }
            } else {
                // TODO: 13.04.16 Refactor this
                System.out.println(row);
            }
        }
        AnsiConsole.systemUninstall();
    }
}

@@ -117,34 +117,450 @@
 til.
-List;%0A%0Apublic class Util %7B
+HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Apublic class Util %7B%0A    /**%0A     * Map containing character and its corresponding color.%0A     */%0A    private static final Map%3CCharacter, Ansi.Color%3E colors = new HashMap%3C%3E();%0A%0A    /**%0A     * Initialize colors map when class is loaded.%0A     */%0A    static %7B%0A        colors.put('@', Ansi.Color.CYAN);%0A        colors.put('+', Ansi.Color.GREEN);%0A        colors.put('-', Ansi.Color.RED);%0A    %7D
 %0A%0A  
@@ -1025,724 +1025,177 @@
 if (
+!
 row.
-length() %3E= 1) %7B%0A                switch (row.charAt(0)) %7B%0A                    case '@':%0A                        System.out.println(Ansi.ansi().fg(Ansi.Color.CYAN).a(row).rese
+isEmpty() && colors.containsKey(row.charA
 t(
+0
 ))
-;%0A                        break;%0A                    case '+':%0A                        System.out.println(Ansi.ansi().fg(Ansi.Color.GREEN).a(row).reset());%0A                        break;%0A                    case '-':%0A                        System.out.println(Ansi.ansi().fg(Ansi.Color.RED).a(row).reset());%0A                        break;%0A                    default:%0A                        System.out.println(row);%0A                        break;%0A                %7D%0A            %7D else %7B%0A                // TODO: 13.04.16 Refactor this
+) %7B%0A                System.out.println(Ansi.ansi().fg(colors.get(row.charAt(0))).a(row).reset());%0A            %7D else %7B
 %0A   

Refactor Util#outputDiff to get colors from static field