Skip to content

Commit 2c9e06d

Browse files
committedDec 12, 2021
Replace chalk with ansi-colors
1 parent 21e2702 commit 2c9e06d

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## next
22

33
- Allowed args after and between options
4+
- Replaced `chalk` with `ansi-colors`
45

56
## 3.0.0-beta.1
67

‎lib/help.js

+9-22
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1+
const colors = require('ansi-colors');
2+
13
const MAX_LINE_WIDTH = process.stdout.columns || 200;
24
const MIN_OFFSET = 20;
35
const reAstral = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
46
const ansiRegex = /\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[m|K]/g;
57
const byName = (a, b) => a.name > b.name || -(a.name < b.name);
6-
let chalk;
7-
8-
function initChalk() {
9-
if (!chalk) {
10-
const ChalkInstance = require('chalk').Instance;
11-
12-
chalk = new ChalkInstance({
13-
level: Number(process.stdout.isTTY)
14-
});
15-
}
16-
17-
return chalk;
18-
}
198

209
function stringLength(str) {
2110
return str
@@ -82,7 +71,7 @@ function commandsHelp(command) {
8271

8372
const lines = command.getCommands().sort(byName).map(({ name, meta, params }) => ({
8473
description: meta.description,
85-
name: chalk.green(name) + args(params, chalk.gray)
74+
name: colors.green(name) + args(params, colors.gray)
8675
}));
8776

8877
return [
@@ -104,8 +93,8 @@ function optionsHelp(command) {
10493
const lines = options.map(({ short, long, params, description }) => ({
10594
description,
10695
name: [
107-
short ? chalk.yellow(short) + ', ' : shortPlaceholder,
108-
chalk.yellow(long),
96+
short ? colors.yellow(short) + ', ' : shortPlaceholder,
97+
colors.yellow(long),
10998
args(params)
11099
].join('')
111100
}));
@@ -127,19 +116,17 @@ function optionsHelp(command) {
127116
* @api private
128117
*/
129118
module.exports = function getCommandHelp(command, commandPath) {
130-
initChalk();
131-
132119
commandPath = Array.isArray(commandPath) && commandPath.length
133120
? commandPath.concat(command.name).join(' ')
134121
: command.name;
135122

136123
return [
137124
(command.meta.description ? command.meta.description + '\n\n' : '') +
138125
'Usage:\n\n' +
139-
' ' + chalk.cyan(commandPath) +
140-
args(command.params, chalk.magenta) +
141-
(command.options.size !== 0 ? ' [' + chalk.yellow('options') + ']' : '') +
142-
(command.commands.size !== 0 ? ' [' + chalk.green('command') + ']' : ''),
126+
' ' + colors.cyan(commandPath) +
127+
args(command.params, colors.magenta) +
128+
(command.options.size !== 0 ? ' [' + colors.yellow('options') + ']' : '') +
129+
(command.commands.size !== 0 ? ' [' + colors.green('command') + ']' : ''),
143130
commandsHelp(command) +
144131
optionsHelp(command)
145132
].join('\n');

‎package-lock.json

+21-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"node": ">=8.0.0"
2222
},
2323
"dependencies": {
24-
"chalk": "^4.1.2"
24+
"ansi-colors": "^4.1.1"
2525
},
2626
"devDependencies": {
2727
"c8": "^7.10.0",

0 commit comments

Comments
 (0)
Please sign in to comment.