Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ansi_up

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansi_up - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

.dir_bash_history

32

ansi_up.js
// ansi_up.js
// version : 1.1.3
// version : 1.2.0
// author : Dru Nelson

@@ -10,3 +10,3 @@ // license : MIT

var ansi_up,
VERSION = "1.1.3",
VERSION = "1.2.0",

@@ -94,14 +94,26 @@ // check for nodeJS

//
// This regex matches two groups within a chunk.
// The first group matches all of the number+semicolon command sequences
// before the 'm' character. These are the graphics or SGR commands.
// The second group is the text (including newlines) that is colored by
// the first group's commands.
var matches = text.match(/([\d;]*)m([\s\S]*)/m);
// This regex matches four groups within a chunk.
//
// The first and third groups match code type.
// We supported only SGR command. It has empty first group and 'm' in third.
//
// The second group matches all of the number+semicolon command sequences
// before the 'm' (or other trailing) character.
// These are the graphics or SGR commands.
//
// The last group is the text (including newlines) that is colored by
// the other group's commands.
var matches = text.match(/^([!\x3c-\x3f]*)([\d;]*)([\x20-\x2c]*[\x40-\x7e])([\s\S]*)/m);
if (!matches) return text;
var orig_txt = matches[2];
var nums = matches[1].split(';');
var orig_txt = matches[4];
var nums = matches[2].split(';');
// We currently support only "SGR" (Select Graphic Rendition)
// Simply ignore if not a SGR command.
if (matches[1] !== '' || matches[3] !== 'm') {
return orig_txt;
}
var self = this;

@@ -108,0 +120,0 @@ nums.map(function (num_str) {

{
"name": "ansi_up",
"main": "ansi_up.js",
"version": "1.1.3",
"version": "1.2.0",
"homepage": "https://github.com/drudru/ansi_up",

@@ -6,0 +6,0 @@ "authors": [

{
"name": "ansi_up",
"version": "1.1.3",
"version": "1.2.0",
"description": "Convert ansi sequences in strings to colorful HTML",

@@ -5,0 +5,0 @@ "keywords": ["ansi", "html"],

@@ -55,7 +55,15 @@ # ansi_up.js

_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 CSS definition.
_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.
#### ansi_to_html (txt, options)
This replaces ANSI terminal escape codes with SPAN tags that wrap the content. See the example output above.
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.
#### escape_for_html (txt)
This does the minimum escaping of text to make it compliant with HTML. In particular, the '&','<', and '>' characters are escaped.
This does the minimum escaping of text to make it compliant with HTML. In particular, the '&','<', and '>' characters are escaped. This should be run prior to ansi_to_html.

@@ -66,8 +74,2 @@ #### linkify (txt)

#### ansi_to_html (txt, options)
This replaces ANSI terminal escape codes with SPAN tags that wrap the content. By default the styles are inline on the SPAN tags.
The options parameter is optional and if you pass an object with the key/value pair 'use_classes: true' classes will be set on the SPAN tag instead of inline styles. The classes 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.
## Building

@@ -89,2 +91,3 @@

- AIZAWA Hina (<https://github.com/fetus-hina>)
- James R. White (<https://github.com/jamesrwhite>)

@@ -91,0 +94,0 @@ - Aaron Stone (<https://github.com/sodabrew>)

@@ -306,5 +306,56 @@ var ansi_up = require('../ansi_up');

});
it('should correctly convert a string similar to CSI', function() {
// https://github.com/drudru/ansi_up/pull/15
this.timeout(1);
// "[1;31m" is a plain text. not an escape sequence.
var start = "foo\033[1@bar[1;31mbaz\033[0m";
var l = ansi_up.ansi_to_html(start);
// is all plain texts exist?
l.should.containEql('foo');
l.should.containEql('bar');
l.should.containEql('baz');
l.should.containEql('1;31m');
});
describe('ignore unsupported CSI', function() {
it('(italic)', function() {
this.timeout(1);
var start = "foo\033[3mbar\033[0mbaz";
var l = ansi_up.ansi_to_html(start);
l.should.eql('foobarbaz');
});
it('(cursor-up)', function() {
this.timeout(1);
var start = "foo\033[1Abar";
var l = ansi_up.ansi_to_html(start);
l.should.eql('foobar');
});
it('(scroll-left)', function() {
this.timeout(1);
// <ESC>[1 @ (including ascii space)
var start = "foo\033[1 @bar";
var l = ansi_up.ansi_to_html(start);
l.should.eql('foobar');
});
it('(DECMC)', function() {
this.timeout(1);
var start = "foo\033[?11ibar";
var l = ansi_up.ansi_to_html(start);
l.should.eql('foobar');
});
it('(RLIMGCP)', function() {
this.timeout(1);
var start = "foo\033[<!3ibar";
var l = ansi_up.ansi_to_html(start);
l.should.eql('foobar');
});
it('(DECSCL)', function() {
this.timeout(1);
var start = "foo\033[61;0\"pbar"
var l = ansi_up.ansi_to_html(start);
l.should.eql('foobar');
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc