[Pkg-javascript-commits] [node-ansi-regex] 01/03: Imported Upstream version 1.1.1

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Fri Mar 20 22:49:07 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository node-ansi-regex.

commit cbf8f7099b60b66139c4b7e5946f5f8ca016702c
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Fri Mar 20 23:43:45 2015 +0100

    Imported Upstream version 1.1.1
---
 .editorconfig     |   1 -
 .jshintrc         |   3 -
 .travis.yml       |   3 +
 index.js          |   2 +-
 package.json      |   9 +-
 test.js           |  19 ----
 test/test.js      |  43 +++++++++
 test/viewCodes.js | 268 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 322 insertions(+), 26 deletions(-)

diff --git a/.editorconfig b/.editorconfig
index 8311fe1..86c8f59 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,4 +1,3 @@
-# editorconfig.org
 root = true
 
 [*]
diff --git a/.jshintrc b/.jshintrc
index c511975..804f8af 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -4,12 +4,9 @@
 	"bitwise": true,
 	"camelcase": true,
 	"curly": true,
-	"eqeqeq": true,
 	"immed": true,
-	"indent": 4,
 	"newcap": true,
 	"noarg": true,
-	"quotmark": "single",
 	"undef": true,
 	"unused": "vars",
 	"strict": true
diff --git a/.travis.yml b/.travis.yml
index 244b7e8..dedfc07 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,6 @@
+sudo: false
 language: node_js
 node_js:
+  - 'iojs'
+  - '0.12'
   - '0.10'
