Skip to content

Commit

Permalink
Expose the spinner interval as a getter
Browse files Browse the repository at this point in the history
Fixes #202
  • Loading branch information
sindresorhus committed Feb 21, 2022
1 parent c5026b7 commit 447812b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions index.d.ts
Expand Up @@ -179,6 +179,13 @@ export interface Ora {
*/
indent: number;

/**
The interval between each frame.
The interval is decided by the chosen spinner.
*/
readonly interval: number;

/**
Start the spinner.
Expand Down
10 changes: 7 additions & 3 deletions index.js
Expand Up @@ -119,7 +119,7 @@ class Ora {

this.color = this.options.color;
this.hideCursor = this.options.hideCursor !== false;
this.interval = this.options.interval || this.spinner.interval || 100;
this._interval = this.options.interval || this.spinner.interval || 100;
this.stream = this.options.stream;
this.id = undefined;
this.isEnabled = typeof this.options.isEnabled === 'boolean' ? this.options.isEnabled : isInteractive({stream: this.stream});
Expand Down Expand Up @@ -149,10 +149,14 @@ class Ora {

_updateInterval(interval) {
if (interval !== undefined) {
this.interval = interval;
this._interval = interval;
}
}

get interval() {
return this._interval;
}

get spinner() {
return this._spinner;
}
Expand Down Expand Up @@ -330,7 +334,7 @@ class Ora {
}

this.render();
this.id = setInterval(this.render.bind(this), this.interval);
this.id = setInterval(this.render.bind(this), this._interval);

return this;
}
Expand Down

0 comments on commit 447812b

Please sign in to comment.