use of org.springframework.boot.ansi.AnsiElement in project spring-boot by spring-projects.
the class ColorConverter method format.
@Override
public void format(LogEvent event, StringBuilder toAppendTo) {
StringBuilder buf = new StringBuilder();
for (PatternFormatter formatter : this.formatters) {
formatter.format(event, buf);
}
if (buf.length() > 0) {
AnsiElement element = this.styling;
if (element == null) {
// Assume highlighting
element = LEVELS.get(event.getLevel().intLevel());
element = (element == null ? AnsiColor.GREEN : element);
}
appendAnsiString(toAppendTo, buf.toString(), element);
}
}
use of org.springframework.boot.ansi.AnsiElement in project spring-boot by spring-projects.
the class ColorConverter method newInstance.
/**
* Creates a new instance of the class. Required by Log4J2.
* @param config the configuration
* @param options the options
* @return a new instance, or {@code null} if the options are invalid
*/
public static ColorConverter newInstance(Configuration config, String[] options) {
if (options.length < 1) {
LOGGER.error("Incorrect number of options on style. " + "Expected at least 1, received {}", options.length);
return null;
}
if (options[0] == null) {
LOGGER.error("No pattern supplied on style");
return null;
}
PatternParser parser = PatternLayout.createPatternParser(config);
List<PatternFormatter> formatters = parser.parse(options[0]);
AnsiElement element = (options.length == 1 ? null : ELEMENTS.get(options[1]));
return new ColorConverter(formatters, element);
}
use of org.springframework.boot.ansi.AnsiElement in project spring-boot by spring-projects.
the class ColorConverter method transform.
@Override
protected String transform(ILoggingEvent event, String in) {
AnsiElement element = ELEMENTS.get(getFirstOption());
if (element == null) {
// Assume highlighting
element = LEVELS.get(event.getLevel().toInteger());
element = (element == null ? AnsiColor.GREEN : element);
}
return toAnsiString(in, element);
}
use of org.springframework.boot.ansi.AnsiElement in project spring-boot by spring-projects.
the class ImageBanner method printBanner.
private void printBanner(BufferedImage image, int margin, boolean invert, PrintStream out) {
AnsiElement background = (invert ? AnsiBackground.BLACK : AnsiBackground.DEFAULT);
out.print(AnsiOutput.encode(AnsiColor.DEFAULT));
out.print(AnsiOutput.encode(background));
out.println();
out.println();
AnsiColor lastColor = AnsiColor.DEFAULT;
for (int y = 0; y < image.getHeight(); y++) {
for (int i = 0; i < margin; i++) {
out.print(" ");
}
for (int x = 0; x < image.getWidth(); x++) {
Color color = new Color(image.getRGB(x, y), false);
AnsiColor ansiColor = AnsiColors.getClosest(color);
if (ansiColor != lastColor) {
out.print(AnsiOutput.encode(ansiColor));
lastColor = ansiColor;
}
out.print(getAsciiPixel(color, invert));
}
out.println();
}
out.print(AnsiOutput.encode(AnsiColor.DEFAULT));
out.print(AnsiOutput.encode(AnsiBackground.DEFAULT));
out.println();
}
Aggregations