本文整理了Java中org.fusesource.jansi.Ansi
类的一些代码示例,展示了Ansi
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ansi
类的具体详情如下:
包路径:org.fusesource.jansi.Ansi
类名称:Ansi
[英]Provides a fluent API for generating ANSI escape sequences.
[中]提供用于生成ANSI转义序列的流畅API。
代码示例来源:origin: fabric8io/docker-maven-plugin
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;
}
}
代码示例来源:origin: apache/hive
/**
* 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++;
}
代码示例来源:origin: micronaut-projects/micronaut-core
private Ansi ansiPrompt(String prompt) {
return ansi()
.a(Ansi.Attribute.INTENSITY_BOLD)
.fgBright(BLUE)
.a(prompt)
.a(Ansi.Attribute.INTENSITY_BOLD_OFF)
.fg(DEFAULT);
}
代码示例来源:origin: micronaut-projects/micronaut-core
private Ansi outputErrorLabel(Ansi ansi, String label) {
return ansi
.a(Ansi.Attribute.INTENSITY_BOLD)
.fg(RED)
.a(CATEGORY_SEPARATOR)
.a(SPACE)
.a(label)
.a(" ")
.a(Ansi.Attribute.INTENSITY_BOLD_OFF)
.fg(Color.DEFAULT);
}
代码示例来源:origin: micronaut-projects/micronaut-core
private Ansi outputCategory(Ansi ansi, String categoryName) {
return ansi
.a(Ansi.Attribute.INTENSITY_BOLD)
.fgBright(BLUE)
.a(categoryName)
.a(SPACE)
.a(Ansi.Attribute.INTENSITY_BOLD_OFF);
}
代码示例来源:origin: prestodb/presto
public void reprintLine(String line)
{
if (isRealTerminal()) {
out.print(ansi().eraseLine(Erase.ALL).a(line).a('\n').toString());
}
else {
out.print('\r' + line);
}
out.flush();
lines++;
}
代码示例来源:origin: GlowstoneMC/Glowstone
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,
代码示例来源:origin: fabric8io/docker-maven-plugin
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());
}
}
代码示例来源:origin: org.jledit/core
/**
* Displays Text highlighting the text that was marked as highlighted.
*
* @param text
*/
protected void displayText(String text) {
if (highLight != null && !highLight.isEmpty() && text.contains(highLight)) {
String highLightedText = text.replaceAll(highLight, ansi().bold().bg(theme.getHighLightBackground()).fg(theme.getHighLightForeground()).a(highLight).boldOff().reset().toString());
console.out().print(highLightedText);
} else {
console.out().print(text);
}
}
代码示例来源:origin: org.jledit/core
public void redrawHeader() {
saveCursorPosition();
getConsole().out().print(ansi().cursor(1, 1));
Ansi style = ansi();
if (getTheme().getHeaderBackground() != null) {
style.bg(getTheme().getHeaderBackground());
}
if (getTheme().getHeaderForeground() != null) {
style.fg(getTheme().getHeaderForeground());
}
String textCoords = "L:" + getLine() + " C:" + getColumn();
int displayFileLength = getTerminal().getWidth() - getTitle().length() - textCoords.length() - 1;
getConsole().out().print(style.a(getTitle()).a(":").a(Strings.tryToTrimToSize(getDisplayAs(), displayFileLength)).a(isDirty() ? DIRTY_SIGN : "").eraseLine(Ansi.Erase.FORWARD));
getConsole().out().print(ansi().cursor(1, getTerminal().getWidth() - textCoords.length()));
getConsole().out().print(ansi().a(textCoords).reset());
getConsole().out().print(ansi().cursor(getTerminal().getHeight(), 1));
restoreCursorPosition();
}
代码示例来源:origin: io.github.christian-draeger/page-content-tester
@Override
public void testIgnored(Description description) throws Exception {
System.out.println("\u23ed " + ansi().fgBrightBlack().bold().a("skipped test : ").reset() + description.getDisplayName());
}
代码示例来源:origin: org.seedstack.seed/seed-shell-support
private String resetColor() {
if (terminal.isAnsiSupported()) {
return Ansi.ansi().reset().toString();
} else {
return "";
}
}
代码示例来源:origin: apache/hive
/**
* NOTE: Use this method only if isUnixTerminal is true.
* Repositions the cursor back to line 0.
*/
private void repositionCursor() {
if (lines > 0) {
out.print(ansi().cursorUp(lines).toString());
out.flush();
lines = 0;
}
}
代码示例来源:origin: org.testifyproject.tools/test-logger
String getMagentaMessage(String loggerName) {
return ansi()
.bold()
.fgMagenta()
.a(loggerName)
.reset()
.toString();
}
代码示例来源:origin: fabric8io/docker-maven-plugin
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 "";
}
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* Makes sure that the console has been reset to the default state and that the out stream has been flushed.
*/
public void flush() {
if (isAnsiEnabled()) {
out.print(ansi().reset().toString());
}
out.flush();
}
代码示例来源:origin: com.dslplatform/dsl-clc
private void askSafe(final String question, final Color color) {
if (withColor) {
try {
write(console, false, Ansi.ansi().fgBright(color).bold().a(question + " ").boldOff().reset().toString());
return;
} catch (NoSuchMethodError ignore) {
warning("Incompatible jansi found on classpath. Reverting to no-color");
withColor = false;
}
}
write(console, false, question + " ");
}
代码示例来源:origin: jamesagnew/hapi-fhir
private void logUsage() {
logAppHeader();
System.out.println("Usage:");
System.out.println(" " + provideCommandName() + " {command} [options]");
System.out.println();
System.out.println("Commands:");
int longestCommandLength = 0;
for (BaseCommand next : ourCommands) {
longestCommandLength = Math.max(longestCommandLength, next.getCommandName().length());
}
for (BaseCommand next : ourCommands) {
String left = " " + StringUtils.rightPad(next.getCommandName(), longestCommandLength);
String[] rightParts = WordUtils.wrap(next.getCommandDescription(), 80 - (left.length() + 3)).split("\\n");
for (int i = 1; i < rightParts.length; i++) {
rightParts[i] = StringUtils.leftPad("", left.length() + 3) + rightParts[i];
}
System.out.println(ansi().bold().fg(Ansi.Color.GREEN) + left + ansi().boldOff().fg(Ansi.Color.WHITE) + " - " + ansi().bold() + StringUtils.join(rightParts, LINESEP));
}
System.out.println();
System.out.println(ansi().boldOff().fg(Ansi.Color.WHITE) + "See what options are available:");
System.out.println(" " + provideCommandName() + " help {command}");
System.out.println();
}
代码示例来源:origin: fabric8io/docker-maven-plugin
private String evaluateEmphasis(String message, Ansi.Color msgColor) {
// Split with delimiters [[.]]. See also http://stackoverflow.com/a/2206545/207604
String prepared = message.replaceAll("\\[\\[(.)]]","[[]]$1[[]]");
String[] parts = prepared.split("\\[\\[]]");
if (parts.length == 1) {
return message;
}
String msgColorS = ansi().fg(msgColor).toString();
StringBuilder ret = new StringBuilder(parts[0]);
boolean colorOpen = true;
for (int i = 1; i < parts.length; i+=2) {
ret.append(colorOpen ? getEmphasisColor(parts[i]) : msgColorS);
colorOpen = !colorOpen;
if (i+1 < parts.length) {
ret.append(parts[i+1]);
}
}
return ret.toString();
}
代码示例来源:origin: micronaut-projects/micronaut-core
@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();
}
}
内容来源于网络,如有侵权,请联系作者删除!