Refine search
/** * NOTE: Use this method only if isUnixTerminal is true. * Erases the current line and prints the given multiline. Make sure the specified line is not * terminated by linebreak. * * @param line - line to print */ private void reprintMultiLine(String line) { int numLines = line.split("\r\n|\r|\n").length; out.print(ansi().eraseLine(Ansi.Erase.ALL).a(line).a('\n').toString()); out.flush(); lines += numLines; }
private void log(final String level, Object msg, Throwable cause) { assert level != null; assert msg != null; if (io == null) { synchronized (Logger.class) { if (io == null) { io = new IO(); } } } // Allow the msg to be a Throwable, and handle it properly if no cause is given if (cause == null) { if (msg instanceof Throwable) { cause = (Throwable) msg; msg = cause.getMessage(); } } Color color = GREEN; if (WARN.equals(level) || ERROR.equals(level)) { color = RED; } io.out.println(ansi().a(INTENSITY_BOLD).fg(color).a(level).reset().a(" [").a(name).a("] ").a(msg)); if (cause != null) { cause.printStackTrace(io.out); } io.flush(); }
/** * NOTE: Use this method only if isUnixTerminal is true. * Erases the current line and prints the given line with the specified color. * * @param line - line to print * @param color - color for the line */ private void reprintLineWithColorAsBold(String line, Ansi.Color color) { out.print(ansi().eraseLine(Ansi.Erase.ALL).fg(color).bold().a(line).a('\n').boldOff().reset() .toString()); out.flush(); lines++; }
private String doUserInput(String msg, boolean secure) { // Add a space to the end of the message if there isn't one already. if (!msg.endsWith(" ") && !msg.endsWith("\t")) { msg += ' '; } lastMessage = ""; msg = isAnsiEnabled() ? outputCategory(ansi(), ">").fg(DEFAULT).a(msg).reset().toString() : msg; try { return readLine(msg, secure); } finally { cursorMove = 0; } }
@Override public void error(String label, String message) { verifySystemOut(); if (message == null) { return; } cursorMove = 0; try { if (isAnsiEnabled()) { Ansi ansi = outputErrorLabel(userInputActive ? moveDownToSkipPrompt() : ansi(), label).a(message).reset(); if (message.endsWith(LINE_SEPARATOR)) { out.print(ansi); } else { out.println(ansi); } } else { out.print(label); out.print(" "); logSimpleError(message); } } finally { postPrintMessage(); } }
Ansi.ansi().a(Attribute.RESET).fg(Color.BLACK).boldOff().toString()); replacements.put(ChatColor.DARK_BLUE, Ansi.ansi().a(Attribute.RESET).fg(Color.BLUE).boldOff().toString()); replacements.put(ChatColor.DARK_GREEN, Ansi.ansi().a(Attribute.RESET).fg(Color.GREEN).boldOff().toString()); replacements.put(ChatColor.DARK_AQUA, Ansi.ansi().a(Attribute.RESET).fg(Color.CYAN).boldOff().toString()); replacements.put(ChatColor.DARK_RED, Ansi.ansi().a(Attribute.RESET).fg(Color.RED).boldOff().toString()); replacements.put(ChatColor.DARK_PURPLE, Ansi.ansi().a(Attribute.RESET).fg(Color.MAGENTA).boldOff().toString()); replacements.put(ChatColor.GOLD, Ansi.ansi().a(Attribute.RESET).fg(Color.YELLOW).boldOff().toString()); replacements.put(ChatColor.GRAY, Ansi.ansi().a(Attribute.RESET).fg(Color.WHITE).boldOff().toString()); replacements.put(ChatColor.DARK_GRAY, Ansi.ansi().a(Attribute.RESET).fg(Color.BLACK).bold().toString()); replacements .put(ChatColor.BLUE, Ansi.ansi().a(Attribute.RESET).fg(Color.BLUE).bold() .toString()); replacements .put(ChatColor.GREEN, Ansi.ansi().a(Attribute.RESET).fg(Color.GREEN).bold() .toString()); replacements .put(ChatColor.AQUA, Ansi.ansi().a(Attribute.RESET).fg(Color.CYAN).bold() .toString()); replacements .put(ChatColor.RED, Ansi.ansi().a(Attribute.RESET).fg(Color.RED).bold().toString()); replacements.put(ChatColor.LIGHT_PURPLE,
public void test(final String[] args) { System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable // System.out.println(System.getProperty("java.class.path")); final String config = args == null || args.length == 0 ? "target/test-classes/log4j2-console-msg-ansi.xml" : args[0]; try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config)) { final Logger logger = LogManager.getLogger(ConsoleAppenderJAnsiMessageMain.class); logger.info(ansi().fg(RED).a("Hello").fg(CYAN).a(" World").reset()); // JAnsi format: // logger.info("@|red Hello|@ @|cyan World|@"); for (final Entry<Object, Object> entry : System.getProperties().entrySet()) { logger.info("@|KeyStyle {}|@ = @|ValueStyle {}|@", entry.getKey(), entry.getValue()); } } }
private void updateAnsiProgress(String imageId, String status, String progressMessage) { Map<String,Integer> imgLineMap = imageLines.get(); Integer line = imgLineMap.get(imageId); int diff = 0; if (line == null) { line = imgLineMap.size(); imgLineMap.put(imageId, line); } else { diff = imgLineMap.size() - line; } if (diff > 0) { print(ansi().cursorUp(diff).eraseLine(Ansi.Erase.ALL).toString()); } // Status with progress bars: (max length = 11, hence pad to 11) // Extracting // Downloading String progress = progressMessage != null ? progressMessage : ""; String msg = ansi() .fg(COLOR_PROGRESS_ID).a(imageId).reset().a(": ") .fg(COLOR_PROGRESS_STATUS).a(StringUtils.rightPad(status,11) + " ") .fg(COLOR_PROGRESS_BAR).a(progress).toString(); println(msg); if (diff > 0) { // move cursor back down to bottom print(ansi().cursorDown(diff - 1).toString()); } }
public ColouredWriter(ConsoleReader console) { this.console = console; replacements.put( ChatColor.BLACK, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.BLACK ).boldOff().toString() ); replacements.put( ChatColor.DARK_BLUE, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.BLUE ).boldOff().toString() ); replacements.put( ChatColor.DARK_GREEN, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.GREEN ).boldOff().toString() ); replacements.put( ChatColor.DARK_AQUA, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.CYAN ).boldOff().toString() ); replacements.put( ChatColor.DARK_RED, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.RED ).boldOff().toString() ); replacements.put( ChatColor.DARK_PURPLE, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.MAGENTA ).boldOff().toString() ); replacements.put( ChatColor.GOLD, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.YELLOW ).boldOff().toString() ); replacements.put( ChatColor.GRAY, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.WHITE ).boldOff().toString() ); replacements.put( ChatColor.DARK_GRAY, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.BLACK ).bold().toString() ); replacements.put( ChatColor.BLUE, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.BLUE ).bold().toString() ); replacements.put( ChatColor.GREEN, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.GREEN ).bold().toString() ); replacements.put( ChatColor.AQUA, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.CYAN ).bold().toString() ); replacements.put( ChatColor.RED, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.RED ).bold().toString() ); replacements.put( ChatColor.LIGHT_PURPLE, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.MAGENTA ).bold().toString() ); replacements.put( ChatColor.YELLOW, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.YELLOW ).bold().toString() ); replacements.put( ChatColor.WHITE, Ansi.ansi().a( Ansi.Attribute.RESET ).fg( Ansi.Color.WHITE ).bold().toString() ); replacements.put( ChatColor.MAGIC, Ansi.ansi().a( Ansi.Attribute.BLINK_SLOW ).toString() ); replacements.put( ChatColor.BOLD, Ansi.ansi().a( Ansi.Attribute.UNDERLINE_DOUBLE ).toString() ); replacements.put( ChatColor.STRIKETHROUGH, Ansi.ansi().a( Ansi.Attribute.STRIKETHROUGH_ON ).toString() ); replacements.put( ChatColor.UNDERLINE, Ansi.ansi().a( Ansi.Attribute.UNDERLINE ).toString() ); replacements.put( ChatColor.ITALIC, Ansi.ansi().a( Ansi.Attribute.ITALIC ).toString() ); replacements.put( ChatColor.RESET, Ansi.ansi().a( Ansi.Attribute.RESET ).toString() ); }