From b5fc35ea3f262adecaf9c8cf905db4f3e2cba878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20M=C3=A5rtensson?= Date: Mon, 24 Jul 2017 13:11:21 +0200 Subject: [PATCH] Use escape codes from `ansi-styles` (#22) --- index.js | 31 ++----------------------------- package.json | 1 + 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/index.js b/index.js index d2ae454..c52dfd0 100755 --- a/index.js +++ b/index.js @@ -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', @@ -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 @@ -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') { diff --git a/package.json b/package.json index 79e8b3a..0c48779 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "text" ], "dependencies": { + "ansi-styles": "^3.2.0", "string-width": "^2.1.1", "strip-ansi": "^4.0.0" },