From 2fc387667609e47f9bc5f79f5d5daeeccdd3501e Mon Sep 17 00:00:00 2001 From: Cristian Barlutiu Date: Thu, 23 May 2024 08:54:48 +0200 Subject: [PATCH 1/3] Added exports for Colorette.isColorSupported --- index.d.ts | 4 +++- index.js | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 72b2a6b..eecdbf2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -213,6 +213,7 @@ interface PrettyOptions_ { } declare function build(options: PrettyOptions_): PinoPretty.PrettyStream; +type isColorSupported = PinoPretty.isColorSupported declare namespace PinoPretty { type Prettifier = (inputData: string | object, key: string, log: object, extras: PrettifierExtras) => string; @@ -224,7 +225,8 @@ declare namespace PinoPretty { type ColorizerFactory = typeof colorizerFactory; type PrettyFactory = typeof prettyFactory; type Build = typeof build; + type isColorSupported = typeof Colorette.isColorSupported; } export default PinoPretty; -export { build, PinoPretty, PrettyOptions_ as PrettyOptions, colorizerFactory, prettyFactory }; +export { build, PinoPretty, PrettyOptions_ as PrettyOptions, colorizerFactory, prettyFactory, isColorSupported }; diff --git a/index.js b/index.js index 66a0afd..31d8fa8 100644 --- a/index.js +++ b/index.js @@ -178,4 +178,5 @@ module.exports = build module.exports.build = build module.exports.prettyFactory = prettyFactory module.exports.colorizerFactory = colors +module.exports.isColorSupported = isColorSupported module.exports.default = build From e5234bee177e100ae2d5c266581039dcef4fc0cd Mon Sep 17 00:00:00 2001 From: Cristian Barlutiu Date: Thu, 23 May 2024 10:07:20 +0200 Subject: [PATCH 2/3] added tests to check for pinoPretty.isColorSupported --- test/basic.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/basic.test.js b/test/basic.test.js index 18f74c1..ede3f70 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -1179,6 +1179,12 @@ test('basic prettifier tests', (t) => { log.info('foo') }) + t.test('check support for colors', (t) => { + t.plan(1) + const isColorSupported = pinoPretty.isColorSupported + t.type(isColorSupported, 'boolean') + }) + t.end() }) From feaed4f0c0d3c44d836168e5c428b804af5763bb Mon Sep 17 00:00:00 2001 From: Cristian Barlutiu Date: Thu, 23 May 2024 10:20:18 +0200 Subject: [PATCH 3/3] updated the docs and added section for color support in TTY --- Readme.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Readme.md b/Readme.md index 8fd48ba..5004029 100644 --- a/Readme.md +++ b/Readme.md @@ -230,6 +230,19 @@ module.exports = opts => require('pino-pretty')({ }) ``` +### Checking color support in TTY + +This boolean returns whether the currently used TTY supports colorizing the logs. + +```js +import pretty from 'pino-pretty' + +if (pretty.isColorSupported) { + ... +} + +``` + ### Options