org.fusesource.jansi.Ansi Java Examples
The following examples show how to use
org.fusesource.jansi.Ansi.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThirdPartySyncCommand.java From mojito with Apache License 2.0 | 6 votes |
@Override public void execute() throws CommandException { consoleWriter.newLine().a("Third party TMS synchronization for repository: ").fg(CYAN).a(repositoryParam).reset() .a(" project id: ").fg(CYAN).a(thirdPartyProjectId).reset() .a(" actions: ").fg(CYAN).a(Objects.toString(actions)).reset() .a(" plural-separator: ").fg(CYAN).a(Objects.toString(pluralSeparator)).reset() .a(" locale-mapping: ").fg(CYAN).a(Objects.toString(localeMapping)).reset() .a(" options: ").fg(CYAN).a(Objects.toString(options)).println(2); Repository repository = commandHelper.findRepositoryByName(repositoryParam); PollableTask pollableTask = thirdPartyClient.sync(repository.getId(), thirdPartyProjectId, pluralSeparator, localeMapping, actions, options); commandHelper.waitForPollableTask(pollableTask.getId()); consoleWriter.fg(Ansi.Color.GREEN).newLine().a("Finished").println(2); }
Example #2
Source File: DemoCreateCommand.java From mojito with Apache License 2.0 | 6 votes |
@Override public void execute() throws CommandException { createDemoRepository(); initOutputDirectory(); addResourceBundleToDemoDirectory(); importTM(); push(); consoleWriter.newLine().a("Demo repository is ready!").println().println() .a("Go to directory: ") .fg(Ansi.Color.CYAN) .a(outputDirectoryPath.toString()) .reset() .a(". Try to generate the localized files: ") .fg(Ansi.Color.CYAN) .a("mojito pull -r " + repository.getName()) .reset() .a(" then modify ").fg(Ansi.Color.CYAN).a(DEMO_PROPERTIES).reset() .a(" and re-synchronize: ") .fg(Ansi.Color.CYAN) .a("mojito push -r " + repository.getName()) .println(2); }
Example #3
Source File: AnsiConsole.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public void draw(Ansi ansi) { String prefix = StringUtils.getCommonPrefix(new String[]{text, displayedText}); if (prefix.length() < displayedText.length()) { ansi.cursorLeft(displayedText.length() - prefix.length()); } if (prefix.length() < text.length()) { ColorMap.Color color = colorMap.getStatusBarColor(); color.on(ansi); ansi.a(text.substring(prefix.length())); color.off(ansi); } if (displayedText.length() > text.length()) { ansi.eraseLine(Ansi.Erase.FORWARD); } displayedText = text; }
Example #4
Source File: LinkedOrderBook.java From limit-order-book with GNU General Public License v3.0 | 6 votes |
private String formatAskLevel(final double per, final long volSum, final Limit askLevel) { if (askLevel != null) { long tLim = askLevel.getLastAdded(); long tNow = System.currentTimeMillis(); long diff = tNow - tLim; Ansi ansi; if (diff < 3000) ansi = ansi().bold().fgBrightRed(); else if (diff < 60000) ansi = ansi().fgRed(); else if (diff < 300000) ansi = ansi(); else ansi = ansi().fgBrightBlack(); return ansi.a(Util.asUSD(askLevel.getPrice())).reset() + "\t" + Util.asBTC(askLevel.getVolume()) + "\t" + askLevel.getOrders() + "\t" + Util.asBTC(volSum) + "\t" + (volSum <= state.moLast100BuyMax ? ansi().fgBrightGreen() : ansi().fgBrightDefault()).a(String.format("%.2f", per) + "%").reset(); } return ""; }
Example #5
Source File: RepoCreateCommand.java From mojito with Apache License 2.0 | 6 votes |
@Override public void execute() throws CommandException { consoleWriter.a("Create repository: ").fg(Ansi.Color.CYAN).a(nameParam).println(); try { Set<RepositoryLocale> repositoryLocales = localeHelper.extractRepositoryLocalesFromInput(encodedBcp47Tags, true); Set<IntegrityChecker> integrityCheckers = extractIntegrityCheckersFromInput(integrityCheckParam, true); Locale sourceLocale = null; if (sourceLocaleBcp47Tags != null) { sourceLocale = localeClient.getLocaleByBcp47Tag(sourceLocaleBcp47Tags); } Repository repository = repositoryClient.createRepository(nameParam, descriptionParam, sourceLocale, repositoryLocales, integrityCheckers, checkSLA); consoleWriter.newLine().a("created --> repository id: ").fg(Ansi.Color.MAGENTA).a(repository.getId()).println(); } catch (ParameterException | ResourceNotCreatedException | LocaleNotFoundException ex) { throw new CommandException(ex.getMessage(), ex); } }
Example #6
Source File: DemoCreateCommand.java From mojito with Apache License 2.0 | 6 votes |
void addResourceBundleToDemoDirectory() throws CommandException { try { String resourceBundleName = DEMO_PROPERTIES; URL inputResourceBundleUrl = getResourceURL(resourceBundleName); Path resourceBundlePath = outputDirectoryPath.resolve(resourceBundleName); String resourceBundleContent = Resources.toString(inputResourceBundleUrl, StandardCharsets.UTF_8); consoleWriter.newLine().a("Add resource bundle: ").fg(Ansi.Color.CYAN).a(resourceBundlePath.toString()).println(); Files.write(resourceBundleContent, resourceBundlePath.toFile(), StandardCharsets.UTF_8); } catch (IOException ioe) { throw new CommandException("Error copying resource bundle file into the demo directory", ioe); } }
Example #7
Source File: MainLogger.java From Jupiter with GNU General Public License v3.0 | 6 votes |
private String colorize(String string) { if (string.indexOf(TextFormat.ESCAPE) < 0) { return string; } else if (Nukkit.ANSI) { for (TextFormat color : colors) { if (replacements.containsKey(color)) { string = string.replaceAll("(?i)" + color, replacements.get(color)); } else { string = string.replaceAll("(?i)" + color, ""); } } } else { return TextFormat.clean(string); } return string + Ansi.ansi().reset(); }
Example #8
Source File: AnsiLoggerTest.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
@Test public void emphasizeInfoSpecificBrightColor() { TestLog testLog = new TestLog(); AnsiLogger logger = new AnsiLogger(testLog, true, null, false, "T>"); Ansi ansi = new Ansi(); logger.info("Lowercase enables [[c]]bright version[[c]] of %d colors",Ansi.Color.values().length - 1); assertEquals(ansi.fg(AnsiLogger.COLOR_INFO) .a("T>") .a("Lowercase enables ") .fgBright(Ansi.Color.CYAN) .a("bright version") .fg(AnsiLogger.COLOR_INFO) .a(" of 8 colors") .reset().toString(), testLog.getMessage()); }
Example #9
Source File: AnsiLoggerTest.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Test public void emphasizeWarning() { TestLog testLog = new TestLog(); AnsiLogger logger = new AnsiLogger(testLog, true, null, false, "T>"); Ansi ansi = new Ansi(); logger.warn("%s messages support [[*]]emphasis[[*]] too","Warning"); assertEquals(ansi.fg(AnsiLogger.WARNING) .a("T>") .a("Warning messages support ") .fgBright(AnsiLogger.EMPHASIS) .a("emphasis") .fg(AnsiLogger.WARNING) .a(" too") .reset().toString(), testLog.getMessage()); }
Example #10
Source File: GroovyInterpreter.java From COMP6237 with BSD 3-Clause "New" or "Revised" License | 6 votes |
public GroovyInterpreter(Binding binding) throws IOException { this.binding = binding; if (this.binding == null) this.binding = new Binding(); is = new PipedInputStream(); os = new PipedOutputStream(); pis = new PipedInputStream(os); pos = new PipedOutputStream(is); System.setProperty(TerminalFactory.JLINE_TERMINAL, "none"); AnsiConsole.systemInstall(); Ansi.setDetector(new AnsiDetector()); binding.setProperty("out", new ImmediateFlushingPrintWriter(pos)); shell = new Groovysh(binding, new IO(pis, pos, pos)); // { // @Override // public void displayWelcomeBanner(InteractiveShellRunner runner) { // // do nothing // } // }; shell.getIo().setVerbosity(Verbosity.QUIET); }
Example #11
Source File: AnsiLoggerTest.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
@Test public void emphasizeInfoSpecificColor() { TestLog testLog = new TestLog(); AnsiLogger logger = new AnsiLogger(testLog, true, null, false, "T>"); Ansi ansi = new Ansi(); logger.info("Specific [[C]]color[[C]] %s","is possible"); assertEquals(ansi.fg(AnsiLogger.COLOR_INFO) .a("T>") .a("Specific ") .fg(Ansi.Color.CYAN) .a("color") .fg(AnsiLogger.COLOR_INFO) .a(" is possible") .reset().toString(), testLog.getMessage()); }
Example #12
Source File: CUIRenderer.java From consoleui with Apache License 2.0 | 6 votes |
public CUIRenderer() { String os = System.getProperty("os.name"); if( os.startsWith("Windows") ) { checkedBox = "(*) "; uncheckedBox = "( ) "; line = "---------"; cursorSymbol = ansi().fg(Ansi.Color.CYAN).a("> ").toString(); noCursorSpace = ansi().fg(Ansi.Color.DEFAULT).a(" ").toString(); } else { checkedBox = "\u25C9 "; uncheckedBox = "\u25EF "; line = "\u2500─────────────"; cursorSymbol = ansi().fg(Ansi.Color.CYAN).a("\u276F ").toString(); noCursorSpace = ansi().fg(Ansi.Color.DEFAULT).a(" ").toString(); } resourceBundle = ResourceBundle.getBundle("consoleui_messages"); }
Example #13
Source File: AnsiConsole.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public void draw(Ansi ansi) { String prefix = StringUtils.getCommonPrefix(new String[]{text, displayedText}); if (prefix.length() < displayedText.length()) { ansi.cursorLeft(displayedText.length() - prefix.length()); } if (prefix.length() < text.length()) { ColorMap.Color color = colorMap.getStatusBarColor(); color.on(ansi); ansi.a(text.substring(prefix.length())); color.off(ansi); } if (displayedText.length() > text.length()) { ansi.eraseLine(Ansi.Erase.FORWARD); } displayedText = text; }
Example #14
Source File: StyleRenderer.java From helidon-build-tools with Apache License 2.0 | 6 votes |
private static void apply(Ansi ansi, Code code, boolean bright) { if (code.isColor()) { final Color color = code.getColor(); if (code.isBackground()) { if (bright) { ansi.bgBright(color); } else { ansi.bg(color); } } else { if (bright) { ansi.fgBright(color); } else { ansi.fg(color); } } } else if (code.isAttribute()) { ansi.a(code.getAttribute()); } }
Example #15
Source File: TreePrinter.java From seed with Mozilla Public License 2.0 | 6 votes |
private void printTree(Node node, String leftPadding, Ansi ansi) { if (!node.isRootNode()) { ansi .a(leftPadding) .fg(Ansi.Color.YELLOW).a(node.getName()).reset() .newline(); for (PropertyInfo propertyInfo : node.getPropertyInfo()) { printProperty(propertyInfo, leftPadding, ansi); } } for (Node child : node.getChildren()) { printTree(child, leftPadding + (node.isRootNode() ? "" : INDENTATION), ansi); } }
Example #16
Source File: Help.java From actframework with Apache License 2.0 | 6 votes |
private void list(String label, Collection<CliCmdInfo> commands, CliContext context, String q, String fmt) { List<String> lines = new ArrayList<>(); lines.add(label.toUpperCase()); q = S.string(q).trim(); boolean hasFilter = S.notEmpty(q); List<CliCmdInfo> toBeDisplayed = new ArrayList<>(); for (CliCmdInfo info : commands) { String cmd = info.name; if (hasFilter && !(cmd.toLowerCase().contains(q) || cmd.matches(q))) { continue; } if (null == fmt) { toBeDisplayed.add(info); } else { lines.add(S.fmt(fmt, info.nameAndShortcut(), info.help)); } } context.println(Ansi.ansi().render(S.join("\n", lines)).toString()); if (null == fmt) { // display table list context.println(CliView.TABLE.render(toBeDisplayed, metaInfo, context)); } }
Example #17
Source File: AnsiConsole.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void onDeactivate(Ansi ansi) { if (displayedText.length() > 0) { ansi.cursorLeft(displayedText.length()); ansi.eraseLine(Ansi.Erase.FORWARD); displayedText = ""; } }
Example #18
Source File: RepoViewCommand.java From mojito with Apache License 2.0 | 5 votes |
@Override public void execute() throws CommandException { consoleWriter.a("View repository: ").fg(Ansi.Color.CYAN).a(nameParam).println(); try { Repository repository = repositoryClient.getRepositoryByName(nameParam); consoleWriter.newLine().a("Repository id --> ").fg(Ansi.Color.MAGENTA).a(repository.getId()).println(); printIntegrityChecker(repository); printLocales(repository); consoleWriter.println(); } catch (RepositoryNotFoundException ex) { throw new CommandException(ex.getMessage(), ex); } }
Example #19
Source File: ExtractionDiffCommand.java From mojito with Apache License 2.0 | 5 votes |
void failSafe(Throwable t) { String msg = "Unexpected error: " + t.getMessage() + "\n" + ExceptionUtils.getStackTrace(t); consoleWriter.newLine().fg(Ansi.Color.YELLOW).a(msg).println(2); logger.error("Unexpected error", t); consoleWriter.fg(Ansi.Color.GREEN).a("Failing safe...").println(); tryToSendFailSafeNotification(); }
Example #20
Source File: AnsiConsole.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void render(Action<Ansi> action) { Ansi ansi = createAnsi(); action.execute(ansi); try { target.append(ansi.toString()); flushable.flush(); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #21
Source File: AnsiConsole.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public void setText(String text) { if (text.equals(this.text)) { return; } this.text = text; container.redraw(this, new Action<Ansi>() { public void execute(Ansi ansi) { draw(ansi); } }); }
Example #22
Source File: AnsiLogger.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
private String getEmphasisColor(String id) { Ansi.Color color = COLOR_MAP.get(id.toUpperCase()); if (color != null) { return id.toLowerCase().equals(id) ? // lower case letter means bright color ... ansi().fgBright(color).toString() : ansi().fg(color).toString(); } else { return ""; } }
Example #23
Source File: AnsiConsole.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void onDeactivate(Ansi ansi) { if (displayedText.length() > 0) { ansi.cursorLeft(displayedText.length()); ansi.eraseLine(Ansi.Erase.FORWARD); displayedText = ""; } }
Example #24
Source File: AnsiConsole.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void setText(String text) { if (text.equals(this.text)) { return; } this.text = text; container.redraw(this, new Action<Ansi>() { public void execute(Ansi ansi) { draw(ansi); } }); }
Example #25
Source File: TreePrinter.java From seed with Mozilla Public License 2.0 | 5 votes |
private void printProperty(PropertyInfo propertyInfo, String leftPadding, Ansi ansi) { ansi .a(leftPadding) .a(INDENTATION) .fgBright(Ansi.Color.BLUE) .a(propertyInfo.isSingleValue() ? "~" : "") .a(propertyInfo.isMandatory() ? "*" : "") .a(propertyInfo.getName()) .reset(); Object defaultValue = propertyInfo.getDefaultValue(); if (defaultValue != null) { String stringDefaultValue = String.valueOf(defaultValue); if (!defaultToString(defaultValue).equals(stringDefaultValue)) { ansi .a(" = ") .fgBright(Ansi.Color.GREEN) .a(defaultValue instanceof String ? String.format("\"%s\"", stringDefaultValue) : stringDefaultValue) .reset(); } } ansi .fgBright(Ansi.Color.MAGENTA) .a(" (") .a(propertyInfo.getType()) .a(")") .reset() .a(": ") .a(AnsiRenderer.render(propertyInfo.getShortDescription())) .newline(); for (PropertyInfo child : propertyInfo.getInnerPropertyInfo().values()) { printProperty(child, leftPadding + INDENTATION, ansi); } }
Example #26
Source File: AnsiLogger.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
private void initializeColor(boolean useColor) { this.useAnsi = useColor && !log.isDebugEnabled(); if (useAnsi) { AnsiConsole.systemInstall(); Ansi.setEnabled(true); } else { Ansi.setEnabled(false); } }
Example #27
Source File: LogOutputSpec.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
private String formatPrefix(String prefix,boolean withColor) { if (withColor) { Ansi ansi = ansi(); if (fgBright) { ansi.fgBright(color); } else { ansi.fg(color); } return ansi.a(prefix).reset().toString(); } else { return prefix; } }
Example #28
Source File: ColouredConsoleSender.java From Thermos with GNU General Public License v3.0 | 5 votes |
protected ColouredConsoleSender() { super(); this.terminal = ((CraftServer) getServer()).getReader().getTerminal(); replacements.put(ChatColor.BLACK, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString()); replacements.put(ChatColor.DARK_BLUE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString()); replacements.put(ChatColor.DARK_GREEN, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString()); replacements.put(ChatColor.DARK_AQUA, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString()); replacements.put(ChatColor.DARK_RED, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString()); replacements.put(ChatColor.DARK_PURPLE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString()); replacements.put(ChatColor.GOLD, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString()); replacements.put(ChatColor.GRAY, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString()); replacements.put(ChatColor.DARK_GRAY, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString()); replacements.put(ChatColor.BLUE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString()); replacements.put(ChatColor.GREEN, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString()); replacements.put(ChatColor.AQUA, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString()); replacements.put(ChatColor.RED, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.RED).bold().toString()); replacements.put(ChatColor.LIGHT_PURPLE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString()); replacements.put(ChatColor.YELLOW, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString()); replacements.put(ChatColor.WHITE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString()); replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Attribute.BLINK_SLOW).toString()); replacements.put(ChatColor.BOLD, Ansi.ansi().a(Attribute.UNDERLINE_DOUBLE).toString()); replacements.put(ChatColor.STRIKETHROUGH, Ansi.ansi().a(Attribute.STRIKETHROUGH_ON).toString()); replacements.put(ChatColor.UNDERLINE, Ansi.ansi().a(Attribute.UNDERLINE).toString()); replacements.put(ChatColor.ITALIC, Ansi.ansi().a(Attribute.ITALIC).toString()); replacements.put(ChatColor.RESET, Ansi.ansi().a(Attribute.RESET).toString()); }
Example #29
Source File: AnsiConsole.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public Label getStatusBar() { if (statusBar == null) { statusBar = new LabelImpl(container); render(new Action<Ansi>() { public void execute(Ansi ansi) { textArea.onDeactivate(ansi); statusBar.onActivate(ansi); } }); } return statusBar; }
Example #30
Source File: AnsiConsole.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void onActivate(Ansi ansi) { if (extraEol) { ansi.cursorUp(1); ansi.cursorRight(width); extraEol = false; } }