0.0.6 • Published 8 years ago
sgr-parser v0.0.6
sgr-parser
Parse console output which includes escape sequence.
Install
npm install sgr-parserHow to use
SGRParser takes two constructor parameters.
keepState: Keep previous state while continuous parsing.handleCR: Deal CR(0x0d) code asESC[2K(Remove current line.)
SGRParser has following two methods.
- tokenize(str: string): Array;
- It returns 3 kind of Token(StringToken, EscapeToken, ErrorToken)
- StringToken has
strproperty. It holds tokenized string. - EscapeToken has
optionsproperty andcodeproperty. options is array of number. code is code of key. - ErrorToken means invalid EscapeSequence. It is almost same as StringToken.
- parse(str)
- It returns Array of Line object.
- Line object has following four properties.
str: stringclassname: It holds sgr classname. (e.g.sgr-33-m)newLine:truemeans LF exists before this string.removeLine: If the escape sequenceESC[2Kexists, it will beLine("", "", false, true).- Other escapes except
ESC[[n]mwill be ignored.
var SGRParser = require("sgr-parser");
var input = "\u001b[31mtest\u001b[0m";
var lines = new SGRParser(true, true).parse(input); // [Line("test", "sgr-31-m", false, false)]