From 8187c63f0b45304db78edcdfe04d825226701537 Mon Sep 17 00:00:00 2001 From: OWA Framework Date: Sun, 23 Jun 2019 09:06:14 -0700 Subject: [PATCH 1/6] Use dots animation in certain Windows shells that support it --- README.md | 10 +++++----- changelog.md | 4 ++++ index.js | 6 +++--- utils.js | 15 ++++++++++++--- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f6fef9a..651c344 100644 --- a/README.md +++ b/README.md @@ -45,16 +45,16 @@ Parameters - **spinnerColor** - `string`: Any valid [chalk color](https://github.com/chalk/chalk#colors). The default value is `greenBright`. - **succeedPrefix** - `string`: The default value is ✓. - **failPrefix**- `string`: The default value is ✖. - - **spinner**- `object`: + - **spinner**- `object`: - **interval** - `number` - **frames** - `string[]` - + You can see the already provided spinner [here](https://github.com/jcarpanelli/spinnies/blob/master/spinners.json). - **disableSpins** - `boolean`: Disable spins (will still print raw messages). -*Note: If you are working in any `win32` platform, the default spin animation will be overriden. You can get rid of this defining a different spinner animation manually.* +*Note: If you are working in any `win32` platform, the default spin animation will be overriden. You can get rid of this defining a different spinner animation manually, or by using the integrated VSCode terminal or Windows Terminal.* -Example: +Example: ```js const spinner = { interval: 80, frames: ['🍇', '🍈', '🍉', '🍋'] } @@ -132,7 +132,7 @@ Parameters: Return value: Returns the spinner's options. -Example: +Example: ```js const spinnies = new Spinnies(); diff --git a/changelog.md b/changelog.md index 19848fd..a05dd8c 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.4.3] - 2019-06-123 +### Changed +- Use the Unicode dots animation when run inside a VSCode integrated terminal or Windows Terminal. + ## [0.4.2] - 2019-06-18 ### Fixed - Fix line breaks when a custom succeedPrefix/failPrefix is provided diff --git a/index.js b/index.js index 2f0f106..7615423 100644 --- a/index.js +++ b/index.js @@ -5,17 +5,17 @@ const chalk = require('chalk'); const cliCursor = require('cli-cursor'); const { dashes, dots } = require('./spinners'); -const { purgeSpinnerOptions, purgeSpinnersOptions, colorOptions, breakText, getLinesLength } = require('./utils'); +const { purgeSpinnerOptions, purgeSpinnersOptions, colorOptions, breakText, getLinesLength, terminalSupportsUnicode } = require('./utils'); const { isValidStatus, writeStream, cleanStream } = require('./utils'); class Spinnies { constructor(options = {}) { options = purgeSpinnersOptions(options); - this.options = { + this.options = { spinnerColor: 'greenBright', succeedColor: 'green', failColor: 'red', - spinner: process.platform === 'win32' ? dashes : dots, + spinner: !terminalSupportsUnicode() ? dashes : dots, disableSpins: false, ...options }; diff --git a/utils.js b/utils.js index 141a01e..d974a7f 100644 --- a/utils.js +++ b/utils.js @@ -28,7 +28,7 @@ function purgeSpinnersOptions({ spinner, disableSpins, ...others }) { } function turnToValidSpinner(spinner = {}) { - const platformSpinner = process.platform === 'win32' ? dashes : dots; + const platformSpinner = !terminalSupportsUnicode() ? dashes : dots; if (!typeof spinner === 'object') return platformSpinner; let { interval, frames } = spinner; if (!Array.isArray(frames) || frames.length < 1) frames = platformSpinner.frames; @@ -47,8 +47,8 @@ function colorOptions({ color, succeedColor, failColor, spinnerColor }) { } function prefixOptions({ succeedPrefix, failPrefix }) { - succeedPrefix = succeedPrefix ? succeedPrefix : (process.platform === 'win32' ? '√' : '✓'); - failPrefix = failPrefix ? failPrefix : (process.platform === 'win32' ? '×' : '✖'); + succeedPrefix = succeedPrefix ? succeedPrefix : (!terminalSupportsUnicode() ? '√' : '✓'); + failPrefix = failPrefix ? failPrefix : (!terminalSupportsUnicode() ? '×' : '✖'); return { succeedPrefix, failPrefix }; } @@ -90,6 +90,14 @@ function cleanStream(stream, rawLines) { readline.moveCursor(stream, 0, -rawLines.length); } +function terminalSupportsUnicode() { + // The default command prompt and powershell in Windows do not support Unicode characters. + // However, the VSCode integrated terminal and the Windows Terminal both do. + return process.platform !== 'win32' + || process.env.TERM_PROGRAM === 'vscode' + || !!process.env.WT_SESSION +} + module.exports = { purgeSpinnersOptions, purgeSpinnerOptions, @@ -98,4 +106,5 @@ module.exports = { getLinesLength, writeStream, cleanStream, + terminalSupportsUnicode, } From 21fa8bd26773ff4645511c8c84e248d305581b0f Mon Sep 17 00:00:00 2001 From: Michael Loughry Date: Mon, 1 Jul 2019 10:06:30 -0700 Subject: [PATCH 2/6] Update changelog.md Co-Authored-By: Juan Bautista Carpanelli --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index a05dd8c..911e617 100644 --- a/changelog.md +++ b/changelog.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.4.3] - 2019-06-123 +## Unreleased ### Changed - Use the Unicode dots animation when run inside a VSCode integrated terminal or Windows Terminal. From f43bc8efa6e727e44db53f820ade0f03f44c7f5c Mon Sep 17 00:00:00 2001 From: Michael Loughry Date: Mon, 1 Jul 2019 10:06:38 -0700 Subject: [PATCH 3/6] Update index.js Co-Authored-By: Juan Bautista Carpanelli --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7615423..8781bf0 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,7 @@ class Spinnies { spinnerColor: 'greenBright', succeedColor: 'green', failColor: 'red', - spinner: !terminalSupportsUnicode() ? dashes : dots, + spinner: terminalSupportsUnicode() ? dots : dashes, disableSpins: false, ...options }; From f07842ccd9101343fb9132e06a02973131edd3cd Mon Sep 17 00:00:00 2001 From: Michael Loughry Date: Mon, 1 Jul 2019 10:06:43 -0700 Subject: [PATCH 4/6] Update utils.js Co-Authored-By: Juan Bautista Carpanelli --- utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.js b/utils.js index d974a7f..b9daba7 100644 --- a/utils.js +++ b/utils.js @@ -28,7 +28,7 @@ function purgeSpinnersOptions({ spinner, disableSpins, ...others }) { } function turnToValidSpinner(spinner = {}) { - const platformSpinner = !terminalSupportsUnicode() ? dashes : dots; + const platformSpinner = terminalSupportsUnicode() ? dots : dashes; if (!typeof spinner === 'object') return platformSpinner; let { interval, frames } = spinner; if (!Array.isArray(frames) || frames.length < 1) frames = platformSpinner.frames; From ee46f9e0ac6c88cf8e254286c365a60811641bd6 Mon Sep 17 00:00:00 2001 From: Michael Loughry Date: Mon, 1 Jul 2019 10:08:47 -0700 Subject: [PATCH 5/6] Perform suggested refactor --- utils.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/utils.js b/utils.js index b9daba7..d96338f 100644 --- a/utils.js +++ b/utils.js @@ -47,8 +47,13 @@ function colorOptions({ color, succeedColor, failColor, spinnerColor }) { } function prefixOptions({ succeedPrefix, failPrefix }) { - succeedPrefix = succeedPrefix ? succeedPrefix : (!terminalSupportsUnicode() ? '√' : '✓'); - failPrefix = failPrefix ? failPrefix : (!terminalSupportsUnicode() ? '×' : '✖'); + if(terminalSupportUnicode()) { + succeedPrefix = succeedPrefix || '✓'; + failPrefix = failPrefix || '✖'; + } else { + succeedPrefix = succeedPrefix || '√'; + failPrefix = failPrefix || '×'; + } return { succeedPrefix, failPrefix }; } From 807d5a46d535358c2855e67b3a26d3620e648c97 Mon Sep 17 00:00:00 2001 From: Juan Bautista Carpanelli Date: Mon, 1 Jul 2019 19:22:25 -0300 Subject: [PATCH 6/6] Fix function call in utils.js --- utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.js b/utils.js index d96338f..10361f4 100644 --- a/utils.js +++ b/utils.js @@ -47,7 +47,7 @@ function colorOptions({ color, succeedColor, failColor, spinnerColor }) { } function prefixOptions({ succeedPrefix, failPrefix }) { - if(terminalSupportUnicode()) { + if(terminalSupportsUnicode()) { succeedPrefix = succeedPrefix || '✓'; failPrefix = failPrefix || '✖'; } else {