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 2, 2021
1 parent 435595c commit a3df660
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,4 +1,5 @@
import escapeStringRegexp from 'escape-string-regexp';
import isUnicodeSupported from 'is-unicode-supported';

const {platform} = process;

Expand Down Expand Up @@ -286,9 +287,8 @@ export const windowsSymbols = {
oneTenth: '1/10'
};

// 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;
export default figures;

const isWindowsSymbol = ([key, mainSymbol]) => figures[key] !== mainSymbol;
Expand All @@ -308,7 +308,7 @@ const getReplacements = () => {

// On Windows, substitute non-Windows to Windows figures
export const 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 @@ -35,7 +35,8 @@
"fallback"
],
"dependencies": {
"escape-string-regexp": "^5.0.0"
"escape-string-regexp": "^5.0.0",
"is-unicode-supported": "^1.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
Expand Down
3 changes: 2 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import test from 'ava';
import isUnicodeSupported from 'is-unicode-supported';
// eslint-disable-next-line unicorn/import-index, import/extensions
import figures, {replaceSymbols, mainSymbols, windowsSymbols} from './index.js';

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 a3df660

Please sign in to comment.