Package Exports
- node-ansiparser
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-ansiparser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
A parser for ANSI escape code sequences. It implements the parser described here http://vt100.net/emu/dec_ansi_parser (thanks to Paul Williams).
The parser uses callbacks to methods of a given terminal object.
NOTE: If the terminal object doesnt provide the needed methods the parser will inject dummy methods to keep working.
Methods a terminal should implement:
- inst_p(s) print string s
- inst_o(s) osc call
- inst_x(flag) trigger one char method
- inst_c(collected, params, flag) trigger csi method
- inst_e(collected, flag) trigger esc method
- inst_H(collected, params, flag) dcs command
- inst_P(data) dcs put
- inst_U() dcs leave
Methods
- parse(s) parse the given string and call the terminal methods
- reset() reset the parser
Usage example
This example uses a simple terminal object, which just logs the actions:
var AnsiParser = require('node-ansiparser');
var terminal = {
inst_p: function(s) {console.log('print', s);},
inst_o: function(s) {console.log('osc', s);},
inst_x: function(flag) {console.log('execute', flag.charCodeAt(0));},
inst_c: function(collected, params, flag) {console.log('csi', collected, params, flag);},
inst_e: function(collected, flag) {console.log('esc', collected, flag);},
inst_H: function(collected, params, flag) {console.log('dcs-Hook', collected, params, flag);},
inst_P: function(dcs) {console.log('dcs-Put', dcs);},
inst_U: function() {console.log('dcs-Unhook');}
};
var parser = new AnsiParser(terminal);
parser.parse('\x1b[31mHello World!\n');
parser.parse('\x1bP0!u%5\x1b\'');
For a more complex terminal see node-ansiterminal.