Skip to content

Commit

Permalink
Improve detection for terminals supporting Unicode
Browse files Browse the repository at this point in the history
Closes #26
  • Loading branch information
sindresorhus committed Mar 17, 2021
1 parent 8b5b437 commit 2f0c0d3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Includes fallbacks for Windows CMD which only supports a [limited character set]
import logSymbols = require('log-symbols');
console.log(logSymbols.success, 'Finished successfully!');
// On good OSes: βœ” Finished successfully!
// On Windows: √ Finished successfully!
// Terminals with Unicode support: βœ” Finished successfully!
// Terminals without Unicode support: √ Finished successfully!
```
*/
declare const logSymbols: {
Expand Down
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const chalk = require('chalk');

const isSupported = process.platform !== 'win32' || process.env.CI || process.env.TERM === 'xterm-256color';
const isUnicodeSupported = require('is-unicode-supported');

const main = {
info: chalk.blue('β„Ή'),
Expand All @@ -10,11 +9,11 @@ const main = {
error: chalk.red('βœ–')
};

const fallbacks = {
const fallback = {
info: chalk.blue('i'),
success: chalk.green('√'),
warning: chalk.yellow('β€Ό'),
error: chalk.red('Γ—')
};

module.exports = isSupported ? main : fallbacks;
module.exports = isUnicodeSupported() ? main : fallback;
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Colored symbols for various log levels. Example: `βœ”οΈŽ Success`",
"license": "MIT",
"repository": "sindresorhus/log-symbols",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
Expand Down Expand Up @@ -38,13 +39,14 @@
"stdout"
],
"dependencies": {
"chalk": "^4.0.0"
"chalk": "^4.1.0",
"is-unicode-supported": "^0.1.0"
},
"devDependencies": {
"ava": "^3.7.1",
"ava": "^2.4.0",

This comment has been minimized.

Copy link
@papb

papb Mar 17, 2021

Why did you downgrade ava?

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Mar 18, 2021

Author Owner

Just muscle memory to downgrade AVA after I upgrade all dependencies since I don't want the churn of switching all import to require and in a month to import again. Obviously, doesn't apply in this case, but that's why it happened.

"strip-ansi": "^6.0.0",
"tsd": "^0.11.0",
"xo": "^0.30.0"
"tsd": "^0.14.0",
"xo": "^0.38.2"
},
"browser": "browser.js"
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ $ npm install log-symbols
const logSymbols = require('log-symbols');

console.log(logSymbols.success, 'Finished successfully!');
// On good OSes: βœ” Finished successfully!
// On Windows: √ Finished successfully!
// Terminals with Unicode support: βœ” Finished successfully!
// Terminals without Unicode support: √ Finished successfully!
```

## API
Expand Down

0 comments on commit 2f0c0d3

Please sign in to comment.