chalk/examples/screenshot.js

28 lines
603 B
JavaScript
Raw Normal View History

import process from 'node:process';
2021-04-16 15:23:29 +07:00
import styles from 'ansi-styles';
import chalk from '../source/index.js';
2016-10-26 12:58:01 +07:00
2017-05-21 23:28:38 +07:00
// Generates screenshot
2017-06-29 16:00:51 -07:00
for (const key of Object.keys(styles)) {
2020-04-02 15:56:21 +08:00
let returnValue = key;
2016-10-26 12:58:01 +07:00
2022-07-03 00:36:34 +02:00
// We skip `overline` as almost no terminal supports it so we cannot show it off.
if (
key === 'reset'
|| key === 'hidden'
|| key === 'grey'
|| key === 'bgGray'
|| key === 'bgGrey'
|| key === 'overline'
|| key.endsWith('Bright')
) {
2016-10-26 12:58:01 +07:00
continue;
}
if (/^bg[^B]/.test(key)) {
2020-04-02 15:56:21 +08:00
returnValue = chalk.black(returnValue);
2016-10-26 12:58:01 +07:00
}
2020-04-02 15:56:21 +08:00
process.stdout.write(chalk[key](returnValue) + ' ');
2016-10-26 12:58:01 +07:00
}