Java Code Examples for org.fusesource.jansi.Ansi#Color

The following examples show how to use org.fusesource.jansi.Ansi#Color . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultColorMap.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Color createColor(String style) {
    String colorSpec = System.getProperty(String.format("org.gradle.color.%s", style), defaults.get(style));

    if (colorSpec != null) {
        if (colorSpec.equalsIgnoreCase(BOLD)) {
            return new AttributeColor(INTENSITY_BOLD, INTENSITY_BOLD_OFF);
        }
        if (colorSpec.equalsIgnoreCase("reverse")) {
            return new AttributeColor(NEGATIVE_ON, NEGATIVE_OFF);
        }
        if (colorSpec.equalsIgnoreCase("italic")) {
            return new AttributeColor(ITALIC, ITALIC_OFF);
        }

        Ansi.Color ansiColor = Ansi.Color.valueOf(colorSpec.toUpperCase());
        if (ansiColor != DEFAULT) {
            return new ForegroundColor(ansiColor);
        }
    }

    return noDecoration;
}
 
Example 2
Source File: DefaultColorMap.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Color createColor(String style) {
    String colorSpec = System.getProperty(String.format("org.gradle.color.%s", style), defaults.get(style));

    if (colorSpec != null) {
        if (colorSpec.equalsIgnoreCase(BOLD)) {
            return new AttributeColor(INTENSITY_BOLD, INTENSITY_BOLD_OFF);
        }
        if (colorSpec.equalsIgnoreCase("reverse")) {
            return new AttributeColor(NEGATIVE_ON, NEGATIVE_OFF);
        }
        if (colorSpec.equalsIgnoreCase("italic")) {
            return new AttributeColor(ITALIC, ITALIC_OFF);
        }

        Ansi.Color ansiColor = Ansi.Color.valueOf(colorSpec.toUpperCase());
        if (ansiColor != DEFAULT) {
            return new ForegroundColor(ansiColor);
        }
    }

    return noDecoration;
}
 
Example 3
Source File: Application.java    From ig-webapi-java-sample with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void logMessage(int x, int y, String message, Ansi.Color fgColor, Ansi.Color bgColor, Ansi.Attribute... attributes) {
   message = message.substring(0, Math.min(message.length(), 120));
   Ansi ansi = ansi().cursor(y, x).eraseLine();
   if(attributes != null) {
      for (Ansi.Attribute attribute : attributes) {
         ansi = ansi.a(attribute);
      }
   }
   ansi = ansi.fg(fgColor != null ? fgColor : Ansi.Color.DEFAULT);
   ansi = ansi.bg(bgColor != null ? bgColor : Ansi.Color.DEFAULT);
   System.out.println(ansi.a(message).reset());
}
 
Example 4
Source File: ColorFormatter.java    From tomee with Apache License 2.0 5 votes vote down vote up
private Ansi.Color color(final String lvl, final String aDefault) {
    try {
        return Ansi.Color.valueOf(SystemInstance.get().getProperty(OPENEJB_LOG_COLOR_PREFIX + lvl, aDefault));
    } catch (final IllegalArgumentException iae) {
        return Ansi.Color.valueOf(aDefault);
    }
}
 
Example 5
Source File: LogOutputSpec.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Builder(toBuilder = true)
private LogOutputSpec(
    String prefix, Ansi.Color color, boolean fgBright, DateTimeFormatter timeFormatter, String file,
    boolean useColor, boolean logStdout) {

    this.prefix = prefix;
    this.color = color;
    this.fgBright = fgBright;
    this.timeFormatter = timeFormatter;
    this.file = file;
    this.useColor = useColor;
    this.logStdout = logStdout;
}
 
Example 6
Source File: AnsiLogger.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private String evaluateEmphasis(String message, Ansi.Color msgColor) {
    // Split but keep the content by splitting on [[ and ]] separately when they
    // are followed or preceded by their counterpart. This lets the split retain
    // the character in the center.
    String[] parts = message.split("(\\[\\[(?=.]])|(?<=\\[\\[.)]])");
    if (parts.length == 1) {
        return message;
    }
    // The split up string is comprised of a leading plain part, followed
    // by groups of colorization that are <SET> color-part <RESET> plain-part.
    // To avoid emitting needless color changes, we skip the set or reset
    // if the subsequent part is empty.
    String msgColorS = ansi().fg(msgColor).toString();
    StringBuilder ret = new StringBuilder(parts[0]);

    for (int i = 1; i < parts.length; i += 4) {
        boolean colorPart = i + 1 < parts.length && parts[i + 1].length() > 0;
        boolean plainPart = i + 3 < parts.length && parts[i + 3].length() > 0;

        if (colorPart) {
            ret.append(getEmphasisColor(parts[i]));
            ret.append(parts[i + 1]);
            if(plainPart) {
                ret.append(msgColorS);
            }
        }
        if (plainPart) {
            ret.append(parts[i + 3]);
        }
    }
    return ret.toString();
}
 
Example 7
Source File: AnsiLogger.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private String getEmphasisColor(String id) {
    Ansi.Color color = COLOR_MAP.get(id.toUpperCase());
    if (color != null) {
        return id.equals(id.toLowerCase()) ?
                // lower case letter means bright color ...
                ansi().fgBright(color).toString() :
                ansi().fg(color).toString();
    } else {
        return "";
    }
}
 
