org.fusesource.jansi.Ansi.fg()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中org.fusesource.jansi.Ansi.fg()方法的一些代码示例,展示了Ansi.fg()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ansi.fg()方法的具体详情如下:
包路径:org.fusesource.jansi.Ansi
类名称:Ansi
方法名:fg

Ansi.fg介绍

暂无

代码示例

代码示例来源: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: 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: prestodb/presto

Ansi ansi = Ansi.ansi();
ansi.fg(Ansi.Color.CYAN);
for (int i = 1; i < location.getLineNumber(); i++) {
  ansi.a(lines.get(i - 1)).newline();
ansi.fg(Ansi.Color.RED);
ansi.a(bad).newline();
for (int i = location.getLineNumber(); i < lines.size(); i++) {

代码示例来源: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: 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: micronaut-projects/micronaut-core

.fg(Color.DEFAULT).a(msg).reset();
out.println(lastStatus);
if (!userInputActive) {

代码示例来源:origin: org.apache.logging.log4j/log4j-core

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());
    }
  }
}

代码示例来源:origin: micronaut-projects/micronaut-core

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;
  }
}

代码示例来源: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: apache/drill

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: org.codehaus.groovy/groovy

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();
}

代码示例来源: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: fabric8io/docker-maven-plugin

private String colored(String message, Ansi.Color color, boolean addPrefix, Object ... params) {
  Ansi ansi = ansi().fg(color);
  String msgToPrint = addPrefix ? prefix + message : message;
  return ansi.a(format(evaluateEmphasis(msgToPrint, color), params)).reset().toString();
}

代码示例来源: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: 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: SpigotMC/BungeeCord

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() );
}

代码示例来源:origin: jamesagnew/hapi-fhir

String message = "Unrecognized command: " + ansi().bold().fg(Ansi.Color.RED) + theArgs[0] + ansi().boldOff().fg(Ansi.Color.WHITE);
System.out.println(message);
System.out.println();
System.err.println("  " + ansi().fg(Ansi.Color.RED).bold() + e.getMessage());
System.err.println("" + ansi().fg(Ansi.Color.WHITE).boldOff());
logCommandUsageNoHeader(command);
runCleanupHookAndUnregister();

代码示例来源:origin: jamesagnew/hapi-fhir

String leftString = "Issue " + count + ": ";
int leftWidth = leftString.length();
b.append(ansi().fg(Color.GREEN)).append(leftString);
if (next.getSeverity() != null) {
  b.append(next.getSeverity()).append(ansi().fg(Color.WHITE)).append(" - ");
  b.append(ansi().fg(Color.WHITE)).append(next.getLocationString());
  b.append(ansi().fg(Color.WHITE));
  b.append(leftPad("", leftWidth)).append(line);

代码示例来源:origin: yahoo/elide

@Override
  public String toString() {
    return ansi().fg(color).a(name).reset().toString();
  }
}

相关文章