diff --git a/jansi/src/main/java/org/fusesource/jansi/Ansi.java b/jansi/src/main/java/org/fusesource/jansi/Ansi.java
index ded20ec9..317aa455 100644
--- a/jansi/src/main/java/org/fusesource/jansi/Ansi.java
+++ b/jansi/src/main/java/org/fusesource/jansi/Ansi.java
@@ -21,121 +21,127 @@
/**
* Provides a fluent API for generating ANSI escape sequences.
- *
+ *
* @author Hiram Chirino
* @since 1.0
*/
public class Ansi {
private static final char FIRST_ESC_CHAR = 27;
- private static final char SECOND_ESC_CHAR = '[';
-
- public static enum Color {
- BLACK(0, "BLACK"),
- RED(1, "RED"),
- GREEN(2, "GREEN"),
- YELLOW(3, "YELLOW"),
- BLUE(4, "BLUE"),
- MAGENTA(5, "MAGENTA"),
- CYAN(6, "CYAN"),
- WHITE(7,"WHITE"),
- DEFAULT(9,"DEFAULT");
-
- private final int value;
- private final String name;
-
- Color(int index, String name) {
- this.value = index;
- this.name = name;
- }
-
- @Override
- public String toString() {
- return name;
- }
-
- public int value() {
- return value;
- }
-
- public int fg() {
- return value + 30;
- }
-
- public int bg() {
- return value + 40;
- }
-
- public int fgBright() {
- return value + 90;
- }
-
- public int bgBright() {
- return value + 100;
- }
- };
-
- public static enum Attribute {
- RESET ( 0, "RESET"),
- INTENSITY_BOLD ( 1, "INTENSITY_BOLD"),
- INTENSITY_FAINT ( 2, "INTENSITY_FAINT"),
- ITALIC ( 3, "ITALIC_ON"),
- UNDERLINE ( 4, "UNDERLINE_ON"),
- BLINK_SLOW ( 5, "BLINK_SLOW"),
- BLINK_FAST ( 6, "BLINK_FAST"),
- NEGATIVE_ON ( 7, "NEGATIVE_ON"),
- CONCEAL_ON ( 8, "CONCEAL_ON"),
- STRIKETHROUGH_ON ( 9, "STRIKETHROUGH_ON"),
- UNDERLINE_DOUBLE ( 21, "UNDERLINE_DOUBLE"),
- INTENSITY_BOLD_OFF ( 22, "INTENSITY_BOLD_OFF"),
- ITALIC_OFF ( 23, "ITALIC_OFF"),
- UNDERLINE_OFF ( 24, "UNDERLINE_OFF"),
- BLINK_OFF ( 25, "BLINK_OFF"),
- NEGATIVE_OFF ( 27, "NEGATIVE_OFF"),
- CONCEAL_OFF ( 28, "CONCEAL_OFF"),
- STRIKETHROUGH_OFF ( 29, "STRIKETHROUGH_OFF");
-
- private final int value;
- private final String name;
-
- Attribute(int index, String name) {
- this.value = index;
- this.name = name;
- }
-
- @Override
- public String toString() {
- return name;
- }
-
- public int value() {
- return value;
- }
-
- };
-
- public static enum Erase {
- FORWARD(0, "FORWARD"),
- BACKWARD(1, "BACKWARD"),
- ALL(2, "ALL");
-
- private final int value;
- private final String name;
-
- Erase(int index, String name) {
- this.value = index;
- this.name = name;
- }
-
- @Override
- public String toString() {
- return name;
- }
-
- public int value() {
- return value;
- }
- };
+ private static final char SECOND_ESC_CHAR = '[';
+
+ public static enum Color {
+ BLACK(0, "BLACK"),
+ RED(1, "RED"),
+ GREEN(2, "GREEN"),
+ YELLOW(3, "YELLOW"),
+ BLUE(4, "BLUE"),
+ MAGENTA(5, "MAGENTA"),
+ CYAN(6, "CYAN"),
+ WHITE(7, "WHITE"),
+ DEFAULT(9, "DEFAULT");
+
+ private final int value;
+ private final String name;
+
+ Color(int index, String name) {
+ this.value = index;
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ public int value() {
+ return value;
+ }
+
+ public int fg() {
+ return value + 30;
+ }
+
+ public int bg() {
+ return value + 40;
+ }
+
+ public int fgBright() {
+ return value + 90;
+ }
+
+ public int bgBright() {
+ return value + 100;
+ }
+ }
+
+ ;
+
+ public static enum Attribute {
+ RESET(0, "RESET"),
+ INTENSITY_BOLD(1, "INTENSITY_BOLD"),
+ INTENSITY_FAINT(2, "INTENSITY_FAINT"),
+ ITALIC(3, "ITALIC_ON"),
+ UNDERLINE(4, "UNDERLINE_ON"),
+ BLINK_SLOW(5, "BLINK_SLOW"),
+ BLINK_FAST(6, "BLINK_FAST"),
+ NEGATIVE_ON(7, "NEGATIVE_ON"),
+ CONCEAL_ON(8, "CONCEAL_ON"),
+ STRIKETHROUGH_ON(9, "STRIKETHROUGH_ON"),
+ UNDERLINE_DOUBLE(21, "UNDERLINE_DOUBLE"),
+ INTENSITY_BOLD_OFF(22, "INTENSITY_BOLD_OFF"),
+ ITALIC_OFF(23, "ITALIC_OFF"),
+ UNDERLINE_OFF(24, "UNDERLINE_OFF"),
+ BLINK_OFF(25, "BLINK_OFF"),
+ NEGATIVE_OFF(27, "NEGATIVE_OFF"),
+ CONCEAL_OFF(28, "CONCEAL_OFF"),
+ STRIKETHROUGH_OFF(29, "STRIKETHROUGH_OFF");
+
+ private final int value;
+ private final String name;
+
+ Attribute(int index, String name) {
+ this.value = index;
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ public int value() {
+ return value;
+ }
+
+ }
+
+ ;
+
+ public static enum Erase {
+ FORWARD(0, "FORWARD"),
+ BACKWARD(1, "BACKWARD"),
+ ALL(2, "ALL");
+
+ private final int value;
+ private final String name;
+
+ Erase(int index, String name) {
+ this.value = index;
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ public int value() {
+ return value;
+ }
+ }
+
+ ;
public static final String DISABLE = Ansi.class.getName() + ".disable";
@@ -153,14 +159,12 @@ public static void setDetector(final Callable detector) {
public static boolean isDetected() {
try {
return detector.call();
- }
- catch (Exception e) {
+ } catch (Exception e) {
return true;
}
}
- private static final InheritableThreadLocal holder = new InheritableThreadLocal()
- {
+ private static final InheritableThreadLocal holder = new InheritableThreadLocal() {
@Override
protected Boolean initialValue() {
return isDetected();
@@ -178,15 +182,13 @@ public static boolean isEnabled() {
public static Ansi ansi() {
if (isEnabled()) {
return new Ansi();
- }
- else {
+ } else {
return new NoAnsi();
}
}
private static class NoAnsi
- extends Ansi
- {
+ extends Ansi {
@Override
public Ansi fg(Color color) {
return this;
@@ -314,32 +316,33 @@ public Ansi reset() {
}
}
- private final StringBuilder builder;
- private final ArrayList attributeOptions = new ArrayList(5);
-
- public Ansi() {
- this(new StringBuilder());
- }
+ private final StringBuilder builder;
+ private final ArrayList attributeOptions = new ArrayList(5);
- public Ansi(Ansi parent) {
- this(new StringBuilder(parent.builder));
- attributeOptions.addAll(parent.attributeOptions);
- }
+ public Ansi() {
+ this(new StringBuilder());
+ }
+
+ public Ansi(Ansi parent) {
+ this(new StringBuilder(parent.builder));
+ attributeOptions.addAll(parent.attributeOptions);
+ }
public Ansi(int size) {
- this(new StringBuilder(size));
- }
+ this(new StringBuilder(size));
+ }
public Ansi(StringBuilder builder) {
- this.builder = builder;
- }
+ this.builder = builder;
+ }
- public static Ansi ansi(StringBuilder builder) {
- return new Ansi(builder);
- }
- public static Ansi ansi(int size) {
- return new Ansi(size);
- }
+ public static Ansi ansi(StringBuilder builder) {
+ return new Ansi(builder);
+ }
+
+ public static Ansi ansi(int size) {
+ return new Ansi(size);
+ }
public Ansi fg(Color color) {
attributeOptions.add(color.fg());
@@ -350,60 +353,60 @@ public Ansi fgBlack() {
return this.fg(Color.BLACK);
}
- public Ansi fgBlue() {
+ public Ansi fgBlue() {
return this.fg(Color.BLUE);
}
- public Ansi fgCyan() {
+ public Ansi fgCyan() {
return this.fg(Color.CYAN);
}
- public Ansi fgDefault() {
+ public Ansi fgDefault() {
return this.fg(Color.DEFAULT);
}
- public Ansi fgGreen() {
+ public Ansi fgGreen() {
return this.fg(Color.GREEN);
}
- public Ansi fgMagenta() {
+ public Ansi fgMagenta() {
return this.fg(Color.MAGENTA);
}
- public Ansi fgRed() {
+ public Ansi fgRed() {
return this.fg(Color.RED);
}
- public Ansi fgYellow() {
+ public Ansi fgYellow() {
return this.fg(Color.YELLOW);
}
- public Ansi bg(Color color) {
- attributeOptions.add(color.bg());
- return this;
- }
+ public Ansi bg(Color color) {
+ attributeOptions.add(color.bg());
+ return this;
+ }
- public Ansi bgCyan() {
+ public Ansi bgCyan() {
return this.fg(Color.CYAN);
}
- public Ansi bgDefault() {
+ public Ansi bgDefault() {
return this.bg(Color.DEFAULT);
}
- public Ansi bgGreen() {
+ public Ansi bgGreen() {
return this.bg(Color.GREEN);
}
- public Ansi bgMagenta() {
+ public Ansi bgMagenta() {
return this.bg(Color.MAGENTA);
}
- public Ansi bgRed() {
+ public Ansi bgRed() {
return this.bg(Color.RED);
}
- public Ansi bgYellow() {
+ public Ansi bgYellow() {
return this.bg(Color.YELLOW);
}
@@ -416,91 +419,91 @@ public Ansi fgBrightBlack() {
return this.fgBright(Color.BLACK);
}
- public Ansi fgBrightBlue() {
+ public Ansi fgBrightBlue() {
return this.fgBright(Color.BLUE);
}
- public Ansi fgBrightCyan() {
+ public Ansi fgBrightCyan() {
return this.fgBright(Color.CYAN);
}
- public Ansi fgBrightDefault() {
+ public Ansi fgBrightDefault() {
return this.fgBright(Color.DEFAULT);
}
- public Ansi fgBrightGreen() {
+ public Ansi fgBrightGreen() {
return this.fgBright(Color.GREEN);
}
- public Ansi fgBrightMagenta() {
+ public Ansi fgBrightMagenta() {
return this.fgBright(Color.MAGENTA);
}
- public Ansi fgBrightRed() {
+ public Ansi fgBrightRed() {
return this.fgBright(Color.RED);
}
- public Ansi fgBrightYellow() {
+ public Ansi fgBrightYellow() {
return this.fgBright(Color.YELLOW);
}
-
+
public Ansi bgBright(Color color) {
attributeOptions.add(color.bgBright());
return this;
}
- public Ansi bgBrightCyan() {
+ public Ansi bgBrightCyan() {
return this.fgBright(Color.CYAN);
}
- public Ansi bgBrightDefault() {
+ public Ansi bgBrightDefault() {
return this.bgBright(Color.DEFAULT);
}
- public Ansi bgBrightGreen() {
+ public Ansi bgBrightGreen() {
return this.bgBright(Color.GREEN);
}
- public Ansi bgBrightMagenta() {
+ public Ansi bgBrightMagenta() {
return this.bg(Color.MAGENTA);
}
- public Ansi bgBrightRed() {
+ public Ansi bgBrightRed() {
return this.bgBright(Color.RED);
}
- public Ansi bgBrightYellow() {
+ public Ansi bgBrightYellow() {
return this.bgBright(Color.YELLOW);
}
- public Ansi a(Attribute attribute) {
- attributeOptions.add(attribute.value());
- return this;
- }
-
- public Ansi cursor(final int x, final int y) {
- return appendEscapeSequence('H', x, y);
- }
+ public Ansi a(Attribute attribute) {
+ attributeOptions.add(attribute.value());
+ return this;
+ }
+
+ public Ansi cursor(final int x, final int y) {
+ return appendEscapeSequence('H', x, y);
+ }
public Ansi cursorToColumn(final int x) {
return appendEscapeSequence('G', x);
}
- public Ansi cursorUp(final int y) {
- return appendEscapeSequence('A', y);
- }
+ public Ansi cursorUp(final int y) {
+ return appendEscapeSequence('A', y);
+ }
- public Ansi cursorDown(final int y) {
- return appendEscapeSequence('B', y);
- }
+ public Ansi cursorDown(final int y) {
+ return appendEscapeSequence('B', y);
+ }
- public Ansi cursorRight(final int x) {
- return appendEscapeSequence('C', x);
- }
+ public Ansi cursorRight(final int x) {
+ return appendEscapeSequence('C', x);
+ }
- public Ansi cursorLeft(final int x) {
- return appendEscapeSequence('D', x);
- }
+ public Ansi cursorLeft(final int x) {
+ return appendEscapeSequence('D', x);
+ }
public Ansi cursorDownLine() {
return appendEscapeSequence('E');
@@ -518,46 +521,46 @@ public Ansi cursorUpLine(final int n) {
return appendEscapeSequence('F', n);
}
- public Ansi eraseScreen() {
- return appendEscapeSequence('J',Erase.ALL.value());
- }
+ public Ansi eraseScreen() {
+ return appendEscapeSequence('J', Erase.ALL.value());
+ }
- public Ansi eraseScreen(final Erase kind) {
- return appendEscapeSequence('J', kind.value());
- }
+ public Ansi eraseScreen(final Erase kind) {
+ return appendEscapeSequence('J', kind.value());
+ }
- public Ansi eraseLine() {
- return appendEscapeSequence('K');
- }
+ public Ansi eraseLine() {
+ return appendEscapeSequence('K');
+ }
- public Ansi eraseLine(final Erase kind) {
- return appendEscapeSequence('K', kind.value());
- }
+ public Ansi eraseLine(final Erase kind) {
+ return appendEscapeSequence('K', kind.value());
+ }
- public Ansi scrollUp(final int rows) {
- return appendEscapeSequence('S', rows);
- }
+ public Ansi scrollUp(final int rows) {
+ return appendEscapeSequence('S', rows);
+ }
- public Ansi scrollDown(final int rows) {
- return appendEscapeSequence('T', rows);
- }
+ public Ansi scrollDown(final int rows) {
+ return appendEscapeSequence('T', rows);
+ }
- public Ansi saveCursorPosition() {
- return appendEscapeSequence('s');
- }
+ public Ansi saveCursorPosition() {
+ return appendEscapeSequence('s');
+ }
@Deprecated
- public Ansi restorCursorPosition() {
- return appendEscapeSequence('u');
- }
+ public Ansi restorCursorPosition() {
+ return appendEscapeSequence('u');
+ }
- public Ansi restoreCursorPosition() {
- return appendEscapeSequence('u');
- }
+ public Ansi restoreCursorPosition() {
+ return appendEscapeSequence('u');
+ }
- public Ansi reset() {
- return a(Attribute.RESET);
- }
+ public Ansi reset() {
+ return a(Attribute.RESET);
+ }
public Ansi bold() {
return a(Attribute.INTENSITY_BOLD);
@@ -567,88 +570,88 @@ public Ansi boldOff() {
return a(Attribute.INTENSITY_BOLD_OFF);
}
- public Ansi a(String value) {
- flushAttributes();
- builder.append(value);
- return this;
- }
-
- public Ansi a(boolean value) {
- flushAttributes();
- builder.append(value);
- return this;
- }
-
- public Ansi a(char value) {
- flushAttributes();
- builder.append(value);
- return this;
- }
-
- public Ansi a(char[] value, int offset, int len) {
- flushAttributes();
- builder.append(value, offset, len);
- return this;
- }
-
- public Ansi a(char[] value) {
- flushAttributes();
- builder.append(value);
- return this;
- }
-
- public Ansi a(CharSequence value, int start, int end) {
- flushAttributes();
- builder.append(value, start, end);
- return this;
- }
-
- public Ansi a(CharSequence value) {
- flushAttributes();
- builder.append(value);
- return this;
- }
-
- public Ansi a(double value) {
- flushAttributes();
- builder.append(value);
- return this;
- }
-
- public Ansi a(float value) {
- flushAttributes();
- builder.append(value);
- return this;
- }
-
- public Ansi a(int value) {
- flushAttributes();
- builder.append(value);
- return this;
- }
-
- public Ansi a(long value) {
- flushAttributes();
- builder.append(value);
- return this;
- }
-
- public Ansi a(Object value) {
- flushAttributes();
- builder.append(value);
- return this;
- }
-
- public Ansi a(StringBuffer value) {
- flushAttributes();
- builder.append(value);
- return this;
- }
+ public Ansi a(String value) {
+ flushAttributes();
+ builder.append(value);
+ return this;
+ }
+
+ public Ansi a(boolean value) {
+ flushAttributes();
+ builder.append(value);
+ return this;
+ }
+
+ public Ansi a(char value) {
+ flushAttributes();
+ builder.append(value);
+ return this;
+ }
+
+ public Ansi a(char[] value, int offset, int len) {
+ flushAttributes();
+ builder.append(value, offset, len);
+ return this;
+ }
+
+ public Ansi a(char[] value) {
+ flushAttributes();
+ builder.append(value);
+ return this;
+ }
+
+ public Ansi a(CharSequence value, int start, int end) {
+ flushAttributes();
+ builder.append(value, start, end);
+ return this;
+ }
+
+ public Ansi a(CharSequence value) {
+ flushAttributes();
+ builder.append(value);
+ return this;
+ }
+
+ public Ansi a(double value) {
+ flushAttributes();
+ builder.append(value);
+ return this;
+ }
+
+ public Ansi a(float value) {
+ flushAttributes();
+ builder.append(value);
+ return this;
+ }
+
+ public Ansi a(int value) {
+ flushAttributes();
+ builder.append(value);
+ return this;
+ }
+
+ public Ansi a(long value) {
+ flushAttributes();
+ builder.append(value);
+ return this;
+ }
+
+ public Ansi a(Object value) {
+ flushAttributes();
+ builder.append(value);
+ return this;
+ }
+
+ public Ansi a(StringBuffer value) {
+ flushAttributes();
+ builder.append(value);
+ return this;
+ }
public Ansi newline() {
flushAttributes();
- builder.append(System.getProperty("line.separator"));
- return this;
+ builder.append(System.getProperty("line.separator"));
+ return this;
}
public Ansi format(String pattern, Object... args) {
@@ -658,12 +661,12 @@ public Ansi format(String pattern, Object... args) {
}
/**
- * Uses the {@link AnsiRenderer}
+ * Uses the {@link AnsiRenderer}
* to generate the ANSI escape sequences for the supplied text.
*
- * @param text text
- * @return this
- *
+ * @param text text
+ * @return this
+ *
* @since 1.1
*/
public Ansi render(final String text) {
@@ -672,13 +675,13 @@ public Ansi render(final String text) {
}
/**
- * String formats and renders the supplied arguments. Uses the {@link AnsiRenderer}
+ * String formats and renders the supplied arguments. Uses the {@link AnsiRenderer}
* to generate the ANSI escape sequences.
*
- * @param text format
- * @param args arguments
- * @return this
- *
+ * @param text format
+ * @param args arguments
+ * @return this
+ *
* @since 1.1
*/
public Ansi render(final String text, Object... args) {
@@ -686,65 +689,65 @@ public Ansi render(final String text, Object... args) {
return this;
}
- @Override
- public String toString() {
- flushAttributes();
- return builder.toString();
- }
-
- ///////////////////////////////////////////////////////////////////
- // Private Helper Methods
- ///////////////////////////////////////////////////////////////////
-
- private Ansi appendEscapeSequence(char command) {
- flushAttributes();
- builder.append(FIRST_ESC_CHAR);
- builder.append(SECOND_ESC_CHAR);
- builder.append(command);
- return this;
- }
-
- private Ansi appendEscapeSequence(char command, int option) {
- flushAttributes();
- builder.append(FIRST_ESC_CHAR);
- builder.append(SECOND_ESC_CHAR);
- builder.append(option);
- builder.append(command);
- return this;
- }
-
- private Ansi appendEscapeSequence(char command, Object... options) {
- flushAttributes();
- return _appendEscapeSequence(command, options);
- }
-
- private void flushAttributes() {
- if( attributeOptions.isEmpty() )
- return;
- if (attributeOptions.size() == 1 && attributeOptions.get(0) == 0) {
- builder.append(FIRST_ESC_CHAR);
- builder.append(SECOND_ESC_CHAR);
- builder.append('m');
- } else {
- _appendEscapeSequence('m', attributeOptions.toArray());
- }
- attributeOptions.clear();
- }
-
- private Ansi _appendEscapeSequence(char command, Object... options) {
- builder.append(FIRST_ESC_CHAR);
- builder.append(SECOND_ESC_CHAR);
- int size = options.length;
- for (int i = 0; i < size; i++) {
- if (i != 0) {
- builder.append(';');
- }
- if (options[i] != null) {
- builder.append(options[i]);
- }
- }
- builder.append(command);
- return this;
- }
+ @Override
+ public String toString() {
+ flushAttributes();
+ return builder.toString();
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ // Private Helper Methods
+ ///////////////////////////////////////////////////////////////////
+
+ private Ansi appendEscapeSequence(char command) {
+ flushAttributes();
+ builder.append(FIRST_ESC_CHAR);
+ builder.append(SECOND_ESC_CHAR);
+ builder.append(command);
+ return this;
+ }
+
+ private Ansi appendEscapeSequence(char command, int option) {
+ flushAttributes();
+ builder.append(FIRST_ESC_CHAR);
+ builder.append(SECOND_ESC_CHAR);
+ builder.append(option);
+ builder.append(command);
+ return this;
+ }
+
+ private Ansi appendEscapeSequence(char command, Object... options) {
+ flushAttributes();
+ return _appendEscapeSequence(command, options);
+ }
+
+ private void flushAttributes() {
+ if (attributeOptions.isEmpty())
+ return;
+ if (attributeOptions.size() == 1 && attributeOptions.get(0) == 0) {
+ builder.append(FIRST_ESC_CHAR);
+ builder.append(SECOND_ESC_CHAR);
+ builder.append('m');
+ } else {
+ _appendEscapeSequence('m', attributeOptions.toArray());
+ }
+ attributeOptions.clear();
+ }
+
+ private Ansi _appendEscapeSequence(char command, Object... options) {
+ builder.append(FIRST_ESC_CHAR);
+ builder.append(SECOND_ESC_CHAR);
+ int size = options.length;
+ for (int i = 0; i < size; i++) {
+ if (i != 0) {
+ builder.append(';');
+ }
+ if (options[i] != null) {
+ builder.append(options[i]);
+ }
+ }
+ builder.append(command);
+ return this;
+ }
}
diff --git a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
index c3fdddbe..03ccf15f 100644
--- a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
+++ b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
@@ -28,13 +28,13 @@
/**
* Provides consistent access to an ANSI aware console PrintStream.
- *
+ *
* @author Hiram Chirino
* @since 1.0
*/
public class AnsiConsole {
- public static final PrintStream system_out = System.out;
+ public static final PrintStream system_out = System.out;
public static final PrintStream out = new PrintStream(wrapOutputStream(system_out));
public static final PrintStream system_err = System.err;
@@ -42,122 +42,123 @@ public class AnsiConsole {
private static int installed;
- private AnsiConsole() {}
+ private AnsiConsole() {
+ }
- public static OutputStream wrapOutputStream(final OutputStream stream) {
- return wrapOutputStream(stream, STDOUT_FILENO);
- }
+ public static OutputStream wrapOutputStream(final OutputStream stream) {
+ return wrapOutputStream(stream, STDOUT_FILENO);
+ }
- public static OutputStream wrapOutputStream(final OutputStream stream, int fileno) {
+ public static OutputStream wrapOutputStream(final OutputStream stream, int fileno) {
// If the jansi.passthrough property is set, then don't interpret
// any of the ansi sequences.
- if( Boolean.getBoolean("jansi.passthrough") ) {
- return stream;
+ if (Boolean.getBoolean("jansi.passthrough")) {
+ return stream;
}
// If the jansi.strip property is set, then we just strip the
// the ansi escapes.
- if( Boolean.getBoolean("jansi.strip") ) {
- return new AnsiOutputStream(stream);
+ if (Boolean.getBoolean("jansi.strip")) {
+ return new AnsiOutputStream(stream);
+ }
+
+ String os = System.getProperty("os.name");
+ if (os.startsWith("Windows") && !isCygwin()) {
+
+ // On windows we know the console does not interpret ANSI codes..
+ try {
+ return new WindowsAnsiOutputStream(stream);
+ } catch (Throwable ignore) {
+ // this happens when JNA is not in the path.. or
+ // this happens when the stdout is being redirected to a file.
+ }
+
+ // Use the ANSIOutputStream to strip out the ANSI escape sequences.
+ return new AnsiOutputStream(stream);
}
- String os = System.getProperty("os.name");
- if( os.startsWith("Windows") && !isCygwin() ) {
-
- // On windows we know the console does not interpret ANSI codes..
- try {
- return new WindowsAnsiOutputStream(stream);
- } catch (Throwable ignore) {
- // this happens when JNA is not in the path.. or
- // this happens when the stdout is being redirected to a file.
- }
-
- // Use the ANSIOutputStream to strip out the ANSI escape sequences.
- return new AnsiOutputStream(stream);
- }
-
- // We must be on some Unix variant, including Cygwin or MSYS(2) on Windows...
- try {
- // If the jansi.force property is set, then we force to output
- // the ansi escapes for piping it into ansi color aware commands (e.g. less -r)
- boolean forceColored = Boolean.getBoolean("jansi.force");
- // If we can detect that stdout is not a tty.. then setup
- // to strip the ANSI sequences..
- int rc = isatty(fileno);
- if( !isCygwin() && !forceColored && rc == 0 ) {
- return new AnsiOutputStream(stream);
- }
-
- // These erros happen if the JNI lib is not available for your platform.
+ // We must be on some Unix variant, including Cygwin or MSYS(2) on Windows...
+ try {
+ // If the jansi.force property is set, then we force to output
+ // the ansi escapes for piping it into ansi color aware commands (e.g. less -r)
+ boolean forceColored = Boolean.getBoolean("jansi.force");
+ // If we can detect that stdout is not a tty.. then setup
+ // to strip the ANSI sequences..
+ int rc = isatty(fileno);
+ if (!isCygwin() && !forceColored && rc == 0) {
+ return new AnsiOutputStream(stream);
+ }
+
+ // These erros happen if the JNI lib is not available for your platform.
} catch (NoClassDefFoundError ignore) {
- } catch (UnsatisfiedLinkError ignore) {
- }
-
- // By default we assume your Unix tty can handle ANSI codes.
- // Just wrap it up so that when we get closed, we reset the
- // attributes.
- return new FilterOutputStream(stream) {
- @Override
- public void close() throws IOException {
- write(AnsiOutputStream.REST_CODE);
- flush();
- super.close();
- }
- };
- }
-
- private static boolean isCygwin() {
- String term = System.getenv("TERM");
- return term != null && term.equals("xterm");
- }
-
- /**
- * If the standard out natively supports ANSI escape codes, then this just
- * returns System.out, otherwise it will provide an ANSI aware PrintStream
- * which strips out the ANSI escape sequences or which implement the escape
- * sequences.
- *
- * @return a PrintStream which is ANSI aware.
- */
- public static PrintStream out() {
- return out;
- }
+ } catch (UnsatisfiedLinkError ignore) {
+ }
+
+ // By default we assume your Unix tty can handle ANSI codes.
+ // Just wrap it up so that when we get closed, we reset the
+ // attributes.
+ return new FilterOutputStream(stream) {
+ @Override
+ public void close() throws IOException {
+ write(AnsiOutputStream.REST_CODE);
+ flush();
+ super.close();
+ }
+ };
+ }
+
+ private static boolean isCygwin() {
+ String term = System.getenv("TERM");
+ return term != null && term.equals("xterm");
+ }
/**
- * If the standard out natively supports ANSI escape codes, then this just
- * returns System.err, otherwise it will provide an ANSI aware PrintStream
- * which strips out the ANSI escape sequences or which implement the escape
- * sequences.
- *
- * @return a PrintStream which is ANSI aware.
- */
+ * If the standard out natively supports ANSI escape codes, then this just
+ * returns System.out, otherwise it will provide an ANSI aware PrintStream
+ * which strips out the ANSI escape sequences or which implement the escape
+ * sequences.
+ *
+ * @return a PrintStream which is ANSI aware.
+ */
+ public static PrintStream out() {
+ return out;
+ }
+
+ /**
+ * If the standard out natively supports ANSI escape codes, then this just
+ * returns System.err, otherwise it will provide an ANSI aware PrintStream
+ * which strips out the ANSI escape sequences or which implement the escape
+ * sequences.
+ *
+ * @return a PrintStream which is ANSI aware.
+ */
public static PrintStream err() {
return err;
}
-
- /**
- * Install Console.out to System.out.
- */
- synchronized static public void systemInstall() {
- installed++;
- if( installed==1 ) {
- System.setOut(out);
+
+ /**
+ * Install Console.out to System.out.
+ */
+ synchronized static public void systemInstall() {
+ installed++;
+ if (installed == 1) {
+ System.setOut(out);
System.setErr(err);
- }
- }
-
- /**
- * undo a previous {@link #systemInstall()}. If {@link #systemInstall()} was called
- * multiple times, it {@link #systemUninstall()} must call the same number of times before
- * it is actually uninstalled.
- */
- synchronized public static void systemUninstall() {
- installed--;
- if( installed==0 ) {
- System.setOut(system_out);
+ }
+ }
+
+ /**
+ * undo a previous {@link #systemInstall()}. If {@link #systemInstall()} was called
+ * multiple times, it {@link #systemUninstall()} must call the same number of times before
+ * it is actually uninstalled.
+ */
+ synchronized public static void systemUninstall() {
+ installed--;
+ if (installed == 0) {
+ System.setOut(system_out);
System.setErr(system_err);
- }
- }
-
+ }
+ }
+
}
diff --git a/jansi/src/main/java/org/fusesource/jansi/AnsiOutputStream.java b/jansi/src/main/java/org/fusesource/jansi/AnsiOutputStream.java
index d1d9338f..3fb76536 100644
--- a/jansi/src/main/java/org/fusesource/jansi/AnsiOutputStream.java
+++ b/jansi/src/main/java/org/fusesource/jansi/AnsiOutputStream.java
@@ -26,488 +26,491 @@
/**
* A ANSI output stream extracts ANSI escape codes written to
* an output stream.
- *
+ *
* For more information about ANSI escape codes, see:
* http://en.wikipedia.org/wiki/ANSI_escape_code
- *
+ *
* This class just filters out the escape codes so that they are not
* sent out to the underlying OutputStream. Subclasses should
* actually perform the ANSI escape behaviors.
- *
+ *
* @author Hiram Chirino
* @author Joris Kuipers
* @since 1.0
*/
public class AnsiOutputStream extends FilterOutputStream {
- public static final byte [] REST_CODE = resetCode();
-
- public AnsiOutputStream(OutputStream os) {
- super(os);
- }
-
- private final static int MAX_ESCAPE_SEQUENCE_LENGTH=100;
- private byte[] buffer = new byte[MAX_ESCAPE_SEQUENCE_LENGTH];
- private int pos=0;
- private int startOfValue;
- private final ArrayList