Added AnsiEscapeCodeSequence.strip() to get the undecorated string.

This commit is contained in:
Jonathan Bernard 2016-03-11 07:33:37 -06:00
parent bbef072f8b
commit 4b3c20a913
2 changed files with 11 additions and 3 deletions

View File

@ -14,7 +14,7 @@ apply plugin: "ch.raffael.pegdown-doclet"
apply plugin: "maven" apply plugin: "maven"
group = "com.jdbernard" group = "com.jdbernard"
version = "4.3" version = "4.4"
repositories { repositories {
mavenLocal() mavenLocal()

View File

@ -6,6 +6,8 @@
*/ */
package com.jdbernard.util; package com.jdbernard.util;
import java.util.regex.Pattern;
/** /**
* The AnsiEscapeCodeSequence class is an extended wrapper around * The AnsiEscapeCodeSequence class is an extended wrapper around
* [ANSI escape codes]. * [ANSI escape codes].
@ -14,15 +16,21 @@ package com.jdbernard.util;
*/ */
public class AnsiEscapeCodeSequence { public class AnsiEscapeCodeSequence {
public StringBuilder value = new StringBuilder();
public static final String CSI = "\u001b["; public static final String CSI = "\u001b[";
public static final Pattern ANSI_SEQ_PATTERN =
Pattern.compile("\u001b\\[[^a-zA-Z]+[a-zA-Z]");
public static enum Colors { public static enum Colors {
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, EXT, DEFAULT } BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, EXT, DEFAULT }
public static enum Erase { ToEnd, ToBeginning, All } public static enum Erase { ToEnd, ToBeginning, All }
public static String strip(String input) {
return ANSI_SEQ_PATTERN.matcher(input).replaceAll(""); }
public StringBuilder value = new StringBuilder();
public String toString() { return value.toString(); } public String toString() { return value.toString(); }
// Multiple methods for various forms of SGR // Multiple methods for various forms of SGR