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 Jul 1, 2021
1 parent 483ed89 commit 37bd303
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 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,9 +285,8 @@ if (platform === 'linux') {
mainSymbols.questionMarkPrefix = '?';
}

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

const isWindowsSymbol = ([key, mainSymbol]) => figures[key] !== mainSymbol;
const getFigureRegExp = ([key, mainSymbol]) => [new RegExp(escapeStringRegexp(mainSymbol), 'g'), windowsSymbols[key]];
Expand All @@ -307,7 +307,7 @@ module.exports = figures;

// On Windows, substitute non-Windows to Windows figures
module.exports.replaceSymbols = string => {
if (!shouldUseWindows) {
if (shouldUseMain) {
return string;
}

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, mainSymbols, windowsSymbols} from '.';

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

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

0 comments on commit 37bd303

Please sign in to comment.