Java Code Examples for org.fusesource.jansi.Ansi#a()

The following examples show how to use org.fusesource.jansi.Ansi#a() . 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: AnsiConsole.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 2
Source File: ColorFormatter.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized String format(final LogRecord record) {
    final boolean exception = record.getThrown() != null;
    final Ansi sbuf = prefix(record);
    sbuf.a(record.getLevel().getLocalizedName());
    sbuf.a(" - ");
    sbuf.a(formatMessage(record));
    if (!exception) {
        suffix(sbuf, record);
    }
    sbuf.newline();
    if (exception) {
        try {
            final StringWriter sw = new StringWriter();
            final PrintWriter pw = new PrintWriter(sw);
            record.getThrown().printStackTrace(pw);
            pw.close();
            sbuf.a(sw.toString());
        } catch (final Exception ex) {
            // no-op
        } finally {
            suffix(sbuf, record);
        }
    }
    return sbuf.toString();
}
 
Example 3
Source File: AnsiConsole.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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: StyleRenderer.java    From helidon-build-tools with Apache License 2.0 6 votes vote down vote up
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 5
Source File: AnsiConsole.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 6
Source File: AnsiConsole.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 7
Source File: JAnsiTextRenderer.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private void render(final Ansi ansi, final Code code) {
    if (code.isColor()) {
        if (code.isBackground()) {
            ansi.bg(code.getColor());
        } else {
            ansi.fg(code.getColor());
        }
    } else if (code.isAttribute()) {
        ansi.a(code.getAttribute());
    }
}
 
Example 8
Source File: Seed.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
private String buildWelcomeMessage() {
    Ansi welcomeMessage = Ansi.ansi().reset().fgBrightGreen().a(WELCOME_MESSAGE).reset();
    if (seedVersion != null) {
        welcomeMessage.a("\n").a("Core v").a(Strings.padEnd(seedVersion, 16, ' '));
    }
    if (businessVersion != null) {
        welcomeMessage.a(seedVersion != null ? "" : "\n").a("Business v").a(businessVersion);
    }
    welcomeMessage.a("\n");
    return welcomeMessage.reset().toString();
}
 
Example 9
Source File: LogHelper.java    From Launcher with GNU General Public License v3.0 5 votes vote down vote up
private static String ansiFormatLog(Level level, String dateTime, String message, boolean sub) {

        Ansi ansi = FormatHelper.rawAnsiFormat(level, dateTime, sub);
        ansi.a(message);

        // Finish with reset code
        return ansi.reset().toString();
    }
 
Example 10
Source File: Application.java    From ig-webapi-java-sample with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void logMessage(int x, int y, String message, Ansi.Color fgColor, Ansi.Color bgColor, Ansi.Attribute... attributes) {
   message = message.substring(0, Math.min(message.length(), 120));
   Ansi ansi = ansi().cursor(y, x).eraseLine();
   if(attributes != null) {
      for (Ansi.Attribute attribute : attributes) {
         ansi = ansi.a(attribute);
      }
   }
   ansi = ansi.fg(fgColor != null ? fgColor : Ansi.Color.DEFAULT);
   ansi = ansi.bg(bgColor != null ? bgColor : Ansi.Color.DEFAULT);
   System.out.println(ansi.a(message).reset());
}
 
Example 11
Source File: PlainTextWriter.java    From JGiven with Apache License 2.0 5 votes vote down vote up
String withColor( Color color, boolean bright, Attribute attribute, String text ) {
    if( withColor ) {
        Ansi ansi = bright ? Ansi.ansi().fgBright( color ) : Ansi.ansi().fg( color );
        if( attribute != null ) {
            ansi = ansi.a( attribute );
        }
        return ansi.a( text ).reset().toString();
    }
    return text;
}
 
Example 12
Source File: VisageFormatter.java    From Visage with MIT License 5 votes vote down vote up
@Override
public String format(LogRecord record) {
	if (record.getThrown() != null) {
		record.getThrown().printStackTrace();
	}
	Ansi ansi = Ansi.ansi();
	if (Visage.ansi) {
		ansi.fgBright(Color.BLACK);
	}
	Date date = new Date(record.getMillis());
	ansi.a("@");
	ansi.a(format.format(date));
	if (Visage.ansi) {
		ansi.reset();
	}
	ansi.a(Strings.padStart(Thread.currentThread().getName(), 22, ' '));
	ansi.a(" ");
	if (Visage.ansi && colors.containsKey(record.getLevel())) {
		ansi.fgBright(colors.get(record.getLevel()));
	}
	ansi.a(names.get(record.getLevel()));
	if (Visage.ansi) {
		ansi.reset();
	}
	ansi.a(": ");
	if (Visage.ansi && colors.containsKey(record.getLevel()) && record.getLevel().intValue() >= Level.SEVERE.intValue()) {
		ansi.bold();
		ansi.fgBright(colors.get(record.getLevel()));
	}
	ansi.a(record.getMessage());
	if (Visage.ansi) {
		ansi.reset();
	}
	ansi.a("\n");
	return ansi.toString();
}
 
Example 13
Source File: DefaultColorMap.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void off(Ansi ansi) {
    ansi.a(off);
}
 
Example 14
Source File: DefaultColorMap.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void off(Ansi ansi) {
    ansi.a(off);
}
 
Example 15
Source File: DefaultColorMap.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void on(Ansi ansi) {
    ansi.a(on);
}
 
Example 16
Source File: DefaultColorMap.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void on(Ansi ansi) {
    ansi.a(on);
}
 
Example 17
Source File: DefaultColorMap.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void on(Ansi ansi) {
    ansi.a(on);
}
 
Example 18
Source File: DefaultColorMap.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void off(Ansi ansi) {
    ansi.a(off);
}
 
Example 19
Source File: DefaultColorMap.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void on(Ansi ansi) {
    ansi.a(on);
}
 
Example 20
Source File: DefaultColorMap.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void off(Ansi ansi) {
    ansi.a(off);
}