Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support color ansi code sequences in custom help #2251

Merged
merged 49 commits into from
Nov 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d11db4a
Add displayWidth method to Help class, and styleTitle placeholder
shadowspawn Sep 16, 2024
c256694
Refactor into boxWrap and stripAnsi
shadowspawn Sep 24, 2024
34b1242
Rename field and add tests
shadowspawn Sep 25, 2024
98f4c89
refactor boxWrap a little
shadowspawn Sep 25, 2024
84f6c67
Refactor help formatting into smaller routines
shadowspawn Sep 27, 2024
8e95a38
Fix test and JSDoc
shadowspawn Sep 27, 2024
1819d5b
Move test for minimum wrap width
shadowspawn Sep 27, 2024
734974c
Add colour help example
shadowspawn Sep 27, 2024
6edca58
Strip color when output does not have color
shadowspawn Sep 29, 2024
a549b22
Fix case for import
shadowspawn Sep 29, 2024
803e06c
Add internal typing: HelpTextEventContext
shadowspawn Sep 29, 2024
45fb82d
Simplify example and stick to colours
shadowspawn Sep 30, 2024
f175be4
Add man style help layout example
shadowspawn Sep 30, 2024
4267b2d
Add min wrap width into boxWrap (too)
shadowspawn Sep 30, 2024
8e91761
Cometic changes
shadowspawn Sep 30, 2024
3f53005
Add FORCE_COLOR=0 support in useColor
shadowspawn Oct 1, 2024
045047c
Add custom help example using Chalk for color and wrapping support
shadowspawn Oct 2, 2024
2750b6d
Rename man example
shadowspawn Oct 2, 2024
27c616f
Add comment
shadowspawn Oct 4, 2024
238b826
Add prepareContext as an explicit setup stage
shadowspawn Oct 4, 2024
318f07c
Beef up color examples
shadowspawn Oct 4, 2024
d27e2b6
Add documentation and types and type tests for new routines
shadowspawn Oct 6, 2024
4f2aca4
Tidy up internal useColor to test for non-empty env values
shadowspawn Oct 9, 2024
53c881d
Add more style hooks
shadowspawn Oct 7, 2024
81eb129
Hard-code name for stable output
shadowspawn Oct 7, 2024
80c9909
.usage() should not include program name
shadowspawn Oct 7, 2024
c4b85ba
Add more style hooks so can do usage strings without separate overrides
shadowspawn Oct 8, 2024
72168e1
Clean up color example
shadowspawn Oct 11, 2024
721b201
Rework chalk example to match styleText example
shadowspawn Oct 11, 2024
ec2fcfb
styleSubcommandTerm is different than styleUsage after all
shadowspawn Oct 12, 2024
e7da1db
Update comments
shadowspawn Oct 12, 2024
0ff9461
Fill out TypeScript
shadowspawn Oct 12, 2024
b6a58ec
Add example of custom centered help
shadowspawn Nov 9, 2024
df8c9f2
Update README with mention of style methods and examples
shadowspawn Nov 9, 2024
ee7c003
Add Help tests for minWidthToWrap and styleFoo
shadowspawn Nov 9, 2024
ea729b1
Make subcommand more complete in test
shadowspawn Nov 9, 2024
2c45f95
Update comment to match code
shadowspawn Nov 9, 2024
278f178
Extend Help test coverage
shadowspawn Nov 9, 2024
4fdf84a
Refine test for ignoring coverage
shadowspawn Nov 9, 2024
9439ad5
Restore simple useColor naming
shadowspawn Nov 9, 2024
e55ceac
Update testing and support for color related environment variables
shadowspawn Nov 9, 2024
90856d0
Tweak CLICOLOR_FORCE test to check Apple convention
shadowspawn Nov 9, 2024
473b7e6
Add tests for getOutHasColors and getErrHasColors
shadowspawn Nov 9, 2024
7d96a32
Remove broken mock-heavy tests
shadowspawn Nov 10, 2024
a4c1b02
Add more style tests
shadowspawn Nov 10, 2024
dd02267
Rework end-to-end style test to use outputHelp()
shadowspawn Nov 10, 2024
1f92f35
Add color environment variables
shadowspawn Nov 10, 2024
9989394
Rename our stripAnsi to stripColor as more accurate
shadowspawn Nov 12, 2024
606975d
Remove bogus assignment to property of this
shadowspawn Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add FORCE_COLOR=0 support in useColor
  • Loading branch information
shadowspawn committed Nov 10, 2024
commit 3f53005bd80c8766285e119032f843a5c856e180
7 changes: 4 additions & 3 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -2555,10 +2555,11 @@ function incrementNodeInspectorPort(args) {
* @private
*/
function useColor() {
// http://http://no-color.org
// https://no-color.org
// https://bixense.com/clicolors/
// https://www.npmjs.com/package/chalk#chalksupportscolor
if ('NO_COLOR' in process.env) return false;
// https://nodejs.org/api/tty.html#writestreamgetcolordepthenv
if ('NO_COLOR' in process.env || process.env.FORCE_COLOR === '0')
return false;
if ('FORCE_COLOR' in process.env || 'CLICOLOR_FORCE' in process.env)
return true;
return undefined;
Expand Down