@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); } }
@Override public void printBanner(Environment environment, Class<?> sourceClass, PrintStream printStream) { for (String line : BANNER) { printStream.println(line); } String version = SpringBootVersion.getVersion(); version = (version == null ? "" : " (v" + version + ")"); String padding = ""; while (padding.length() < STRAP_LINE_SIZE - (version.length() + SPRING_BOOT.length())) { padding += " "; } printStream.println(AnsiOutput.toString(AnsiColor.GREEN, SPRING_BOOT, AnsiColor.DEFAULT, padding, AnsiStyle.FAINT, version)); printStream.println(); }
@Override public String getPrompt() { return AbstractShell.shellPrompt = AnsiOutput.toString(AnsiColor.CYAN, "hdfs-shell ") + AnsiOutput.toString(AnsiColor.YELLOW, contextCommands.getCurrentDir()) + AnsiOutput.toString(AnsiColor.CYAN, " >", AnsiColor.WHITE); }
@Test public void statusWhenStarted() throws Exception { String output = doTest("status-when-started.sh"); assertThat(output).contains("Status: 0"); assertThat(output).has( coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]")); }
@Test public void statusWhenKilled() throws Exception { String output = doTest("status-when-killed.sh"); assertThat(output).contains("Status: 1"); assertThat(output).has(coloredString(AnsiColor.RED, "Not running (process " + extractPid(output) + " not found)")); }
@Test public void stopWhenStopped() throws Exception { String output = doTest("stop-when-stopped.sh"); assertThat(output).contains("Status: 0"); assertThat(output) .has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)")); }
@Test public void startWhenStarted() throws Exception { String output = doTest("start-when-started.sh"); assertThat(output).contains("Status: 0"); assertThat(output).has(coloredString(AnsiColor.YELLOW, "Already running [" + extractPid(output) + "]")); }
@Test public void restartWhenStopped() throws Exception { String output = doTest("restart-when-stopped.sh"); assertThat(output).contains("Status: 0"); assertThat(output) .has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)")); assertThat(output).has( coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]")); }
@Test public void restartWhenStarted() throws Exception { String output = doTest("restart-when-started.sh"); assertThat(output).contains("Status: 0"); assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extract("PID1", output) + "]")); assertThat(output).has(coloredString(AnsiColor.GREEN, "Stopped [" + extract("PID1", output) + "]")); assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extract("PID2", output) + "]")); }
@Test public void startWhenStopped() throws Exception { String output = doTest("start-when-stopped.sh"); assertThat(output).contains("Status: 0"); assertThat(output).has( coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]")); }
private Condition<String> coloredString(AnsiColor color, String string) { String colorString = ESC + "[0;" + color + "m" + string + ESC + "[0m"; return new Condition<String>() { @Override public boolean matches(String value) { return containsString(colorString).matches(value); } }; }
@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); }
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(); }
@Test public void printBannerShouldResetForegroundAndBackground() { String banner = printBanner("black-and-white.gif"); String expected = AnsiOutput.encode(AnsiColor.DEFAULT) + AnsiOutput.encode(AnsiBackground.DEFAULT); assertThat(banner).startsWith(expected); }
@Test public void printBannerWhenInvertedShouldResetForegroundAndBackground() { String banner = printBanner("black-and-white.gif", INVERT_TRUE); String expected = AnsiOutput.encode(AnsiColor.DEFAULT) + AnsiOutput.encode(AnsiBackground.BLACK); assertThat(banner).startsWith(expected); }
@Test public void printBannerShouldPrintWhiteAsBrightWhiteHighLuminance() { String banner = printBanner("black-and-white.gif"); String expected = AnsiOutput.encode(AnsiColor.BRIGHT_WHITE) + HIGH_LUMINANCE_CHARACTER; assertThat(banner).contains(expected); }
@Test public void printBannerWhenInvertedShouldPrintWhiteAsBrightWhiteLowLuminance() { String banner = printBanner("black-and-white.gif", INVERT_TRUE); String expected = AnsiOutput.encode(AnsiColor.BRIGHT_WHITE) + LOW_LUMINANCE_CHARACTER; assertThat(banner).contains(expected); }
@Test public void printBannerWhenShouldPrintAllColors() { String banner = printBanner("colors.gif"); for (AnsiColor color : AnsiColor.values()) { if (color != AnsiColor.DEFAULT) { assertThat(banner).contains(AnsiOutput.encode(color)); } } }
@Override public void printBanner(Environment environment, Class<?> sourceClass, PrintStream printStream) { for (String line : BANNER) { printStream.println(line); } String version = SettingsUtil.getVersionString(); printStream.println(AnsiOutput.toString(AnsiColor.GREEN, AnsiStyle.FAINT, version)); printStream.println(); }
@Test public void statusWhenStopped() throws Exception { String output = doTest("status-when-stopped.sh"); assertThat(output).contains("Status: 3"); assertThat(output).has(coloredString(AnsiColor.RED, "Not running")); }