Comparing version 3.2.0 to 3.3.0
/// <reference types="node"/> | ||
import {Writable} from 'stream'; | ||
import {Writable as WritableStream} from 'stream'; | ||
import {SpinnerName} from 'cli-spinners'; | ||
@@ -28,2 +28,7 @@ | ||
/** | ||
* Text to display before the spinner. | ||
*/ | ||
prefixText?: string; | ||
/** | ||
* Name of one of the provided spinners. See [`example.js`](https://github.com/BendingBender/ora/blob/master/example.js) in this repo if you want to test out different spinners. On Windows, it will always use the line spinner as the Windows command-line doesn't have proper Unicode support. | ||
@@ -80,3 +85,3 @@ * | ||
*/ | ||
stream?: Writable; | ||
stream?: WritableStream; | ||
@@ -119,5 +124,10 @@ /** | ||
/** | ||
* Text to be persisted. Default: Current text. | ||
* Text to be persisted after the symbol. Default: Current `text`. | ||
*/ | ||
text?: string; | ||
/** | ||
* Text to be persisted before the symbol. Default: Current `prefixText`. | ||
*/ | ||
prefixText?: string; | ||
}>; | ||
@@ -132,5 +142,10 @@ | ||
/** | ||
* Change the text. | ||
* Change the text after the spinner. | ||
*/ | ||
text: string; | ||
/** | ||
* Change the text before the spinner. | ||
*/ | ||
prefixText: string; | ||
@@ -137,0 +152,0 @@ /** |
33
index.js
@@ -10,2 +10,3 @@ 'use strict'; | ||
const TEXT = Symbol('text'); | ||
const PREFIX_TEXT = Symbol('prefixText'); | ||
@@ -37,2 +38,3 @@ class Ora { | ||
this.text = this.options.text; | ||
this.prefixText = this.options.prefixText; | ||
this.linesToClear = 0; | ||
@@ -83,2 +85,6 @@ this.indent = this.options.indent; | ||
get prefixText() { | ||
return this[PREFIX_TEXT]; | ||
} | ||
get isSpinning() { | ||
@@ -88,6 +94,6 @@ return this.id !== null; | ||
set text(value) { | ||
this[TEXT] = value; | ||
updateLineCount() { | ||
const columns = this.stream.columns || 80; | ||
this.lineCount = stripAnsi('--' + value).split('\n').reduce((count, line) => { | ||
const fullPrefixText = (typeof this[PREFIX_TEXT] === 'string') ? this[PREFIX_TEXT] + '-' : ''; | ||
this.lineCount = stripAnsi(fullPrefixText + '--' + this[TEXT]).split('\n').reduce((count, line) => { | ||
return count + Math.max(1, Math.ceil(wcwidth(line) / columns)); | ||
@@ -97,2 +103,12 @@ }, 0); | ||
set text(value) { | ||
this[TEXT] = value; | ||
this.updateLineCount(); | ||
} | ||
set prefixText(value) { | ||
this[PREFIX_TEXT] = value; | ||
this.updateLineCount(); | ||
} | ||
frame() { | ||
@@ -107,4 +123,6 @@ const {frames} = this.spinner; | ||
this.frameIndex = ++this.frameIndex % frames.length; | ||
const fullPrefixText = typeof this.prefixText === 'string' ? this.prefixText + ' ' : ''; | ||
const fullText = typeof this.text === 'string' ? ' ' + this.text : ''; | ||
return frame + ' ' + this.text; | ||
return fullPrefixText + frame + fullText; | ||
} | ||
@@ -196,4 +214,9 @@ | ||
stopAndPersist(options = {}) { | ||
const prefixText = options.prefixText || this.prefixText; | ||
const fullPrefixText = (typeof prefixText === 'string') ? prefixText + ' ' : ''; | ||
const text = options.text || this.text; | ||
const fullText = (typeof text === 'string') ? ' ' + text : ''; | ||
this.stop(); | ||
this.stream.write(`${options.symbol || ' '} ${options.text || this.text}\n`); | ||
this.stream.write(`${fullPrefixText}${options.symbol || ' '}${fullText}n`); | ||
@@ -200,0 +223,0 @@ return this; |
{ | ||
"name": "ora", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "Elegant terminal spinner", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -53,2 +53,8 @@ # ora [![Build Status](https://travis-ci.org/sindresorhus/ora.svg?branch=master)](https://travis-ci.org/sindresorhus/ora) | ||
##### prefixText | ||
Type: `string` | ||
Text to display before the spinner. | ||
##### spinner | ||
@@ -166,6 +172,13 @@ | ||
Type: `string`<br> | ||
Default: Current text | ||
Default: Current `text` | ||
Text to be persisted. | ||
Text to be persisted after the symbol | ||
###### prefixText | ||
Type: `string`<br> | ||
Default: Current `prefixText` | ||
Text to be persisted before the symbol. | ||
<img src="screenshot-2.gif" width="480"> | ||
@@ -187,4 +200,8 @@ | ||
Change the text. | ||
Change the text after the spinner. | ||
#### .prefixText | ||
Change the text before the spinner. | ||
#### .color | ||
@@ -191,0 +208,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17562
398
240