Skip to content

Commit

Permalink
Use escape codes from ansi-styles (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevva authored and sindresorhus committed Jul 24, 2017
1 parent 165504b commit b5fc35e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
31 changes: 2 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const stringWidth = require('string-width');
const stripAnsi = require('strip-ansi');
const ansiStyles = require('ansi-styles');

const ESCAPES = new Set([
'\u001B',
Expand All @@ -9,34 +10,6 @@ const ESCAPES = new Set([

const END_CODE = 39;

const ESCAPE_CODES = new Map([
[0, 0],
[1, 22],
[2, 22],
[3, 23],
[4, 24],
[7, 27],
[8, 28],
[9, 29],
[30, 39],
[31, 39],
[32, 39],
[33, 39],
[34, 39],
[35, 39],
[36, 39],
[37, 39],
[90, 39],
[40, 49],
[41, 49],
[42, 49],
[43, 49],
[44, 49],
[45, 49],
[46, 49],
[47, 49]
]);

const wrapAnsi = code => `${ESCAPES.values().next().value}[${code}m`;

// Calculate the length of words split on ' ', ignoring
Expand Down Expand Up @@ -169,7 +142,7 @@ const exec = (str, cols, opts) => {
escapeCode = code === END_CODE ? null : code;
}

const code = ESCAPE_CODES.get(Number(escapeCode));
const code = ansiStyles.codes.get(Number(escapeCode));

if (escapeCode && code) {
if (pre[i + 1] === '\n') {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"text"
],
"dependencies": {
"ansi-styles": "^3.2.0",
"string-width": "^2.1.1",
"strip-ansi": "^4.0.0"
},
Expand Down

0 comments on commit b5fc35e

Please sign in to comment.