/** * Hook method that allows controlling whether or not output streams should be wrapped by * AnsiConsole.wrapOutputStream. Unfortunately, Eclipse consoles will look to the AnsiWrap * like they do not understand ansi, even if we were to implement support in Eclipse to' * handle it and the wrapped stream will not pass the ansi chars on to Eclipse). * * @param out The output stream * @return The output stream wrapped an as {@link AnsiConsole} */ protected OutputStream ansiWrap(OutputStream out) { return AnsiConsole.wrapOutputStream(out); }
/** * 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++; }
public void resetScreen() { if (lines > 0) { if (isRealTerminal()) { out.print(ansi().cursorUp(lines).eraseScreen(Erase.FORWARD).toString()); } else { out.print('\r'); } out.flush(); lines = 0; } }
private static String diy(String color, String value) { if (devEnable) { return String.valueOf(Ansi.ansi().eraseScreen().render("@|" + color + " " + value + "|@")); } else { return value; } }
private Ansi moveDownToSkipPrompt() { return ansi() .cursorDown(1) .cursorLeft(PROMPT.length()); }
/** * Replays the last status message. */ public void echoStatus() { if (lastStatus != null) { updateStatus(lastStatus.toString()); } }
static int consoleWidth(String s) { return consoleWidth(new AnsiString(s)); }
/** * @return Whether ansi is enabled */ public boolean isAnsiEnabled() { return Ansi.isEnabled() && (terminal != null && terminal.isAnsiSupported()) && ansiEnabled; }
private static int consoleWidth(AnsiString s) { CharSequence plain = s.getPlain(); int n = 0; for (int i = 0; i < plain.length(); i++) { n += max(wcwidth(plain.charAt(i)), 0); } return n; } }
/** * Shows the prompt to request user input. * * @return The user input prompt */ public String showPrompt() { String prompt = isAnsiEnabled() ? ansiPrompt(PROMPT).toString() : PROMPT; return showPrompt(prompt); }