diff --git a/index.js b/index.js
index 783c5c7..2fcdd1e 100644
--- a/index.js
+++ b/index.js
@@ -1,4 +1,4 @@
 'use strict';
 module.exports = function () {
-	return /\u001b\[(?:[0-9]{1,3}(?:;[0-9]{1,3})*)?[m|K]/g;
+	return /(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/g;
 };
diff --git a/package.json b/package.json
index 2734a78..2d71a33 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "ansi-regex",
-  "version": "0.2.1",
+  "version": "1.1.1",
   "description": "Regular expression for matching ANSI escape codes",
   "license": "MIT",
   "repository": "sindresorhus/ansi-regex",
@@ -9,11 +9,16 @@
     "email": "sindresorhus at gmail.com",
     "url": "http://sindresorhus.com"
   },
+  "maintainers": [
+    "Sindre Sorhus <sindresorhus at gmail.com> (http://sindresorhus.com)",
+    "Joshua Appelman <jappelman at xebia.com> (http://jbnicolai.com)"
+  ],
   "engines": {
     "node": ">=0.10.0"
   },
   "scripts": {
-    "test": "mocha"
+    "test": "mocha test/test.js",
+    "view-supported": "node test/viewCodes.js"
   },
   "files": [
     "index.js"
diff --git a/test.js b/test.js
deleted file mode 100644
index 7081ed6..0000000
--- a/test.js
+++ /dev/null
@@ -1,19 +0,0 @@
-'use strict';
-var assert = require('assert');
-var ansiRegex = require('./');
-
-it('should match ansi code in a string', function () {
-	assert(ansiRegex().test('foo\u001b[4mcake\u001b[0m'));
-	assert(ansiRegex().test('\u001b[4mcake\u001b[0m'));
-	assert(ansiRegex().test('foo\u001b[4mcake\u001b[0m'));
-	assert(ansiRegex().test('\u001b[0m\u001b[4m\u001b[42m\u001b[31mfoo\u001b[39m\u001b[49m\u001b[24mfoo\u001b[0m'));
-	assert(ansiRegex().test('foo\u001b[mfoo'));
-});
-
-it('should match ansi code from ls command', function () {
-	assert(ansiRegex().test('\u001b[00;38;5;244m\u001b[m\u001b[00;38;5;33mfoo\u001b[0m'));
-});
-
-it('should match reset;setfg;setbg;italics;strike;underline sequence in a string', function () {
-	assert(ansiRegex().test('\u001b[0;33;49;3;9;4mbar\u001b[0m'));
-});
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..f93b6bc
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,43 @@
+'use strict';
+var assert = require('assert');
+var ansiRegex = require('../');
+
+// testing against codes found at: http://ascii-table.com/ansi-escape-sequences-vt-100.php
+
+it('should match ansi code in a string', function (done) {
+	assert.equal(ansiRegex().test('foo\u001b[4mcake\u001b[0m'), true);
+	assert.equal(ansiRegex().test('\u001b[4mcake\u001b[0m'), true);
+	assert.equal(ansiRegex().test('foo\u001b[4mcake\u001b[0m'), true);
+	assert.equal(ansiRegex().test('\u001b[0m\u001b[4m\u001b[42m\u001b[31mfoo\u001b[39m\u001b[49m\u001b[24mfoo\u001b[0m'), true);
+	assert.equal(ansiRegex().test('foo\u001b[mfoo'), true);
+	done();
+});
+
+it('should match ansi code from ls command', function (done) {
+	assert.equal(ansiRegex().test('\u001b[00;38;5;244m\u001b[m\u001b[00;38;5;33mfoo\u001b[0m'), true);
+	done();
+});
+
+it('should match reset;setfg;setbg;italics;strike;underline sequence in a string', function (done) {
+	assert.equal(ansiRegex().test('\u001b[0;33;49;3;9;4mbar\u001b[0m'), true);
+	assert.equal(('foo\u001b[0;33;49;3;9;4mbar').match(ansiRegex())[0], '\u001b[0;33;49;3;9;4m');
+	done();
+});
+
+it('should match clear tabs sequence in a string', function (done) {
+	assert.equal(ansiRegex().test('foo\u001b[0gbar'), true);
+	assert.equal(('foo\u001b[0gbar').match(ansiRegex())[0], '\u001b[0g');
+	done();
+});
+
+it('should match clear line from cursor right in a string', function (done) {
+	assert.equal(ansiRegex().test('foo\u001b[Kbar'), true);
+	assert.equal(('foo\u001b[Kbar').match(ansiRegex())[0], '\u001b[K');
+	done();
+});
+
+it('should match clear screen in a string', function (done) {
+	assert.equal(ansiRegex().test('foo\u001b[2Jbar'), true);
+	assert.equal(('foo\u001b[2Jbar').match(ansiRegex())[0], '\u001b[2J');
+	done();
+});
diff --git a/test/viewCodes.js b/test/viewCodes.js
new file mode 100644
index 0000000..1090b25
--- /dev/null
+++ b/test/viewCodes.js
@@ -0,0 +1,268 @@
+'use strict';
+var ansiRegex = require('../');
+var allCodes = {};
+var supported = [];
+var unsupported = [];
+
+// from http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
+var vt52Codes = {
+	'A': ['Cursor up'],
+	'B': ['Cursor down'],
+	'C': ['Cursor right'],
+	'D': ['Cursor left'],
+	'H': ['Cursor to home'],
+	'I': ['Reverse line feed'],
+	'J': ['Erase to end of screen'],
+	'K': ['Erase to end of line'],
+	'Z': ['Identify'],
+	'=': ['Enter alternate keypad mode'],
+	'>': ['Exit alternate keypad mode'],
+	'1': ['Graphics processor on'],
+	'2': ['Graphics processor off'],
+	'<': ['Enter ANSI mode']
+};
+
+// from http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
+var ansiCompatible = {
+	'[176A':['Cursor up Pn lines'],
+	'[176B':['Cursor down Pn lines'],
+	'[176C':['Cursor forward Pn characters (right)'],
+	'[176D':['Cursor backward Pn characters (left)'],
+	'[176;176H':['Direct cursor addressing, where Pl is line#, Pc is column#'],
+	'[176;176f':['Direct cursor addressing, where Pl is line#, Pc is column#'],
+
+	'7':['Save cursor and attributes'],
+	'8':['Restore cursor and attributes'],
+
+	'#3':['Change this line to double-height top half'],
+	'#4':['Change this line to double-height bottom half'],
+	'#5':['Change this line to single-width single-height'],
+	'#6':['Change this line to double-width single-height'],
+
+	'[176;176;176;176;176;176;176m': ['Text Styles'],
+	'[176;176;176;176;176;176;176q': ['Programmable LEDs'],
+
+	'[K':['Erase from cursor to end of line'],
+	'[0K':['Same'],
+	'[1K':['Erase from beginning of line to cursor'],
+	'[2K':['Erase line containing cursor'],
+	'[J':['Erase from cursor to end of screen'],
+	'[0J':['Same'],
+	'[2J':['Erase entire screen'],
+
+	'(A': ['United Kingdom (UK) (Character Set G0)'],
+	')A': ['United Kingdom (UK) (Character Set G1)'],
+	'(B': ['United States (USASCII) (Character Set G0)'],
+	')B': ['United States (USASCII) (Character Set G1)'],
+	'(0': ['Special graphics/line drawing set (Character Set G0)'],
+	')0': ['Special graphics/line drawing set (Character Set G1)'],
+	'(1': ['Alternative character ROM (Character Set G0)'],
+	')1': ['Alternative character ROM (Character Set G1)'],
+	'(2': ['Alternative graphic ROM (Character Set G0)'],
+	')2': ['Alternative graphic ROM (Character Set G1)'],
+
+	'H': ['Set tab at current column'],
+	'[g': ['Clear tab at current column'],
+	'[0g': ['Same'],
+	'[3g': ['Clear all tabs'],
+
+	'[6n': ['Cursor position report'],
+	'[176;176R': ['(response; Pl=line#; Pc=column#)'],
+	'[5n': ['Status report'],
+	'[c': ['(response; terminal Ok)'],
+	'[0c': ['(response; teminal not Ok)'],
+	'[?1;176c': ['response; where Ps is option present:'],
+
+	'c': ['Causes power-up reset routine to be executed'],
+	'#8': ['Fill screen with "E"'],
+	'[2;176y': ['Invoke Test(s), where Ps is a decimal computed by adding the numbers of the desired tests to be executed']
+
+};
+
+// from http://ascii-table.com/ansi-escape-sequences-vt-100.php
+var commonCodes = {
+	'[176A': ['Move cursor up n lines', 'CUU'],
+	'[176B': ['Move cursor down n lines', 'CUD'],
+	'[176C': ['Move cursor right n lines', 'CUF'],
+	'[176D': ['Move cursor left n lines', 'CUB'],
+	'[176;176H': ['Move cursor to screen location v,h', 'CUP'],
+	'[176;176f': ['Move cursor to screen location v,h', 'CUP'],
+	'[176;176r': ['Set top and bottom lines of a window', 'DECSTBM'],
+	'[176;176R': ['Response: cursor is at v,h', 'CPR'],
+
+	'[?1;1760c': ['Response: terminal type code n', 'DA'],
+
+	'[20h': ['Set new line mode', 'LMN'],
+	'[?1h': ['Set cursor key to application', 'DECCKM'],
+	'[?3h': ['Set number of columns to 132', 'DECCOLM'],
+	'[?4h': ['Set smooth scrolling', 'DECSCLM'],
+	'[?5h': ['Set reverse video on screen', 'DECSCNM'],
+	'[?6h': ['Set origin to relative', 'DECOM'],
+	'[?7h': ['Set auto-wrap mode', 'DECAWM'],
+	'[?8h': ['Set auto-repeat mode', 'DECARM'],
+	'[?9h': ['Set interlacing mode', 'DECINLM'],
+	'[20l': ['Set line feed mode', 'LMN'],
+	'[?1l': ['Set cursor key to cursor', 'DECCKM'],
+	'[?2l': ['Set VT52 (versus ANSI)', 'DECANM'],
+	'[?3l': ['Set number of columns to 80', 'DECCOLM'],
+	'[?4l': ['Set jump scrolling', 'DECSCLM'],
+	'[?5l': ['Set normal video on screen', 'DECSCNM'],
+	'[?6l': ['Set origin to absolute', 'DECOM'],
+	'[?7l': ['Reset auto-wrap mode', 'DECAWM'],
+	'[?8l': ['Reset auto-repeat mode', 'DECARM'],
+	'[?9l': ['Reset interlacing mode', 'DECINLM'],
+
+	'N': ['Set single shift 2', 'SS2'],
+	'O': ['Set single shift 3', 'SS3'],
+
+	'[m': ['Turn off character attributes', 'SGR0'],
+	'[0m': ['Turn off character attributes', 'SGR0'],
+	'[1m': ['Turn bold mode on', 'SGR1'],
+	'[2m': ['Turn low intensity mode on', 'SGR2'],
+	'[4m': ['Turn underline mode on', 'SGR4'],
+	'[5m': ['Turn blinking mode on', 'SGR5'],
+	'[7m': ['Turn reverse video on', 'SGR7'],
+	'[8m': ['Turn invisible text mode on', 'SGR8'],
+
+	'[9m': ['strikethrough on', '--'],
+	'[22m': ['bold off (see below)', '--'],
+	'[23m': ['italics off', '--'],
+	'[24m': ['underline off', '--'],
+	'[27m': ['inverse off', '--'],
+	'[29m': ['strikethrough off', '--'],
+	'[30m': ['set foreground color to black', '--'],
+	'[31m': ['set foreground color to red', '--'],
+	'[32m': ['set foreground color to green', '--'],
+	'[33m': ['set foreground color to yellow', '--'],
+	'[34m': ['set foreground color to blue', '--'],
+	'[35m': ['set foreground color to magenta (purple)', '--'],
+	'[36m': ['set foreground color to cyan', '--'],
+	'[37m': ['set foreground color to white', '--'],
+	'[39m': ['set foreground color to default (white)', '--'],
+	'[40m': ['set background color to black', '--'],
+	'[41m': ['set background color to red', '--'],
+	'[42m': ['set background color to green', '--'],
+	'[43m': ['set background color to yellow', '--'],
+	'[44m': ['set background color to blue', '--'],
+	'[45m': ['set background color to magenta (purple)', '--'],
+	'[46m': ['set background color to cyan', '--'],
+	'[47m': ['set background color to white', '--'],
+	'[49m': ['set background color to default (black)', '--'],
+
+	'[H': ['Move cursor to upper left corner', 'cursorhome'],
+	'[;H': ['Move cursor to upper left corner', 'cursorhome'],
+	'[f': ['Move cursor to upper left corner', 'hvhome'],
+	'[;f': ['Move cursor to upper left corner', 'hvhome'],
+	'M': ['Move/scroll window down one line', 'RI'],
+	'E': ['Move to next line', 'NEL'],
+
+	'H': ['Set a tab at the current column', 'HTS'],
+	'[g': ['Clear a tab at the current column', 'TBC'],
+	'[0g': ['Clear a tab at the current column', 'TBC'],
+	'[3g': ['Clear all tabs', 'TBC'],
+
+	'[K': ['Clear line from cursor right', 'EL0'],
+	'[0K': ['Clear line from cursor right', 'EL0'],
+	'[1K': ['Clear line from cursor left', 'EL1'],
+	'[2K': ['Clear entire line', 'EL2'],
+	'[J': ['Clear screen from cursor down', 'ED0'],
+	'[0J': ['Clear screen from cursor down', 'ED0'],
+	'[1J': ['Clear screen from cursor up', 'ED1'],
+	'[2J': ['Clear entire screen', 'ED2'],
+
+	'[c': ['Identify what terminal type', 'DA'],
+	'[0c': ['Identify what terminal type (another)', 'DA'],
+	'c': ['Reset terminal to initial state', 'RIS'],
+	'[2;1y': [ 'Confidence power up test', 'DECTST'],
+	'[2;2y': [ 'Confidence loopback test', 'DECTST'],
+	'[2;9y': [ 'Repeat power up test', 'DECTST'],
+	'[2;10y': [ 'Repeat loopback test', 'DECTST'],
+	'[0q': ['Turn off all four leds', 'DECLL0'],
+	'[1q': ['Turn on LED #1', 'DECLL1'],
+	'[2q': ['Turn on LED #2', 'DECLL2'],
+	'[3q': ['Turn on LED #3', 'DECLL3'],
+	'[4q': ['Turn on LED #4', 'DECLL4']
+};
+
+// from http://ascii-table.com/ansi-escape-sequences-vt-100.php
+var otherCodes = {
+	'7': ['Save cursor position and attributes', 'DECSC'],
+	'8': ['Restore cursor position and attributes', 'DECSC'],
+
+	'=': ['Set alternate keypad mode', 'DECKPAM'],
+	'>': ['Set numeric keypad mode', 'DECKPNM'],
+
+	'(A': ['Set United Kingdom G0 character set', 'setukg0'],
+	')A': ['Set United Kingdom G1 character set', 'setukg1'],
+	'(B': ['Set United States G0 character set', 'setusg0'],
+	')B': ['Set United States G1 character set', 'setusg1'],
+	'(0': ['Set G0 special chars. & line set', 'setspecg0'],
+	')0': ['Set G1 special chars. & line set', 'setspecg1'],
+	'(1': ['Set G0 alternate character ROM', 'setaltg0'],
+	')1': ['Set G1 alternate character ROM', 'setaltg1'],
+	'(2': ['Set G0 alt char ROM and spec. graphics', 'setaltspecg0'],
+	')2': ['Set G1 alt char ROM and spec. graphics', 'setaltspecg1'],
+
+	'#3': ['Double-height letters, top half', 'DECDHL'],
+	'#4': ['Double-height letters, bottom half', 'DECDHL'],
+	'#5': ['Single width, single height letters', 'DECSWL'],
+	'#6': ['Double width, single height letters', 'DECDWL'],
+	'#8': ['Screen alignment display', 'DECALN'],
+
+	'5n': ['Device status report', 'DSR'],
+	'0n': ['Response: terminal is OK', 'DSR'],
+	'3n': ['Response: terminal is not OK', 'DSR'],
+	'6n': ['Get cursor position', 'DSR']
+};
+
+function addCodesToTest(codes) {
+	for (var code in codes){
+		allCodes[code] = codes[code];
+	}
+}
+
+function identifySupportedCodes() {
+	var codeSupport = {};
+
+	for (var code in allCodes) {
+		codeSupport = {
+			code : code,
+			matches: ('\u001b'+code).match( ansiRegex() ),
+			description: allCodes[code][0],
+			// neighbourDelimitWorks: ('\u001b'+code+'a209ZELLO').match(ansiRegex({vt100: true}))[0] === ('\u001b'+code).match(ansiRegex({vt100: true}))[0],
+		};
+
+		if (codeSupport.matches !== null && codeSupport.matches[0] === '\u001b' + code) {
+			supported.push(codeSupport);
+		} else {
+			unsupported.push(codeSupport);
+		}
+
+	}
+}
+
+function displaySupport() {
+	process.stdout.write('\u001b[32m');
+
+	console.log('SUPPORTED');
+	for (var i = 0; i < supported.length; i++) {
+		console.log(supported[i]);
+	}
+
+	process.stdout.write('\u001b[31m');
+	console.log('UNSUPPORTED');
+
+	for (var i = 0; i < unsupported.length; i++) {
+		console.log(unsupported[i]);
+	}
+
+	process.stdout.write('\u001b[0m');
+}
+
+addCodesToTest(vt52Codes);
+addCodesToTest(ansiCompatible);
+addCodesToTest(commonCodes);
+addCodesToTest(otherCodes);
+
+identifySupportedCodes();
+displaySupport();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-ansi-regex.git



More information about the Pkg-javascript-commits mailing list