public class AnsiEscapeParser
extends java.lang.Object
AnsiEscapeParser class wraps calls of JCFunc-library's functions in itself. Workflow: 1) create new parser with some parameters (choose parsing MODE) 2) use: - "touch()" or "matches()" for escaped sequencies' searching in input line - "parse()" for parsing escaped sequencies in input line - "processSGRparameters()" if found escaped sequence is SGR (color) function 3) user may change "on-the-fly": - parser's behaviour (ignore, remove, parse) - set of parsing sequencies 4) user cann't change "on-the-fly" parsing MODE.
Modifier and Type | Class and Description |
---|---|
static class |
AnsiEscapeParser.Behaviour
Behaviour class describes parser's behaviour
|
Constructor and Description |
---|
AnsiEscapeParser(java.awt.Color defFColor,
java.awt.Color defBColor)
This constructor gets parser's properties from Console's file of properties.
|
AnsiEscapeParser(int ansi_mode,
AnsiEscapeParser.Behaviour behaviour,
CF[] func_arr,
java.awt.Color defFColor,
java.awt.Color defBColor)
Parser's state is decribed by following properties:
|
Modifier and Type | Method and Description |
---|---|
AnsiEscapeParser.Behaviour |
getBehaviour() |
java.awt.Color |
getDefaultBColor() |
java.awt.Color |
getDefaultFColor() |
boolean |
isBehaviour(AnsiEscapeParser.Behaviour behaviour) |
boolean |
matches(java.lang.String line) |
java.util.ArrayList<Description> |
parse(java.lang.String line) |
java.util.ArrayList<Description> |
parse(java.lang.String line,
boolean ignoreSequences) |
javax.swing.text.SimpleAttributeSet |
processSGRparameters(int[] parameters,
javax.swing.text.SimpleAttributeSet baseAttrs)
This method is handler of only one (but most popular) function: SGR function.
|
java.lang.String |
remove(java.lang.String line,
CF func) |
java.lang.String |
removeAll(java.lang.String line) |
void |
setBehaviour(AnsiEscapeParser.Behaviour newBehaviour) |
void |
setDefaultBColor(java.awt.Color newColor) |
void |
setDefaultFColor(java.awt.Color newColor) |
void |
setFunctions(CF... cmds) |
boolean |
touch(AnsiEscapeParser.Behaviour behaviour,
java.lang.String line)
Check two things:
|
public AnsiEscapeParser(int ansi_mode, AnsiEscapeParser.Behaviour behaviour, CF[] func_arr, java.awt.Color defFColor, java.awt.Color defBColor)
Parser's state is decribed by following properties:
ansi_mode
- - type of escaped sequencies (what kind of escaped sequencies parser processes?)behaviour
- - parser's behaviour proper (what parser does with found sequencies?)func_arr
- - array of processing functions (escaped sequence == ESC + function)defFColor
- - default foreground color (for SGR-function)defBColor
- - default background color (for SGR-function)jcfunc.Sequences.MODE_7BIT
,
Usually use 7-bit mode.
,
AnsiEscapeParser.Behaviour
,
CF
public AnsiEscapeParser(java.awt.Color defFColor, java.awt.Color defBColor)
This constructor gets parser's properties from Console's file of properties.
defFColor
- - default foreground color (for SGR-function)defBColor
- - default background color (for SGR-function)public boolean isBehaviour(AnsiEscapeParser.Behaviour behaviour)
public AnsiEscapeParser.Behaviour getBehaviour()
public java.awt.Color getDefaultFColor()
public java.awt.Color getDefaultBColor()
public boolean matches(java.lang.String line)
public java.util.ArrayList<Description> parse(java.lang.String line)
public java.util.ArrayList<Description> parse(java.lang.String line, boolean ignoreSequences)
public java.lang.String remove(java.lang.String line, CF func)
public java.lang.String removeAll(java.lang.String line)
public boolean touch(AnsiEscapeParser.Behaviour behaviour, java.lang.String line)
Check two things:
behaviour
- - is it the current parser's behaviour?line
- - are there any matches?public void setBehaviour(AnsiEscapeParser.Behaviour newBehaviour)
public void setDefaultFColor(java.awt.Color newColor)
public void setDefaultBColor(java.awt.Color newColor)
public void setFunctions(CF... cmds)
public javax.swing.text.SimpleAttributeSet processSGRparameters(int[] parameters, javax.swing.text.SimpleAttributeSet baseAttrs)
This method is handler of only one (but most popular) function: SGR function. SGR function controls substring's color and style. Usually text with SGR function looks like that: This is #SGR#only example#/SGR#: you'll never see tag "#SGR#" in your texts. There is used some "base" text style for whole line but under tag "#SGR#" base style is changed. Parameters:
parameters
- - array of parameters; usually it is parser's working result.baseAttrs
- - base text's styleDescription