Skip to content

Commit c884e0d

Browse files
committedMar 17, 2021
Improve detection for terminals supporting Unicode
1 parent 498c40a commit c884e0d

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed
 

‎index.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,21 @@ const logSymbols = require('log-symbols');
77
const stripAnsi = require('strip-ansi');
88
const wcwidth = require('wcwidth');
99
const isInteractive = require('is-interactive');
10+
const isUnicodeSupported = require('is-unicode-supported');
1011
const {BufferListStream} = require('bl');
1112

1213
const TEXT = Symbol('text');
1314
const PREFIX_TEXT = Symbol('prefixText');
14-
1515
const ASCII_ETX_CODE = 0x03; // Ctrl+C emits this code
1616

17-
const terminalSupportsUnicode = () => (
18-
process.platform !== 'win32' ||
19-
process.env.TERM_PROGRAM === 'vscode' ||
20-
Boolean(process.env.WT_SESSION)
21-
);
22-
2317
class StdinDiscarder {
2418
constructor() {
2519
this.requests = 0;
2620

2721
this.mutedStream = new BufferListStream();
2822
this.mutedStream.pipe(process.stdout);
2923

30-
const self = this;
24+
const self = this; // eslint-disable-line unicorn/no-this-assignment
3125
this.ourEmit = function (event, data, ...args) {
3226
const {stdin} = process;
3327
if (self.requests > 0 || stdin.emit === self.ourEmit) {
@@ -169,7 +163,7 @@ class Ora {
169163
}
170164

171165
this._spinner = spinner;
172-
} else if (!terminalSupportsUnicode()) {
166+
} else if (!isUnicodeSupported()) {
173167
this._spinner = cliSpinners.line;
174168
} else if (spinner === undefined) {
175169
// Set default spinner

‎index.test-d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {expectType} from 'tsd';
22
import {PassThrough as PassThroughStream} from 'stream';
3-
import ora = require('.');
4-
import {promise} from '.';
3+
import ora = require('./index.js');
4+
import {promise} from './index.js';
55

66
const spinner = ora('Loading unicorns');
77
ora({text: 'Loading unicorns'});

‎package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,21 @@
3737
"idle"
3838
],
3939
"dependencies": {
40-
"bl": "^4.0.3",
40+
"bl": "^4.1.0",
4141
"chalk": "^4.1.0",
4242
"cli-cursor": "^3.1.0",
4343
"cli-spinners": "^2.5.0",
4444
"is-interactive": "^1.0.0",
45-
"log-symbols": "^4.0.0",
45+
"is-unicode-supported": "^0.1.0",
46+
"log-symbols": "^4.1.0",
4647
"strip-ansi": "^6.0.0",
4748
"wcwidth": "^1.0.1"
4849
},
4950
"devDependencies": {
50-
"@types/node": "^14.14.16",
51+
"@types/node": "^14.14.35",
5152
"ava": "^2.4.0",
5253
"get-stream": "^6.0.0",
5354
"tsd": "^0.14.0",
54-
"xo": "^0.36.1"
55+
"xo": "^0.38.2"
5556
}
5657
}

‎test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import {PassThrough as PassThroughStream} from 'stream';
22
import getStream from 'get-stream';
33
import test from 'ava';
44
import stripAnsi from 'strip-ansi';
5-
import Ora from '.';
5+
import Ora from './index.js';
66

7-
const spinnerChar = process.platform === 'win32' ? '-' : '⠋';
7+
const spinnerCharacter = process.platform === 'win32' ? '-' : '⠋';
88
const noop = () => {};
99

1010
const getPassThroughStream = () => {
@@ -41,7 +41,7 @@ const macro = async (t, fn, expected, extraOptions = {}) => {
4141

4242
test('main', macro, spinner => {
4343
spinner.stop();
44-
}, new RegExp(`${spinnerChar} foo`));
44+
}, new RegExp(`${spinnerCharacter} foo`));
4545

4646
test('title shortcut', async t => {
4747
const stream = getPassThroughStream();
@@ -58,7 +58,7 @@ test('title shortcut', async t => {
5858

5959
stream.end();
6060

61-
t.is(await output, `${spinnerChar} foo`);
61+
t.is(await output, `${spinnerCharacter} foo`);
6262
});
6363

6464
test('`.id` is not set when created', t => {
@@ -165,7 +165,7 @@ test('.promise() - resolves', async t => {
165165
test('.promise() - rejects', async t => {
166166
const stream = getPassThroughStream();
167167
const output = getStream(stream);
168-
const rejects = Promise.reject(new Error());
168+
const rejects = Promise.reject(new Error()); // eslint-disable-line unicorn/error-message
169169

170170
Ora.promise(rejects, {
171171
stream,

0 commit comments

Comments
 (0)
Please sign in to comment.