From 511abb05db0a29b9c0c74a79bbd2dc4f74b3f690 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Fri, 8 Oct 2021 14:46:52 +1300 Subject: [PATCH 01/15] Add basic color detection --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3cb1573..391bbea 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,9 @@ +import tty from 'node:tty'; + +const hasColors = tty.WriteStream.prototype.hasColors(); + // Intentionally not using template literal for performance. -const format = (startCode, endCode) => string => '\u001B[' + startCode + 'm' + string + '\u001B[' + endCode + 'm'; +const format = (startCode, endCode) => hasColors ? string => '\u001B[' + startCode + 'm' + string + '\u001B[' + endCode + 'm' : string => string; export const reset = format(0, 0); export const bold = format(1, 22); From 644ac8f168dd19227914650135e04a49173ab988 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Fri, 8 Oct 2021 14:49:06 +1300 Subject: [PATCH 02/15] Update readme.md --- readme.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/readme.md b/readme.md index be87f38..53cd23d 100644 --- a/readme.md +++ b/readme.md @@ -29,8 +29,6 @@ import * as colors from 'yoctocolors'; console.log(colors.red('Yo!')); ``` -*This package does not do color support detection. Check out [`supports-color`](https://github.com/chalk/supports-color) if you need that. Node.js will hopefully get [built-in support](https://github.com/nodejs/node/pull/40240) for color support detection at some point.* - ## Styles ### Modifiers From 9aacd55d1bd947afefb3fc9b078e9a480310884e Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Fri, 8 Oct 2021 14:51:31 +1300 Subject: [PATCH 03/15] Update readme.md --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 53cd23d..e874055 100644 --- a/readme.md +++ b/readme.md @@ -29,6 +29,8 @@ import * as colors from 'yoctocolors'; console.log(colors.red('Yo!')); ``` +*This package support basic color detection. Node.js will hopefully get [better support](https://github.com/nodejs/node/pull/40240) for color support detection at some point.* + ## Styles ### Modifiers From d49a990ebf4ca5790897e5e5ca9c4a36f2cbb288 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Fri, 8 Oct 2021 14:51:51 +1300 Subject: [PATCH 04/15] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index e874055..eb3d950 100644 --- a/readme.md +++ b/readme.md @@ -29,7 +29,7 @@ import * as colors from 'yoctocolors'; console.log(colors.red('Yo!')); ``` -*This package support basic color detection. Node.js will hopefully get [better support](https://github.com/nodejs/node/pull/40240) for color support detection at some point.* +*This package supports basic color detection. Node.js will hopefully get [better support](https://github.com/nodejs/node/pull/40240) for color support detection at some point.* ## Styles From 3536e7a9734c15e34453e01768c216f12d8c4286 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Fri, 8 Oct 2021 19:47:26 +1300 Subject: [PATCH 05/15] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index eb3d950..f0ecab5 100644 --- a/readme.md +++ b/readme.md @@ -29,7 +29,7 @@ import * as colors from 'yoctocolors'; console.log(colors.red('Yo!')); ``` -*This package supports basic color detection. Node.js will hopefully get [better support](https://github.com/nodejs/node/pull/40240) for color support detection at some point.* +*This package supports [basic color detection](https://nodejs.org/docs/latest-v12.x/api/tty.html#tty_writestream_hascolors_count_env). TODO: Use [a better method](https://github.com/nodejs/node/pull/40240) when it's added to Node.js.* ## Styles From c9a0a5867692f89da7dfa701a5d47047ec750e16 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Sat, 9 Oct 2021 00:02:34 +1300 Subject: [PATCH 06/15] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index f0ecab5..d3da314 100644 --- a/readme.md +++ b/readme.md @@ -29,7 +29,7 @@ import * as colors from 'yoctocolors'; console.log(colors.red('Yo!')); ``` -*This package supports [basic color detection](https://nodejs.org/docs/latest-v12.x/api/tty.html#tty_writestream_hascolors_count_env). TODO: Use [a better method](https://github.com/nodejs/node/pull/40240) when it's added to Node.js.* +*This package supports [basic color detection](https://nodejs.org/docs/latest-v12.x/api/tty.html#tty_writestream_hascolors_count_env).* ## Styles From bb3464adcfbcfe38b68b80719502c841f4a97206 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Sat, 9 Oct 2021 00:02:57 +1300 Subject: [PATCH 07/15] Update index.js --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 391bbea..79d47bb 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ import tty from 'node:tty'; +// TODO: Use a better method when it's added to Node.js (https://github.com/nodejs/node/pull/40240) const hasColors = tty.WriteStream.prototype.hasColors(); // Intentionally not using template literal for performance. From b95ad7803bb6f22ef9d400bf1d2a1f65ec292275 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Sun, 10 Oct 2021 03:50:57 +1300 Subject: [PATCH 08/15] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 35948e1..f89805c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { - "test": "xo && ava && tsd" + "test": "xo && FORCE_COLOR=2 ava && tsd" }, "files": [ "index.js", From aa3a93c2a6b0a96c1015e5abcbc1675a27b6f489 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 24 Oct 2021 07:27:25 +0700 Subject: [PATCH 09/15] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index d3da314..49e2d44 100644 --- a/readme.md +++ b/readme.md @@ -29,7 +29,7 @@ import * as colors from 'yoctocolors'; console.log(colors.red('Yo!')); ``` -*This package supports [basic color detection](https://nodejs.org/docs/latest-v12.x/api/tty.html#tty_writestream_hascolors_count_env).* +*This package supports [basic color detection](https://nodejs.org/api/tty.html#writestreamhascolorscount-env).* ## Styles From 42368f098084480bf8004fb97bb20d87a72ba4f8 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Mon, 25 Oct 2021 01:50:37 +1300 Subject: [PATCH 10/15] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 49e2d44..ec1f088 100644 --- a/readme.md +++ b/readme.md @@ -29,7 +29,7 @@ import * as colors from 'yoctocolors'; console.log(colors.red('Yo!')); ``` -*This package supports [basic color detection](https://nodejs.org/api/tty.html#writestreamhascolorscount-env).* +*This package supports [basic color detection](https://nodejs.org/api/tty.html#writestreamhascolorscount-env). Colors can be forcefully enabled by setting the `FORCE_COLOR` environment variable to either ` `, `1`, `true`, `2` or `3`. Colors can be forcefully disabled by setting `FORCE_COLOR` to a value that is not listed prior or by setting `NO_COLOR` or `NODE_DISABLE_COLORS` to any value.* ## Styles From 2a5d7480c1a65d2824a1a04474fcbbdba1aedd17 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Mon, 25 Oct 2021 01:51:29 +1300 Subject: [PATCH 11/15] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index ec1f088..c3bd844 100644 --- a/readme.md +++ b/readme.md @@ -29,7 +29,7 @@ import * as colors from 'yoctocolors'; console.log(colors.red('Yo!')); ``` -*This package supports [basic color detection](https://nodejs.org/api/tty.html#writestreamhascolorscount-env). Colors can be forcefully enabled by setting the `FORCE_COLOR` environment variable to either ` `, `1`, `true`, `2` or `3`. Colors can be forcefully disabled by setting `FORCE_COLOR` to a value that is not listed prior or by setting `NO_COLOR` or `NODE_DISABLE_COLORS` to any value.* +*This package supports [basic color detection](https://nodejs.org/api/tty.html#writestreamhascolorscount-env). Colors can be forcefully enabled by setting the `FORCE_COLOR` environment variable to either ` `, `1`, `true`, `2` or `3` and can be forcefully disabled by setting it to a different value or by setting `NO_COLOR` or `NODE_DISABLE_COLORS` to any value.* ## Styles From 47155ea67bfdc9f18ec45f11eb94624bf01ec331 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Mon, 25 Oct 2021 03:04:22 +1300 Subject: [PATCH 12/15] Update package.json --- package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f89805c..eeb9613 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { - "test": "xo && FORCE_COLOR=2 ava && tsd" + "test": "xo && ava && tsd" }, "files": [ "index.js", @@ -46,5 +46,10 @@ "ava": "^3.15.0", "tsd": "^0.17.0", "xo": "^0.44.0" + }, + "ava": { + "environmentVariables": { + "NO_COLOR": "2" + } } } From 23f001887c3dd9e9d03b00e6e9b813f943e07bd0 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Thu, 28 Oct 2021 00:56:37 +1300 Subject: [PATCH 13/15] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eeb9613..215bfc2 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ }, "ava": { "environmentVariables": { - "NO_COLOR": "2" + "FORCE_COLOR": "2" } } } From 67ff9d89c88cf68c38962ca4317e36eca14cebc3 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Thu, 28 Oct 2021 00:58:57 +1300 Subject: [PATCH 14/15] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 215bfc2..f42b9ed 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ }, "ava": { "environmentVariables": { - "FORCE_COLOR": "2" + "FORCE_COLOR": "1" } } } From 62937bf53ec5b21117b0b47dd58384fee4359a08 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 27 Oct 2021 19:02:13 +0700 Subject: [PATCH 15/15] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index c3bd844..1a98868 100644 --- a/readme.md +++ b/readme.md @@ -29,7 +29,7 @@ import * as colors from 'yoctocolors'; console.log(colors.red('Yo!')); ``` -*This package supports [basic color detection](https://nodejs.org/api/tty.html#writestreamhascolorscount-env). Colors can be forcefully enabled by setting the `FORCE_COLOR` environment variable to either ` `, `1`, `true`, `2` or `3` and can be forcefully disabled by setting it to a different value or by setting `NO_COLOR` or `NODE_DISABLE_COLORS` to any value.* +*This package supports [basic color detection](https://nodejs.org/api/tty.html#writestreamhascolorscount-env). Colors can be forcefully enabled by setting the `FORCE_COLOR` environment variable to `1` and can be forcefully disabled by setting `NO_COLOR` or `NODE_DISABLE_COLORS` to any value. [More info.](https://nodejs.org/api/tty.html#writestreamgetcolordepthenv)* ## Styles