easy-cli-framework
Version:
A framework for building CLI applications that are robust and easy to maintain. Supports theming, configuration files, interactive prompts, and more.
67 lines (63 loc) • 1.64 kB
JavaScript
var ora = require('ora');
/**
* A class to handle themed spinners
*
* @class ThemedSpinner
*
* @param {EasyCLITheme} theme The theme to use
* @param {DisplayOptions} displayOptions The display options for the spinner
*
* @example
* ```typescript
* const theme = new EasyCLITheme();
* const spinner = new ThemedSpinner(theme, 'default');
* spinner.start('Loading...');
* ```
*/
class ThemedSpinner {
/**
* Creates an instance of ThemedSpinner
* @param {EasyCLITheme} theme The theme to use
* @param {DisplayOptions} displayOptions The display options for the spinner
*/
constructor(theme, displayOptions) {
this.theme = theme;
this.displayOptions = displayOptions;
}
/**
* Starts the spinner
*
* @param {string} text The text to display
* @param {Partial<Ora>} [options={}] The options for the spinner
*
* @returns {Ora} The spinner instance
*
* @example
* ```typescript
* spinner.start('Loading...');
* ```
*/
start(text, options = {}) {
var _a;
this.spinner = ora({
...options,
text: (_a = this.theme) === null || _a === undefined ? undefined : _a.formattedString(text, this.displayOptions),
});
return this.spinner.start();
}
/**
* Stops the spinner
*
* @example
* ```typescript
* spinner.stop();
* ```
*/
stop() {
var _a;
(_a = this.spinner) === null || _a === undefined ? undefined : _a.stop();
this.spinner = null;
}
}
exports.ThemedSpinner = ThemedSpinner;
;