UNPKG

resin-cli-visuals

Version:
153 lines (152 loc) 3.65 kB
/** * @module dynamiclist */ import * as Bluebird from 'bluebird'; import InquirerList = require('inquirer/lib/prompts/list'); import UI = require('inquirer/lib/ui/baseUI'); declare class DynamicList extends InquirerList { options: ConstructorParameters<typeof InquirerList>[0] & { emptyMessage: string; }; ui: UI; /** * @summary Dynamic list widget * @name DynamicList * @class * @public * * @param {Object} [options] - options * @param {Object[]} options.choices - initial choices * @param {String} options.message - widget message * @param {String} [options.emptyMessage='No options'] - message for when no choices * * @example * list = new DynamicList * message: 'Foo' * emptyMessage: 'Nothing to show' * choices: [ * name: 'Foo' * value: 'foo' * ] * * # Run the list widget * list.run().then (answer) -> * console.log(answer) * * # You can add new choices on the fly * list.addChoice * name: 'Bar' * value: 'bar' * * # We re-render to be able to see the new options * list.render() */ constructor(options: ConstructorParameters<typeof InquirerList>[0] & { emptyMessage?: string; }); /** * @summary Check if the list is empty * @method * @private * * @returns {Boolean} whether is empty * * @example * list = new DynamicList * message: 'Foo' * emptyMessage: 'Nothing to show' * choices: [ * name: 'Foo' * value: 'foo' * ] * * if list.isEmpty() * console.log('The list is empty') */ isEmpty(): boolean; /** * @summary Event listener for when a choice is selected * @method * @private */ onSubmit(...args: Parameters<InquirerList['onSubmit']>): void; /** * @summary Render the list * @method * @public * * @example * list = new DynamicList * message: 'Foo' * emptyMessage: 'Nothing to show' * choices: [ * name: 'Foo' * value: 'foo' * ] * * list.render() */ render(...args: Parameters<InquirerList['render']>): void; /** * @summary Add a choice * @method * @public * * @param {Object} choice - choice * * @example * list = new DynamicList * message: 'Foo' * emptyMessage: 'Nothing to show' * choices: [ * name: 'Foo' * value: 'foo' * ] * * list.addChoice(name: 'Bar', value: 'bar') * list.render() */ addChoice(choice: Parameters<DynamicList['opt']['choices']['push']>[0]): number; /** * @summary Remove a choice * @method * @public * * @param {Object} choice - choice * * @example * list = new DynamicList * message: 'Foo' * emptyMessage: 'Nothing to show' * choices: [ * name: 'Foo' * value: 'foo' * ] * * list.removeChoice(name: 'Foo', value: 'foo') * list.render() */ removeChoice(choice: DynamicList['opt']['choices']['choices'][number]): void; /** * @summary Run the widget * @method * @public * * @fulfil {String} answer * @returns {Promise} * * @example * list = new DynamicList * message: 'Foo' * emptyMessage: 'Nothing to show' * choices: [ * name: 'Foo' * value: 'foo' * ] * * list.run().then (answer) -> * console.log(answer) */ run(): Bluebird<any>; } export default DynamicList;