Skip to content

Commit 253f966

Browse files
authoredJul 2, 2021
Add support for Windows terminals with Unicode fonts (#80)
1 parent 435595c commit 253f966

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed
 

‎index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import escapeStringRegexp from 'escape-string-regexp';
2+
import isUnicodeSupported from 'is-unicode-supported';
23

34
const {platform} = process;
45

@@ -286,9 +287,8 @@ export const windowsSymbols = {
286287
oneTenth: '1/10'
287288
};
288289

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

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

309309
// On Windows, substitute non-Windows to Windows figures
310310
export const replaceSymbols = string => {
311-
if (!shouldUseWindows) {
311+
if (shouldUseMain) {
312312
return string;
313313
}
314314

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"fallback"
3636
],
3737
"dependencies": {
38-
"escape-string-regexp": "^5.0.0"
38+
"escape-string-regexp": "^5.0.0",
39+
"is-unicode-supported": "^1.0.0"
3940
},
4041
"devDependencies": {
4142
"ava": "^3.15.0",

‎test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import test from 'ava';
2+
import isUnicodeSupported from 'is-unicode-supported';
23
// eslint-disable-next-line unicorn/import-index, import/extensions
34
import figures, {replaceSymbols, mainSymbols, windowsSymbols} from './index.js';
45

5-
const result = (mainSymbols, windowsSymbols) => process.platform === 'win32' ? windowsSymbols : mainSymbols;
6+
const result = (mainSymbols, windowsSymbols) => isUnicodeSupported() ? mainSymbols : windowsSymbols;
67

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

0 commit comments

Comments
 (0)