Skip to content

Commit

Permalink
Merge pull request #554 from marp-team/color-a11y-cli-kind-output
Browse files Browse the repository at this point in the history
Accessibility: Render CLI's kind output in a specific color instead of ANSI color
  • Loading branch information
yhatt authored Oct 1, 2023
2 parents 128666b + bcc9499 commit d54fd27
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
ecmaFeatures: { jsx: true },
},
rules: {
'import/no-unresolved': ['error', { ignore: ['chalk', 'ts-key-enum'] }],
'import/no-unresolved': ['error', { ignore: ['ts-key-enum'] }],
'import/order': ['error', { alphabetize: { order: 'asc' } }],
},
settings: {
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

### Fixed

- Improve stability of in-memory preview for large content ([#553](https://github.com/marp-team/marp-cli/pull/553))
- Improve stability of in-memory preview for large content ([#553](https://github.com/marp-team/marp-cli/pull/553))
- Accessibility: Render CLI's kind output in a specific color instead of ANSI color ([#552](https://github.com/marp-team/marp-cli/issues/552), [#554](https://github.com/marp-team/marp-cli/pull/554))

## v3.3.0 - 2023-09-23

Expand Down
2 changes: 2 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
jest.mock('wrap-ansi')

require('css.escape') // Polyfill for CSS.escape

process.env.FORCE_COLOR = '0'
25 changes: 19 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import chalk from 'chalk'
import chalk, { supportsColorStderr } from 'chalk'
import stripAnsi from 'strip-ansi'
import wrapAnsi from 'wrap-ansi'
import { terminalWidth } from 'yargs'

const { has16m, has256 } = { ...supportsColorStderr } // Workaround for type error

interface CLIOption {
singleLine?: boolean
}
Expand All @@ -27,16 +29,27 @@ export function silence(value: boolean) {
}

export function info(message: string, opts: CLIOption = {}): void {
if (silent) return

const highlight =
has16m || has256 ? chalk.bgHex('#67b8e3').hex('#000') : chalk.inverse

// Use console.warn to output into stderr
if (!silent)
console.warn(messageBlock(chalk.bgCyan.black('[ INFO ]'), message, opts))
console.warn(messageBlock(highlight`[ INFO ]`, message, opts))
}

export function warn(message: string, opts: CLIOption = {}): void {
if (!silent)
console.warn(messageBlock(chalk.bgYellow.black('[ WARN ]'), message, opts))
if (silent) return

const highlight =
has16m || has256 ? chalk.bgHex('#fc0').hex('#000') : chalk.inverse

console.warn(messageBlock(highlight`[ WARN ]`, message, opts))
}

export function error(message: string, opts: CLIOption = {}): void {
console.error(messageBlock(chalk.bgRed.white('[ ERROR ]'), message, opts))
const highlight =
has16m || has256 ? chalk.bgHex('#c00').hex('#fff') : chalk.inverse

console.error(messageBlock(highlight`[ ERROR ]`, message, opts))
}

0 comments on commit d54fd27

Please sign in to comment.