.style(AttributedStyle.DEFAULT) .append("> ") .toAnsi();
public static String parse(String input, Terminal terminal) { if (input == null || !input.contains("{{") || !input.contains("}}")) { return input; } final AttributedStringBuilder asb = new AttributedStringBuilder(input.length()); AnsiStyleHandler handler = new AnsiStyleHandler() { @Override public void character(char c) { asb.append(c); } @Override public void attribute(String... attrs) { asb.style(makeStyle(asb.style(), attrs)); } }; handler.handle(input); return asb.toAnsi(terminal); }
private String style(String key) { int idx = key.indexOf(' '); if (idx > 0) { String spec = key.substring(0, idx); String value = key.substring(idx + 1); AttributedStyle style = resolver.resolve(spec); return new AttributedStringBuilder().style(style).ansiAppend(value).toAnsi(); } return null; }
return asb.toAnsi(terminal);
protected String getDisplay(Terminal terminal, Path p) { // TODO: use $LS_COLORS for output String name = p.getFileName().toString(); if (Files.isDirectory(p)) { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.styled(AttributedStyle.BOLD.foreground(AttributedStyle.RED), name); sb.append("/"); name = sb.toAnsi(terminal); } else if (Files.isSymbolicLink(p)) { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.styled(AttributedStyle.BOLD.foreground(AttributedStyle.RED), name); sb.append("@"); name = sb.toAnsi(terminal); } return name; }
protected String getDisplay(Terminal terminal, Path p) { // TODO: use $LS_COLORS for output String name = p.getFileName().toString(); if (Files.isDirectory(p)) { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.styled(AttributedStyle.BOLD.foreground(AttributedStyle.RED), name); sb.append("/"); name = sb.toAnsi(terminal); } else if (Files.isSymbolicLink(p)) { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.styled(AttributedStyle.BOLD.foreground(AttributedStyle.RED), name); sb.append("@"); name = sb.toAnsi(terminal); } return name; }
protected String getDisplay(Terminal terminal, Path p) { // TODO: use $LS_COLORS for output String name = p.getFileName().toString(); if (Files.isDirectory(p)) { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.styled(AttributedStyle.BOLD.foreground(AttributedStyle.RED), name); sb.append("/"); name = sb.toAnsi(terminal); } else if (Files.isSymbolicLink(p)) { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.styled(AttributedStyle.BOLD.foreground(AttributedStyle.RED), name); sb.append("@"); name = sb.toAnsi(terminal); } return name; }
/** * Color message with given background color * * @param message message to return * @param color background color to print * @return colored message */ public static String getBackgroundColored(String message, PromptColor color) { return new AttributedStringBuilder().append(message, AttributedStyle.DEFAULT.background(color.toJlineAttributedStyle())).toAnsi(); }
/** * Color message with given color * * @param message message to return * @param color color to print * @return colored message */ public static String getColored(String message, PromptColor color) { return new AttributedStringBuilder().append(message, AttributedStyle.DEFAULT.foreground(color.toJlineAttributedStyle())).toAnsi(); }
protected String getDisplay(Terminal terminal, Path p) { // TODO: use $LS_COLORS for output String name = p.getFileName().toString(); if (Files.isDirectory(p)) { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.style(AttributedStyle.BOLD.foreground(AttributedStyle.RED)); sb.append(name); sb.style(AttributedStyle.DEFAULT); sb.append(OS_IS_WINDOWS ? "\\\\" : "/"); name = sb.toAnsi(terminal); } else if (Files.isSymbolicLink(p)) { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.style(AttributedStyle.BOLD.foreground(AttributedStyle.RED)); sb.append(name); sb.style(AttributedStyle.DEFAULT); sb.append("@"); name = sb.toAnsi(terminal); } return name; }
protected String getDisplay(Terminal terminal, Path p) { // TODO: use $LS_COLORS for output String name = p.getFileName().toString(); if (Files.isDirectory(p)) { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.style(AttributedStyle.BOLD.foreground(AttributedStyle.RED)); sb.append(name); sb.style(AttributedStyle.DEFAULT); sb.append(OS_IS_WINDOWS ? "\\\\" : "/"); name = sb.toAnsi(terminal); } else if (Files.isSymbolicLink(p)) { AttributedStringBuilder sb = new AttributedStringBuilder(); sb.style(AttributedStyle.BOLD.foreground(AttributedStyle.RED)); sb.append(name); sb.style(AttributedStyle.DEFAULT); sb.append("@"); name = sb.toAnsi(terminal); } return name; }
@Override protected void doHandleResult(Throwable result) { lastError = result; String toPrint = StringUtils.hasLength(result.getMessage()) ? result.getMessage() : result.toString(); terminal.writer().println(new AttributedString(toPrint, AttributedStyle.DEFAULT.foreground(AttributedStyle.RED)).toAnsi()); if (interactiveRunner.isEnabled() && commandRegistry.listCommands().containsKey(DETAILS_COMMAND_NAME)) { terminal.writer().println( new AttributedStringBuilder() .append("Details of the error have been omitted. You can use the ", AttributedStyle.DEFAULT.foreground(AttributedStyle.RED)) .append(DETAILS_COMMAND_NAME, AttributedStyle.DEFAULT.foreground(AttributedStyle.RED).bold()) .append(" command to print the full stacktrace.", AttributedStyle.DEFAULT.foreground(AttributedStyle.RED)) .toAnsi() ); } terminal.writer().flush(); if (!interactiveRunner.isEnabled()) { if (result instanceof RuntimeException) { throw (RuntimeException) result; } else if (result instanceof Error) { throw (Error) result; } else { throw new RuntimeException((Throwable) result); } } }
/** * Write highlighted output. * * @param output Text output * @param textToHighlight text to highlight */ public static void writeOutput(String output, String textToHighlight) { Terminal terminal = SshSessionContext.<Terminal>get(TERMINAL); AttributedStringBuilder builder = new AttributedStringBuilder() .style(SshSessionContext.<AttributedStyle>get(TEXT_STYLE)); if (Objects.isNull(textToHighlight)) { builder.append(output); } else { addHighlightedTextToBuilder(output, textToHighlight, builder); } terminal.writer().println(builder.style(AttributedStyle.DEFAULT).toAnsi(terminal)); terminal.flush(); }
private void printHelpMessage() { writer.println(); AttributedStringBuilder builder = new AttributedStringBuilder(); builder.append("The following commands are supported by ") .append(CliConstants.APP_NAME) .append(" at the moment.\n\n"); for (CliCommandType cmdType : CliCommandType.values()) { if (cmdType == CliCommandType.INVALID_COMMAND) continue; String cmdText = cmdType.getCommandName(); String cmdDescription = cmdType.getDescription(); builder.style(AttributedStyle.DEFAULT.bold()) .append(cmdText) .append("\t\t") .style(AttributedStyle.DEFAULT) .append(cmdDescription) .append("\n"); } writer.println(builder.toAnsi()); writer.println("HELP <COMMAND> to get help for a specific command.\n"); writer.flush(); }
TerminalProcessor(Shell properties, Completer completer, List<BaseUserInputProcessor> userInputProcessors) { this.properties = properties; this.completer = completer; this.userInputProcessors = userInputProcessors; prompt = new AttributedStringBuilder() .style(getStyle(properties.getPrompt().getColor())) .append(properties.getPrompt().getTitle()) .append("> ") .style(AttributedStyle.DEFAULT) .toAnsi(); }
/** * Read input from line with mask. Use null if input is to be echoed. Use 0 if nothing is to be echoed and other * characters that get echoed with input * * @param text Text to show * @param mask mask * @return input from user * @throws IOException if any */ public static String readInput(String text, Character mask) throws IOException { LineReader reader = SshSessionContext.<LineReader>get(LINE_READER); AttributedStyle textStyle = SshSessionContext.<AttributedStyle>get(TEXT_STYLE); Terminal terminal = SshSessionContext.<Terminal>get(TERMINAL); String prompt = new AttributedStringBuilder() .style(textStyle) .append(text) .append(' ') .style(AttributedStyle.DEFAULT) .toAnsi(terminal); return reader.readLine(prompt, mask); }
private void drawStatusBar(int rowsInBuffer) { terminal.puts(InfoCmp.Capability.save_cursor); terminal.puts(InfoCmp.Capability.cursor_address, height - 1, 0); AttributedStyle statusBarStyle = AttributedStyle.DEFAULT.background(AttributedStyle.WHITE) .foreground(AttributedStyle.BLACK); AttributedStringBuilder attrBuilder = new AttributedStringBuilder() .style(statusBarStyle.bold().italic()) .append("Q") .style(statusBarStyle) .append(": Quit ") .style(statusBarStyle.bold().italic()) .append("SPACE") .style(statusBarStyle) .append(": Pause/Resume ") .append(String.valueOf(rowsInBuffer) + " rows in buffer "); if (paused) { attrBuilder.style(statusBarStyle.bold().foreground(AttributedStyle.RED).blink()) .append("PAUSED"); } String statusBarText = attrBuilder.toAnsi(); terminal.writer().print(statusBarText); terminal.flush(); terminal.puts(InfoCmp.Capability.restore_cursor); }
@Override public String getContent(String content) { String in = super.getContent(content); AttributedStringBuilder sb = new AttributedStringBuilder(); sb.style(sb.style().foreground(color)); if (bold) sb.style(sb.style().bold()); sb.append(in); if (bold) sb.style(sb.style().boldOff()); sb.style(sb.style().foregroundOff()); return sb.toAnsi(); }
@Override public String getContent(String content) { String in = super.getContent(content); AttributedStringBuilder sb = new AttributedStringBuilder(); sb.style(sb.style().foreground(color)); if (bold) sb.style(sb.style().bold()); sb.append(in); if (bold) sb.style(sb.style().boldOff()); sb.style(sb.style().foregroundOff()); return sb.toAnsi(); }
.style(AttributedStyle.DEFAULT.foreground(AttributedStyle.YELLOW)) .append(CliConstants.PROMPT_1ST + CliConstants.PROMPT_1ST_END) .toAnsi();