Example 8
Source File: Application.java    From ig-webapi-java-sample with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void drawChartBar(double value, Ansi.Color color) {
   if(value <= 0) {
      return;
   }
   int maxHeight = 40;
   int maxWidth = 120;
   int yLow = 47;
   int yHigh = yLow - maxHeight;
   int x = (int) (currentTime - initialTime + 1);
   if(x > maxWidth) {
      initialTime = currentTime;
      System.out.println(ansi().eraseScreen().reset());
   }

   double dHighLow = marketHigh - marketLow;
   int lines = (int) Math.round (maxHeight / dHighLow * (value - marketLow));
   System.out.println(ansi().cursor(yLow + 1, x).eraseLine().a("-").reset());
   System.out.println(ansi().cursor(yHigh - 1, x).eraseLine().a("-").reset());
   for(int y=yLow,count=lines; count > 0; y--, count--) {
      System.out.println(ansi().cursor(y, x).eraseLine().bg(color).a(" ").reset());
   }
   System.out.println(ansi().cursor(yLow - lines + 1, x + 1).eraseLine().a(marketOffer).reset());
   for(int y=yLow - lines; y >= yHigh; y--) {
      System.out.println(ansi().cursor(y, x).eraseLine().reset());
   }
   System.out.println(ansi().cursor(yLow + 1, x + 1).eraseLine().a(marketLow + " (low)").reset());
   System.out.println(ansi().cursor(yHigh - 1, x + 1).eraseLine().a(marketHigh + " (high)").reset());
}
 
Example 9
Source File: AnsiLogger.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
private String getEmphasisColor(String id) {
    Ansi.Color color = COLOR_MAP.get(id.toUpperCase());
    if (color != null) {
        return id.toLowerCase().equals(id) ?
            // lower case letter means bright color ...
            ansi().fgBright(color).toString() :
            ansi().fg(color).toString();
    } else {
        return "";
    }
}
 
Example 10
Source File: Configuration.java    From updatebot with Apache License 2.0 5 votes vote down vote up
public String colored(Ansi.Color color, String message) {
    if (!useAnsiColor()) {
        return message;
    }
    Ansi ansi = ansi().fg(color);
    return ansi.a(message).reset().toString();
}
 
Example 11
Source File: AnsiLogger.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
private String evaluateEmphasis(String message, Ansi.Color msgColor) {
    // Split but keep the content by splitting on [[ and ]] separately when they
    // are followed or preceded by their counterpart. This lets the split retain
    // the character in the center.
    String[] parts = message.split("(\\[\\[(?=.]])|(?<=\\[\\[.)]])");
    if (parts.length == 1) {
        return message;
    }
    // The split up string is comprised of a leading plain part, followed
    // by groups of colorization that are <SET> color-part <RESET> plain-part.
    // To avoid emitting needless color changes, we skip the set or reset
    // if the subsequent part is empty.
    String msgColorS = ansi().fg(msgColor).toString();
    StringBuilder ret = new StringBuilder(parts[0]);

    for (int i = 1; i < parts.length; i += 4) {
        boolean colorPart = i + 1 < parts.length && parts[i + 1].length() > 0;
        boolean plainPart = i + 3 < parts.length && parts[i + 3].length() > 0;

        if (colorPart) {
            ret.append(getEmphasisColor(parts[i]));
            ret.append(parts[i + 1]);
            if(plainPart) {
                ret.append(msgColorS);
            }
        }
        if (plainPart) {
            ret.append(parts[i + 3]);
        }
    }
    return ret.toString();
}
 
Example 12
Source File: LogOutputSpec.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
private LogOutputSpec(String prefix, Ansi.Color color, boolean fgBright, DateTimeFormatter timeFormatter, String file, boolean useColor, boolean logStdout) {
    this.prefix = prefix;
    this.color = color;
    this.fgBright = fgBright;
    this.timeFormatter = timeFormatter;
    this.file = file;
    this.useColor = useColor;
    this.logStdout = logStdout;
}
 
Example 13
Source File: CliUtil.java    From styx with Apache License 2.0 4 votes vote down vote up
static Ansi colored(Ansi.Color color, Object obj) {
  return ansi().fg(color).a(obj).reset();
}
 
Example 14
Source File: AnsiLoggerFacade.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
private String colored(String message, Ansi.Color color, boolean addPrefix, Object... params) {
    Ansi ansi = ansi().fg(color);
    String msgToPrint = addPrefix ? prefix + message : message;
    return ansi.a(format(evaluateEmphasis(msgToPrint, color), params)).reset().toString();
}
 
Example 15
Source File: DefaultColorMap.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ForegroundColor(Ansi.Color ansiColor) {
    this.ansiColor = ansiColor;
}
 
Example 16
Source File: AnsiLogger.java    From docker-maven-plugin with Apache License 2.0 4 votes vote down vote up
private String colored(String message, Ansi.Color color, boolean addPrefix, Object ... params) {
    Ansi ansi = ansi().fg(color);
    String msgToPrint = addPrefix ? prefix + message : message;
    return ansi.a(format(evaluateEmphasis(msgToPrint, color), params)).reset().toString();
}
 
Example 17
Source File: DewLog.java    From dew with Apache License 2.0 4 votes vote down vote up
private String ansi(String message, Ansi.Color color, Object... params) {
    return Ansi.ansi().fg(color).a(format(prefix + message, params)).reset().toString();
}
 
Example 18
Source File: DefaultColorMap.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ForegroundColor(Ansi.Color ansiColor) {
    this.ansiColor = ansiColor;
}
 
Example 19
Source File: MavenColorRenderer.java    From maven-color with MIT License 4 votes vote down vote up
private static String colorize(Event event, Ansi.Color color) {
    return ansi().fgBright(color).bold().a(event.getMessage()).reset().toString();
}
 
Example 20
Source File: AnsiLogger.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
private String colored(String message, Ansi.Color color, boolean addPrefix, Object ... params) {
    Ansi ansi = ansi().fg(color);
    String msgToPrint = addPrefix ? prefix + message : message;
    return ansi.a(format(evaluateEmphasis(msgToPrint, color), params)).reset().toString();
}