Skip to content

Commit b5fc35e

Browse files
kevvasindresorhus
authored andcommittedJul 24, 2017
Use escape codes from ansi-styles (#22)
1 parent 165504b commit b5fc35e

File tree

2 files changed

+3
-29
lines changed

2 files changed

+3
-29
lines changed
 

‎index.js

+2-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const stringWidth = require('string-width');
33
const stripAnsi = require('strip-ansi');
4+
const ansiStyles = require('ansi-styles');
45

56
const ESCAPES = new Set([
67
'\u001B',
@@ -9,34 +10,6 @@ const ESCAPES = new Set([
910

1011
const END_CODE = 39;
1112

12-
const ESCAPE_CODES = new Map([
13-
[0, 0],
14-
[1, 22],
15-
[2, 22],
16-
[3, 23],
17-
[4, 24],
18-
[7, 27],
19-
[8, 28],
20-
[9, 29],
21-
[30, 39],
22-
[31, 39],
23-
[32, 39],
24-
[33, 39],
25-
[34, 39],
26-
[35, 39],
27-
[36, 39],
28-
[37, 39],
29-
[90, 39],
30-
[40, 49],
31-
[41, 49],
32-
[42, 49],
33-
[43, 49],
34-
[44, 49],
35-
[45, 49],
36-
[46, 49],
37-
[47, 49]
38-
]);
39-
4013
const wrapAnsi = code => `${ESCAPES.values().next().value}[${code}m`;
4114

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

172-
const code = ESCAPE_CODES.get(Number(escapeCode));
145+
const code = ansiStyles.codes.get(Number(escapeCode));
173146

174147
if (escapeCode && code) {
175148
if (pre[i + 1] === '\n') {

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"text"
4848
],
4949
"dependencies": {
50+
"ansi-styles": "^3.2.0",
5051
"string-width": "^2.1.1",
5152
"strip-ansi": "^4.0.0"
5253
},

0 commit comments

Comments
 (0)
Please sign in to comment.