Skip to content

Commit

Permalink
feat: Added exports color support in TTY (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
synapse authored May 23, 2024
1 parent 91a56eb commit b2004ef
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
...
}

```

<a id="options"></a>
### Options

Expand Down
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ interface PrettyOptions_ {
}

declare function build(options: PrettyOptions_): PinoPretty.PrettyStream;
type isColorSupported = PinoPretty.isColorSupported

declare namespace PinoPretty {
type Prettifier<T = object> = (inputData: string | object, key: string, log: object, extras: PrettifierExtras<T>) => string;
Expand All @@ -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 };
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down

0 comments on commit b2004ef

Please sign in to comment.