Skip to content

Commit

Permalink
Add support for Windows terminals with Unicode fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 27, 2021
1 parent 5aa4c62 commit e420d8b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
const isUnicodeSupported = require('is-unicode-supported');

const {platform} = process;

Expand Down Expand Up @@ -284,8 +285,7 @@ if (platform === 'linux') {
main.questionMarkPrefix = '?';
}

// TODO: Use https://github.com/sindresorhus/is-unicode-supported when targeting Node.js 10.
const figures = platform === 'win32' ? fallback : main;
const figures = isUnicodeSupported() ? main : fallback;

const isFallbackFigure = ([key, mainValue]) => figures[key] !== mainValue;
const getFigureRegExp = ([key, mainValue]) => [new RegExp(escapeStringRegexp(mainValue), 'g'), figures[key]];
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"fallback"
],
"dependencies": {
"escape-string-regexp": "^1.0.5"
"escape-string-regexp": "^1.0.5",
"is-unicode-supported": "^0.1.0"
},
"devDependencies": {
"ava": "^1.4.1",
Expand Down
3 changes: 2 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import test from 'ava';
import isUnicodeSupported from 'is-unicode-supported';
import figures, {replaceSymbols, main, windows} from '.';

const result = (main, windows) => process.platform === 'win32' ? windows : main;
const result = (main, windows) => isUnicodeSupported ? main : windows;

const NON_FIGURE_KEYS = new Set(['main', 'windows', 'replaceSymbols']);
const isFigureKey = ([key]) => !NON_FIGURE_KEYS.has(key);
Expand Down

0 comments on commit e420d8b

Please sign in to comment.