@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 void printBanner(Environment environment, Class<?> sourceClass, PrintStream printStream) { for (String line : BANNER) { printStream.println(line); } String version = FountainBanner.class.getPackage().getImplementationVersion(); version = (version == null ? "" : " (v" + version + ")"); String padding = ""; while (padding.length() < STRAP_LINE_SIZE - (version.length() + FOUNTAIN.length())) { padding += " "; } printStream.println(AnsiOutput.toString(GREEN, FOUNTAIN, DEFAULT, padding, 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); }
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( event.getEnvironment(), "spring.output.ansi."); if (resolver.containsProperty("enabled")) { String enabled = resolver.getProperty("enabled"); AnsiOutput.setEnabled(Enum.valueOf(Enabled.class, enabled.toUpperCase())); } if (resolver.containsProperty("console-available")) { AnsiOutput.setConsoleAvailable( resolver.getProperty("console-available", Boolean.class)); } }
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)); } } }
@Test public void printBannerShouldRenderGradient() throws Exception { AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); String banner = printBanner("gradient.gif", "banner.image.width=10", "banner.image.margin=0"); assertThat(banner).contains("@#8&o:*. "); }
@Test public void printBannerShouldCapWidthAndCalculateHeight() throws Exception { AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); String banner = printBanner("large.gif", "banner.image.margin=0"); assertThat(getBannerWidth(banner)).isEqualTo(76); assertThat(getBannerHeight(banner)).isEqualTo(37); }
@Test public void printBannerShouldPrintMargin() throws Exception { AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); String banner = printBanner("large.gif"); String[] lines = banner.split(NEW_LINE); for (int i = 2; i < lines.length - 1; i++) { assertThat(lines[i]).startsWith(" @"); } }
@Test public void printBannerWhenHasMarginPropertyShouldPrintSizedMargin() throws Exception { AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); String banner = printBanner("large.gif", "banner.image.margin=4"); String[] lines = banner.split(NEW_LINE); for (int i = 2; i < lines.length - 1; i++) { assertThat(lines[i]).startsWith(" @"); } }
@Test public void renderWithColors() throws Exception { Resource resource = new ByteArrayResource( "${Ansi.RED}This is red.${Ansi.NORMAL}".getBytes()); AnsiOutput.setEnabled(AnsiOutput.Enabled.ALWAYS); String banner = printBanner(resource, null, null, null); assertThat(banner).startsWith("\u001B[31mThis is red.\u001B[0m"); }
@Test public void renderWithColorsButDisabled() throws Exception { Resource resource = new ByteArrayResource( "${Ansi.RED}This is red.${Ansi.NORMAL}".getBytes()); AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); String banner = printBanner(resource, null, null, null); assertThat(banner).startsWith("This is red."); }
protected void captureOutput() { AnsiOutput.setEnabled(Enabled.NEVER); this.copy = new ByteArrayOutputStream(); this.captureOut = new CaptureOutputStream(System.out, this.copy); this.captureErr = new CaptureOutputStream(System.err, this.copy); System.setOut(new PrintStream(this.captureOut)); System.setErr(new PrintStream(this.captureErr)); }
@Override public void onApplicationEvent(ContextRefreshedEvent event) { serviceQueueRegistry.getItems().forEach(item -> { final ServiceQueue serviceQueue = applicationContext.getBean(item.getKey(), ServiceQueue.class); if (clusteredEventManager != null && (boolean) item.getValue().get("remoteEventListener")) { clusteredEventManager.joinService(serviceQueue); } if (serviceEndpointServer != null && (boolean) item.getValue().get("exposeRemoteEndpoint")) { final String endpointLocation = (String) item.getValue().get("endpointLocation"); logger.info(AnsiOutput.toString("Registering endpoint: ", BOLD, GREEN, endpointLocation, NORMAL)); serviceEndpointServer.addServiceQueue(endpointLocation, serviceQueue); logger.info("Starting service queue as part of endpoint {}", serviceQueue.name()); serviceQueue.startServiceQueue(); } else { logger.info("Starting service queue standalone {}", serviceQueue.name()); serviceQueue.start(); serviceQueue.startCallBackHandler(); } }); if (serviceEndpointServer != null) { serviceEndpointServer.start(); } applicationContext.publishEvent(new QBitStartedEvent(applicationContext)); }
@Test public void renderWithColors() throws Exception { Resource resource = new ByteArrayResource( "${Ansi.RED}This is red.${Ansi.NORMAL}".getBytes()); AnsiOutput.setEnabled(AnsiOutput.Enabled.ALWAYS); String banner = printBanner(resource, null, null); assertThat(banner, startsWith("\u001B[31mThis is red.\u001B[0m")); }
@Test public void renderWithColorsButDisabled() throws Exception { Resource resource = new ByteArrayResource( "${Ansi.RED}This is red.${Ansi.NORMAL}".getBytes()); AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); String banner = printBanner(resource, null, null); assertThat(banner, startsWith("This is red.")); }
@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(); }
protected String toAnsiString(String in, AnsiElement element) { return AnsiOutput.toString(element, in); }
protected void appendAnsiString(StringBuilder toAppendTo, String in, AnsiElement element) { toAppendTo.append(AnsiOutput.toString(element, in)); }