Skip to content

Instantly share code, notes, and snippets.

@cy6erGn0m
Created June 21, 2012 14:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cy6erGn0m/2966165 to your computer and use it in GitHub Desktop.
Save cy6erGn0m/2966165 to your computer and use it in GitHub Desktop.
Simple example jansi library
package cg;
import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.AnsiConsole;
/**
* User: Sergey Mashkov
* Date: 6/21/12
*/
public class Main {
private static final int MAX = 30;
public static void main(String[] args) throws Exception {
AnsiConsole.systemInstall();
for (int i = 0; i <= 10; ++i) {
printProgress(i * 10);
Thread.sleep(500);
}
AnsiConsole.out().print(Ansi.ansi().reset().fg(Ansi.Color.WHITE));
org.fusesource.jansi.AnsiConsole.systemUninstall();
}
private static void printProgress(int progress) {
double v = ((double)progress) / 100.;
v *= MAX;
int chars = (int)Math.floor(v);
Ansi.Color color = Ansi.Color.RED;
if (progress > 75) {
color = Ansi.Color.GREEN;
} else if (progress > 50) {
color = Ansi.Color.YELLOW;
}
Ansi a = Ansi.ansi(80).restorCursorPosition().saveCursorPosition().a(" ").bold().fg(color).a("[");
int i;
for (i = 1; i <= chars; ++i) {
if (i == chars) {
a.a(">");
} else {
a.a("=");
}
}
a.boldOff();
for (; i <= MAX; ++i) {
a.a("-");
}
a.bold().a("] ").fg(Ansi.Color.WHITE).a(progress).a("%").boldOff();
AnsiConsole.out().print(a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment