pax_global_header 0000666 0000000 0000000 00000000064 13450235617 0014520 g ustar 00root root 0000000 0000000 52 comment=a454e8035bccfc843b9ed2b185167eafb55bcf99
node-ansi-up-4.0.3+dfsg/ 0000775 0000000 0000000 00000000000 13450235617 0014742 5 ustar 00root root 0000000 0000000 node-ansi-up-4.0.3+dfsg/.gitignore 0000664 0000000 0000000 00000000016 13450235617 0016727 0 ustar 00root root 0000000 0000000 node_modules
node-ansi-up-4.0.3+dfsg/.vscode/ 0000775 0000000 0000000 00000000000 13450235617 0016303 5 ustar 00root root 0000000 0000000 node-ansi-up-4.0.3+dfsg/.vscode/launch.json 0000664 0000000 0000000 00000001555 13450235617 0020456 0 ustar 00root root 0000000 0000000 {
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/node_modules/.bin/mocha",
"args": [
"--require", "should",
"test/ansi_up-test.js"
],
"cwd": "${workspaceRoot}",
"outDir": "${workspaceRoot}/",
"sourceMaps": true
},
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"port": 5858,
"outDir": "${workspaceRoot}/"
}
]
} node-ansi-up-4.0.3+dfsg/.vscode/tasks.json 0000664 0000000 0000000 00000000410 13450235617 0020316 0 ustar 00root root 0000000 0000000 {
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "./node_modules/.bin/tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "always"
} node-ansi-up-4.0.3+dfsg/Makefile 0000664 0000000 0000000 00000001023 13450235617 0016376 0 ustar 00root root 0000000 0000000
SOURCE = *.ts
TESTS = test/*.js
REPORTER = dot
typescript:
./node_modules/.bin/tsc -p .
cat ./umd.header ./dist/ansi_up.js ./umd.footer > ansi_up.js
mv ./dist/ansi_up.js ./dist/ansi_up.js.include
node ./scripts/fix-typings.js
test:
@NODE_ENV=test ./node_modules/.bin/mocha \
--require should \
--reporter $(REPORTER) \
$(TESTS)
test_verbose:
@NODE_ENV=test ./node_modules/.bin/mocha \
--require should \
--reporter spec \
$(TESTS)
clean:
rm -rf ./node_modules ansi_up.js
.PHONY: test
node-ansi-up-4.0.3+dfsg/Readme.md 0000664 0000000 0000000 00000022406 13450235617 0016465 0 ustar 00root root 0000000 0000000 # ansi_up.js
__ansi_up__ is a simple, easy to use library that provides a streaming API to
transform text containing
[ANSI color escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors) into proper HTML.
It can also transform any text that looks like a URL into an HTML anchor tag.
This module is a single Javascript file with no dependencies. It is a UMD style module so it
can be utilized in a browser, in node.js (CommonJS), or with AMD (require.js). The source code
was compiled from TypeScript and its type description ships with the NPM. This code has been used in production since 2011 and is actively maintained.
For example, turn this terminal output:
ESC[1;Foreground
[1;30m 30 [1;30m 30 [1;30m 30 [1;30m 30 [1;30m 30 [1;30m 30 [1;30m 30 [1;30m 30 [0m
[1;31m 31 [1;31m 31 [1;31m 31 [1;31m 31 [1;31m 31 [1;31m 31 [1;31m 31 [1;31m 31 [0m
[1;32m 32 [1;32m 32 [1;32m 32 [1;32m 32 [1;32m 32 [1;32m 32 [1;32m 32 [1;32m 32 [0m
...
...into this browser output:

## Browser Example
```HTML
```
## Node Example
```JavaScript
var AU = require('ansi_up');
var ansi_up = new AU.default;
var txt = "\n\n\033[1;33;40m 33;40 \033[1;33;41m 33;41 \033[1;33;42m 33;42 \033[1;33;43m 33;43 \033[1;33;44m 33;44 \033[1;33;45m 33;45 \033[1;33;46m 33;46 \033[1m\033[0\n\n\033[1;33;42m >> Tests OK\n\n"
var html = ansi_up.ansi_to_html(txt);
```
More examples are in the 'examples' directory in the repo.
## Typescript Example
```TypeScript
import {
default as AnsiUp
} from 'ansi_up';
const ansi_up = new AnsiUp();
const txt = "\n\n\x1B[1;33;40m 33;40 \x1B[1;33;41m 33;41 \x1B[1;33;42m 33;42 \x1B[1;33;43m 33;43 \x1B[1;33;44m 33;44 \x1B[1;33;45m 33;45 \x1B[1;33;46m 33;46 \x1B[1m\x1B[0\n\n\x1B[1;33;42m >> Tests OK\n\n"
let html = ansi_up.ansi_to_html(txt);
```
## Installation
$ npm install ansi_up
## Versions
* Version 4.0 - Re-architect code to support terminal linkify escapes.
* Version 3.0 - now treats ANSI bold sequences as CSS font-weight:bold
* Version 2.0 - moved to a stateful, streaming version of the API
* Version 1.3 - was the last of the older, deprecated API.
## Quick Start
1. Use whatever module system to import the _ansi_up_ module.
2. Instantiate the object.
3. For every piece of input that arrives, call **ansi_to_html**.
4. Append the emitted HTML to the previous HTML already emitted.
## API Methods
In order to use _ansi_up_, you must Instantiate an object using your given module
system.
#### ansi_to_html (txt)
This replaces ANSI terminal escape codes/sequences with SPAN tags that wrap the content.
This function only interprets ANSI SGR (Select Graphic Rendition) codes that can be represented in HTML. For example, cursor movement codes are ignored and hidden from output.
The default style uses colors that are very close to the prescribed standard. The standard assumes that the text will have a black background. These colors are set as inline styles on the SPAN tags. Another option is to set 'use_classes: true' in the options argument. This will instead set classes on the spans so the colors can be set via CSS. The class names used are of the format ````ansi-*-fg/bg```` and ````ansi-bright-*-fg/bg```` where * is the colour name, i.e black/red/green/yellow/blue/magenta/cyan/white. See the examples directory for a complete CSS theme for these classes.
#### ansi_to_text (txt) DEPRECATED
This simply removes the ANSI escape codes from the stream.
No escaping is done.
#### linkify(txt) DEPRECATED
** DEPRECATED ** - it turns out that this makes the code much more difficult to achieve while providing
a streaming API. I should do a write-up on this at some point. For now, I leave this documentation here.
If the developer knows what they are doing and want this functionality, they can find the code to do this
in the history of this repo.
This replaces any links in the text with anchor tags that display the link.
Only strings starting with 'http' or 'https', and surrounded by whitespace are
considered valid patterns.
You should only call this method if you can guarantee that the full URL
will be passed into ansi_to_html(). If the URL is split along a buffer
boundary, then the wrong URL will be 'linkified'.
## Properties
#### escape_for_html
(default: true)
This does the minimum escaping of text to make it compliant with HTML.
In particular, the '&','<', and '>' characters are escaped.
#### use_classes
(default: false)
This causes the SPAN tags to use class names for the color style instead
of specified RGB values.
## API Overview
On a high level, _ansi_up_ takes a stream of text and transforms it proper HTML with colors.
It does this by buffering the data and performing multiple passes over the
stream. Each time it consumes data, it may or may not emit HTML. This HTML will always be
proper HTML.
Because this process requires buffering (ie. stateful), you must insantiate an _ansi_up_ object
in order to begin. Also, text may be received later that is styled by a previous.
The first pass converts characters that are unsafe for HTML into their equivalents. It will only
convert '&', '<', and '>' characters. This pass is optional, and is on by default.
The second pass converts any ANSI color sequences to HTML spans. It does this by recognizing
what is termed as ANSI **SGR** codes. All ANSI sequences (SGR and non-SGR) are removed from the
output stream. The SGR codes create HTML **SPAN** tags to surround text that is styled by those
codes. If the ANSI sequence is incomplete, it will be held in _ansi_up_'s internal buffer
until new data is received to complete it.
The third and final pass transforms URLs to HTML anchors. This will also buffer output until a non URL
character is received. This pass is optional, and is off by default.
### Recommended Style of Use
There are two ways to stream this data to a web page. A push model or a pull model.
I have personally used a pull model to 'tail' a file.
In my 'pull' model, I had a process generating a log file on a remote machine.
I had a web server running on the same machine. I developed a simple page
that used AJAX to poll the web server periodically. Specifically I used an
HTTP/1.1 GET request with RFC 7233 Range query. The server would return
either range response.
I would then process each chunk received with _ansi_up_, and append the new
spans to the innerHTML of a PRE tag.
### UTF8 note
One last important note, _ansi_up_ takes its input in the form of a Javascript string.
These strings are UTF8. When you take the output of some program and send it to
Javascript, there will be buffering. Be sure to not send incomplete UTF8 sequences or
Javascript will ignore or drop the sequence from the stream when it converts it to a
string.
_ansi_up_ should be called via the functions defined on the module. It is recommended that the HTML is rendered with a monospace font and black background. See the examples, for a basic theme as a CSS definition.
At the same, it also properly escapes HTML unsafe characters (&,<,>,etc.) into their proper HTML representation.
## Building
To build, a simple Makefile handles it all.
```shell
$ make
```
## Running tests
To run the tests for _ansi_up_, run `npm install` to install dev dependencies. Then:
```shell
$ make test
```
## Credits
This code was developed by Dru Nelson ().
Thanks goes to the following contributors for their patches:
- AIZAWA Hina ()
- James R. White ()
- Aaron Stone ()
- Maximilian Antoni ()
- Jim Bauwens ()
- Jacek Jędrzejewski ()
## License
(The MIT License)
Copyright (c) 2011 Dru Nelson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
node-ansi-up-4.0.3+dfsg/ansi_up.d.ts 0000664 0000000 0000000 00000002146 13450235617 0017175 0 ustar 00root root 0000000 0000000 interface AU_Color {
rgb: number[];
class_name: string;
}
interface TextWithAttr {
fg: AU_Color;
bg: AU_Color;
bold: boolean;
text: string;
}
declare enum PacketKind {
EOS = 0,
Text = 1,
Incomplete = 2,
ESC = 3,
Unknown = 4,
SGR = 5,
OSCURL = 6
}
interface TextPacket {
kind: PacketKind;
text: string;
url: string;
}
export declare class AnsiUp {
VERSION: string;
private ansi_colors;
private palette_256;
private fg;
private bg;
private bold;
private _use_classes;
private _escape_for_html;
private _csi_regex;
private _osc_st;
private _osc_regex;
private _url_whitelist;
private _buffer;
constructor();
use_classes: boolean;
escape_for_html: boolean;
url_whitelist: {};
private setup_palettes;
private escape_txt_for_html;
append_buffer(txt: string): void;
get_next_packet(): TextPacket;
ansi_to_html(txt: string): string;
private with_state;
private process_ansi;
transform_to_html(fragment: TextWithAttr): string;
private process_hyperlink;
}
export {};
node-ansi-up-4.0.3+dfsg/ansi_up.js.map 0000664 0000000 0000000 00000033671 13450235617 0017524 0 ustar 00root root 0000000 0000000 {"version":3,"file":"ansi_up.js","sourceRoot":"","sources":["ansi_up.ts"],"names":[],"mappings":"AAMA,YAAY,CAAC;AAwBb,IAAK,UAQJ;AARD,WAAK,UAAU;IACX,yCAAG,CAAA;IACH,2CAAI,CAAA;IACJ,uDAAU,CAAA;IACV,yCAAG,CAAA;IACH,iDAAO,CAAA;IACP,yCAAG,CAAA;IACH,+CAAM,CAAA;AACV,CAAC,EARI,UAAU,KAAV,UAAU,QAQd;AAYD,MAAM,OAAO,MAAM;IA6Bf;QA3BA,YAAO,GAAG,OAAO,CAAC;QA8Bd,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAE7B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QAEzB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAElB,IAAI,CAAC,cAAc,GAAG,EAAE,MAAM,EAAC,CAAC,EAAE,OAAO,EAAC,CAAC,EAAE,CAAC;IAClD,CAAC;IAED,IAAI,WAAW,CAAC,GAAW;QAEvB,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC;IAC5B,CAAC;IAED,IAAI,WAAW;QAEX,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,IAAI,eAAe,CAAC,GAAW;QAE3B,IAAI,CAAC,gBAAgB,GAAG,GAAG,CAAC;IAChC,CAAC;IAED,IAAI,eAAe;QAEf,OAAO,IAAI,CAAC,gBAAgB,CAAC;IACjC,C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ru/ansi_up
*/
"use strict";
//
// INTERFACES
//
interface AU_Color
{
rgb:number[];
class_name:string;
}
// Represents the output of process_ansi(): a snapshot of the AnsiUp state machine
// at a given point in time, which wraps a fragment of text. This would allow deferred
// processing of text fragments and colors, if ever needed.
interface TextWithAttr {
fg:AU_Color;
bg:AU_Color;
bold:boolean;
text:string;
}
// Used internally when breaking up the raw text into packets
enum PacketKind {
EOS,
Text,
Incomplete, // An Incomplete ESC sequence
ESC, // A single ESC char - random
Unknown, // A valid CSI but not an SGR code
SGR, // Select Graphic Rendition
OSCURL, // Operating System Command
}
interface TextPacket {
kind:PacketKind;
text:string;
url:string;
}
//
// MAIN CLASS
//
class AnsiUp
{
VERSION = "4.0.2";
//
// *** SEE README ON GITHUB FOR PUBLIC API ***
//
// 256 Colors Palette
// CSS RGB strings - ex. "255, 255, 255"
private ansi_colors:AU_Color[][];
private palette_256:AU_Color[];
private fg:AU_Color;
private bg:AU_Color;
private bold:boolean;
private _use_classes:boolean;
private _escape_for_html;
private _csi_regex:RegExp;
private _osc_st:RegExp;
private _osc_regex:RegExp;
private _url_whitelist:{};
private _buffer:string;
constructor()
{
// All construction occurs here
this.setup_palettes();
this._use_classes = false;
this._escape_for_html = true;
this.bold = false;
this.fg = this.bg = null;
this._buffer = '';
this._url_whitelist = { 'http':1, 'https':1 };
}
set use_classes(arg:boolean)
{
this._use_classes = arg;
}
get use_classes():boolean
{
return this._use_classes;
}
set escape_for_html(arg:boolean)
{
this._escape_for_html = arg;
}
get escape_for_html():boolean
{
return this._escape_for_html;
}
set url_whitelist(arg:{})
{
this._url_whitelist = arg;
}
get url_whitelist():{}
{
return this._url_whitelist;
}
private setup_palettes():void
{
this.ansi_colors =
[
// Normal colors
[
{ rgb: [ 0, 0, 0], class_name: "ansi-black" },
{ rgb: [187, 0, 0], class_name: "ansi-red" },
{ rgb: [ 0, 187, 0], class_name: "ansi-green" },
{ rgb: [187, 187, 0], class_name: "ansi-yellow" },
{ rgb: [ 0, 0, 187], class_name: "ansi-blue" },
{ rgb: [187, 0, 187], class_name: "ansi-magenta" },
{ rgb: [ 0, 187, 187], class_name: "ansi-cyan" },
{ rgb: [255, 255, 255], class_name: "ansi-white" }
],
// Bright colors
[
{ rgb: [ 85, 85, 85], class_name: "ansi-bright-black" },
{ rgb: [255, 85, 85], class_name: "ansi-bright-red" },
{ rgb: [ 0, 255, 0], class_name: "ansi-bright-green" },
{ rgb: [255, 255, 85], class_name: "ansi-bright-yellow" },
{ rgb: [ 85, 85, 255], class_name: "ansi-bright-blue" },
{ rgb: [255, 85, 255], class_name: "ansi-bright-magenta" },
{ rgb: [ 85, 255, 255], class_name: "ansi-bright-cyan" },
{ rgb: [255, 255, 255], class_name: "ansi-bright-white" }
]
];
this.palette_256 = [];
// Index 0..15 : Ansi-Colors
this.ansi_colors.forEach( palette => {
palette.forEach( rec => {
this.palette_256.push(rec);
});
});
// Index 16..231 : RGB 6x6x6
// https://gist.github.com/jasonm23/2868981#file-xterm-256color-yaml
let levels = [0, 95, 135, 175, 215, 255];
for (let r = 0; r < 6; ++r) {
for (let g = 0; g < 6; ++g) {
for (let b = 0; b < 6; ++b) {
let col = {rgb:[levels[r], levels[g], levels[b]], class_name:'truecolor'};
this.palette_256.push(col);
}
}
}
// Index 232..255 : Grayscale
let grey_level = 8;
for (let i = 0; i < 24; ++i, grey_level += 10) {
let gry = {rgb:[grey_level, grey_level, grey_level], class_name:'truecolor'};
this.palette_256.push(gry);
}
}
private escape_txt_for_html(txt:string):string
{
return txt.replace(/[&<>]/gm, (str) => {
if (str === "&") return "&";
if (str === "<") return "<";
if (str === ">") return ">";
});
}
private append_buffer(txt:string) {
var str = this._buffer + txt;
this._buffer = str;
}
private get_next_packet():TextPacket {
var pkt =
{
kind: PacketKind.EOS,
text: '',
url: ''
} ;
var len = this._buffer.length;
if (len == 0)
return pkt;
var pos = this._buffer.indexOf("\x1B");
// The most common case, no ESC codes
if (pos == -1)
{
pkt.kind = PacketKind.Text;
pkt.text = this._buffer;
this._buffer = '';
return pkt;
}
if (pos > 0)
{
pkt.kind = PacketKind.Text;
pkt.text = this._buffer.slice(0, pos);
this._buffer = this._buffer.slice(pos);
return pkt;
}
// NOW WE HANDLE ESCAPES
if (pos == 0)
{
if (len == 1) // Lone ESC in Buffer, We don't know yet
{
pkt.kind = PacketKind.Incomplete;
return pkt;
}
var next_char = this._buffer.charAt(1);
// We treat this as a single ESC
// Which effecitvely shows
if ((next_char != '[') && (next_char != ']')) // DeMorgan
{
pkt.kind = PacketKind.ESC;
pkt.text = this._buffer.slice(0, 1);
this._buffer = this._buffer.slice(1);
return pkt;
}
// OK is this an SGR or OSC that we handle
// SGR CHECK
if (next_char == '[')
{
// We do this regex initialization here so
// we can keep the regex close to its use (Readability)
// All ansi codes are typically in the following format.
// We parse it and focus specifically on the
// graphics commands (SGR)
//
// CONTROL-SEQUENCE-INTRODUCER CSI (ESC, '[')
// PRIVATE-MODE-CHAR (!, <, >, ?)
// Numeric parameters separated by semicolons ('0' - '9', ';')
// Intermediate-modifiers (0x20 - 0x2f)
// COMMAND-CHAR (0x40 - 0x7e)
//
if (!this._csi_regex) {
this._csi_regex = rgx`
^ # beginning of line
#
# First attempt
(?: # legal sequence
\x1b\[ # CSI
([\x3c-\x3f]?) # private-mode char
([\d;]*) # any digits or semicolons
([\x20-\x2f]? # an intermediate modifier
[\x40-\x7e]) # the command
)
| # alternate (second attempt)
(?: # illegal sequence
\x1b\[ # CSI
[\x20-\x7e]* # anything legal
([\x00-\x1f:]) # anything illegal
)
`;
}
let match = this._buffer.match(this._csi_regex);
// This match is guaranteed to terminate (even on
// invalid input). The key is to match on legal and
// illegal sequences.
// The first alternate matches everything legal and
// the second matches everything illegal.
//
// If it doesn't match, then we have not received
// either the full sequence or an illegal sequence.
// If it does match, the presence of field 4 tells
// us whether it was legal or illegal.
if (match === null)
{
pkt.kind = PacketKind.Incomplete;
return pkt;
}
// match is an array
// 0 - total match
// 1 - private mode chars group
// 2 - digits and semicolons group
// 3 - command
// 4 - illegal char
if (match[4])
{
// Illegal sequence, just remove the ESC
pkt.kind = PacketKind.ESC;
pkt.text = this._buffer.slice(0, 1);
this._buffer = this._buffer.slice(1);
return pkt;
}
// If not a valid SGR, we don't handle
if ( (match[1] != '') || (match[3] != 'm'))
pkt.kind = PacketKind.Unknown;
else
pkt.kind = PacketKind.SGR;
pkt.text = match[2] // Just the parameters
var rpos = match[0].length;
this._buffer = this._buffer.slice(rpos);
return pkt;
}
// OSC CHECK
if (next_char == ']')
{
if ( (this._buffer.charAt(2) != '8')
|| (this._buffer.charAt(3) != ';') )
{
// This is not a match, so we'll just treat it as ESC
pkt.kind = PacketKind.ESC;
pkt.text = this._buffer.slice(0, 1);
this._buffer = this._buffer.slice(1);
return pkt;
}
// We do this regex initialization here so
// we can keep the regex close to its use (Readability)
// Matching a Hyperlink OSC with a regex is difficult
// because Javascript's regex engine doesn't support
// 'partial match' support.
//
// Therefore, we require the system to match the
// string-terminator(ST) before attempting a match.
// Once we find it, we attempt the Hyperlink-Begin
// match.
// If that goes ok, we scan forward for the next
// ST.
// Finally, we try to match it all and return
// the sequence.
// Also, it is important to note that we consider
// certain control characters as an invalidation of
// the entire sequence.
// We do regex initializations here so
// we can keep the regex close to its use (Readability)
// STRING-TERMINATOR
// This is likely to terminate in most scenarios
// because it will terminate on a newline
if (!this._osc_st) {
this._osc_st = rgxG`
(?: # legal sequence
(\x1b\\) # ESC \
| # alternate
(\x07) # BEL (what xterm did)
)
| # alternate (second attempt)
( # illegal sequence
[\x00-\x06] # anything illegal
| # alternate
[\x08-\x1a] # anything illegal
| # alternate
[\x1c-\x1f] # anything illegal
)
`;
}
// VERY IMPORTANT
// We do a stateful regex match with exec.
// If the regex is global, and it used with 'exec',
// then it will search starting at the 'lastIndex'
// If it matches, the regex can be used again to
// find the next match.
this._osc_st.lastIndex = 0;
{
let match = this._osc_st.exec( this._buffer );
if (match === null)
{
pkt.kind = PacketKind.Incomplete;
return pkt;
}
// If an illegal character was found, bail on the match
if (match[3])
{
// Illegal sequence, just remove the ESC
pkt.kind = PacketKind.ESC;
pkt.text = this._buffer.slice(0, 1);
this._buffer = this._buffer.slice(1);
return pkt;
}
}
// OK - we might have the prefix and URI
// Lets start our search for the next ST
// past this index
{
let match = this._osc_st.exec( this._buffer );
if (match === null)
{
pkt.kind = PacketKind.Incomplete;
return pkt;
}
// If an illegal character was found, bail on the match
if (match[3])
{
// Illegal sequence, just remove the ESC
pkt.kind = PacketKind.ESC;
pkt.text = this._buffer.slice(0, 1);
this._buffer = this._buffer.slice(1);
return pkt;
}
}
// OK, at this point we should have a FULL match!
//
// Lets try to match that now
if (!this._osc_regex) {
this._osc_regex = rgx`
^ # beginning of line
#
\x1b\]8; # OSC Hyperlink
[\x20-\x3a\x3c-\x7e]* # params (excluding ;)
; # end of params
([\x21-\x7e]{0,512}) # URL capture
(?: # ST
(?:\x1b\\) # ESC \
| # alternate
(?:\x07) # BEL (what xterm did)
)
([\x21-\x7e]+) # TEXT capture
\x1b\]8;; # OSC Hyperlink End
(?: # ST
(?:\x1b\\) # ESC \
| # alternate
(?:\x07) # BEL (what xterm did)
)
`;
}
let match = this._buffer.match(this._osc_regex);
if (match === null)
{
// Illegal sequence, just remove the ESC
pkt.kind = PacketKind.ESC;
pkt.text = this._buffer.slice(0, 1);
this._buffer = this._buffer.slice(1);
return pkt;
}
// match is an array
// 0 - total match
// 1 - URL
// 2 - Text
// If a valid SGR
pkt.kind = PacketKind.OSCURL;
pkt.url = match[1];
pkt.text = match[2];
var rpos = match[0].length;
this._buffer = this._buffer.slice(rpos);
return pkt;
}
}
}
ansi_to_html(txt:string):string {
this.append_buffer(txt);
var blocks:string[] = [];
while (true)
{
var packet = this.get_next_packet();
if ( (packet.kind == PacketKind.EOS)
|| (packet.kind == PacketKind.Incomplete) )
break;
//Drop single ESC or Unknown CSI
if ( (packet.kind == PacketKind.ESC)
|| (packet.kind == PacketKind.Unknown) )
continue;
if (packet.kind == PacketKind.Text)
blocks.push( this.transform_to_html(this.with_state(packet)) );
else
if (packet.kind == PacketKind.SGR)
this.process_ansi(packet);
else
if (packet.kind == PacketKind.OSCURL)
blocks.push( this.process_hyperlink(packet) );
}
return blocks.join("");
}
private with_state(pkt:TextPacket):TextWithAttr {
return { bold: this.bold, fg: this.fg, bg: this.bg, text: pkt.text };
}
private process_ansi(pkt:TextPacket)
{
// Ok - we have a valid "SGR" (Select Graphic Rendition)
let sgr_cmds = pkt.text.split(';');
// Each of these params affects the SGR state
// Why do we shift through the array instead of a forEach??
// ... because some commands consume the params that follow !
while (sgr_cmds.length > 0) {
let sgr_cmd_str = sgr_cmds.shift();
let num = parseInt(sgr_cmd_str, 10);
if (isNaN(num) || num === 0) {
this.fg = this.bg = null;
this.bold = false;
} else if (num === 1) {
this.bold = true;
} else if (num === 22) {
this.bold = false;
} else if (num === 39) {
this.fg = null;
} else if (num === 49) {
this.bg = null;
} else if ((num >= 30) && (num < 38)) {
this.fg = this.ansi_colors[0][(num - 30)];
} else if ((num >= 40) && (num < 48)) {
this.bg = this.ansi_colors[0][(num - 40)];
} else if ((num >= 90) && (num < 98)) {
this.fg = this.ansi_colors[1][(num - 90)];
} else if ((num >= 100) && (num < 108)) {
this.bg = this.ansi_colors[1][(num - 100)];
} else if (num === 38 || num === 48) {
// extended set foreground/background color
// validate that param exists
if (sgr_cmds.length > 0) {
// extend color (38=fg, 48=bg)
let is_foreground = (num === 38);
let mode_cmd = sgr_cmds.shift();
// MODE '5' - 256 color palette
if (mode_cmd === '5' && sgr_cmds.length > 0) {
let palette_index = parseInt(sgr_cmds.shift(), 10);
if (palette_index >= 0 && palette_index <= 255) {
if (is_foreground)
this.fg = this.palette_256[palette_index];
else
this.bg = this.palette_256[palette_index];
}
}
// MODE '2' - True Color
if (mode_cmd === '2' && sgr_cmds.length > 2) {
let r = parseInt(sgr_cmds.shift(), 10);
let g = parseInt(sgr_cmds.shift(), 10);
let b = parseInt(sgr_cmds.shift(), 10);
if ((r >= 0 && r <= 255) && (g >= 0 && g <= 255) && (b >= 0 && b <= 255)) {
let c = { rgb: [r,g,b], class_name: 'truecolor'};
if (is_foreground)
this.fg = c;
else
this.bg = c;
}
}
}
}
}
}
private transform_to_html(fragment:TextWithAttr):string {
let txt = fragment.text;
if (txt.length === 0)
return txt;
if (this._escape_for_html)
txt = this.escape_txt_for_html(txt);
// If colors not set, default style is used
if (!fragment.bold && fragment.fg === null && fragment.bg === null)
return txt;
let styles:string[] = [];
let classes:string[] = [];
let fg = fragment.fg;
let bg = fragment.bg;
// Note on bold: https://stackoverflow.com/questions/6737005/what-are-some-advantages-to-using-span-style-font-weightbold-rather-than-b?rq=1
if (fragment.bold)
styles.push('font-weight:bold')
if (!this._use_classes) {
// USE INLINE STYLES
if (fg)
styles.push(`color:rgb(${fg.rgb.join(',')})`);
if (bg)
styles.push(`background-color:rgb(${bg.rgb})`);
} else {
// USE CLASSES
if (fg) {
if (fg.class_name !== 'truecolor') {
classes.push(`${fg.class_name}-fg`);
} else {
styles.push(`color:rgb(${fg.rgb.join(',')})`);
}
}
if (bg) {
if (bg.class_name !== 'truecolor') {
classes.push(`${bg.class_name}-bg`);
} else {
styles.push(`background-color:rgb(${bg.rgb.join(',')})`);
}
}
}
let class_string = '';
let style_string = '';
if (classes.length)
class_string = ` class="${classes.join(' ')}"`;
if (styles.length)
style_string = ` style="${styles.join(';')}"`;
return `${txt}`;
};
private process_hyperlink(pkt:TextPacket):string
{
// Check URL scheme
let parts = pkt.url.split(':');
if (parts.length < 1)
return '';
if (! this._url_whitelist[parts[0]])
return '';
let result = `${this.escape_txt_for_html(pkt.text)}`;
return result;
}
}
//
// PRIVATE FUNCTIONS
//
// ES5 template string transformer
function rgx(tmplObj, ...subst) {
// Use the 'raw' value so we don't have to double backslash in a template string
let regexText:string = tmplObj.raw[0];
// Remove white-space and comments
let wsrgx = /^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm;
let txt2 = regexText.replace(wsrgx, '');
return new RegExp(txt2);
}
// ES5 template string transformer
// Multi-Line On
function rgxG(tmplObj, ...subst) {
// Use the 'raw' value so we don't have to double backslash in a template string
let regexText:string = tmplObj.raw[0];
// Remove white-space and comments
let wsrgx = /^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm;
let txt2 = regexText.replace(wsrgx, '');
return new RegExp(txt2, 'g');
}
node-ansi-up-4.0.3+dfsg/package.json 0000664 0000000 0000000 00000001200 13450235617 0017221 0 ustar 00root root 0000000 0000000 {
"name": "ansi_up",
"version": "4.0.1",
"description": "Convert ansi sequences in strings to colorful HTML",
"keywords": [
"ansi",
"html"
],
"author": "drudru ",
"license": "MIT",
"main": "./ansi_up.js",
"types": "./ansi_up.d.ts",
"repository": {
"type": "git",
"url": "git://github.com/drudru/ansi_up.git"
},
"bugs": {
"url": "http://github.com/drudru/ansi_up/issues"
},
"engines": {
"node": "*"
},
"scripts": {
"test": "make test",
"build": "make typescript"
},
"devDependencies": {
"mocha": "*",
"should": "*",
"typescript": "^3.0"
}
}
node-ansi-up-4.0.3+dfsg/sample.png 0000664 0000000 0000000 00000053347 13450235617 0016745 0 ustar 00root root 0000000 0000000 PNG
IHDR | J s- iCCPICC Profile X YgXK,˒s9sQ`9gTHR
AAɨ" wփwyf귫gj`i!DD
1rrv" d p#ylR
> @VpOw([ @vxGD &㋏ BE";/