symfony-style-console
Version:
Use the style and utilities of the Symfony Console in Node.js
94 lines (93 loc) • 2.78 kB
TypeScript
import { StringHash } from '../Helper/Helper';
import OutputStyle from '../Style/OutputStyle';
/**
* The options that go into a `doAsk` call.
*/
export interface QuestionnaireOptions {
/**
* The question string to show. May contain styles.
*/
question: string;
/**
* Validates given answers.
*/
validator: AnswerValidator;
/**
* Whether the input characters should be hidden.
*/
hideInput: boolean;
errorMsg: string | ((value: string) => string);
}
/**
* A callback to validate answer strings.
*/
export declare type AnswerValidator = (value: string) => boolean;
/**
* Provides simple Q&A with text input, password input, choice and confirmation
*
* @author Florian Reuschel <florian@loilo.de>
*/
export default class Questionnaire {
/**
* The output to use for the questions.
*/
private output;
/**
* Creates a new Questionnaire instance.
*
* @param output The output to use for the questions.
*/
constructor(output: OutputStyle);
/**
* Initializes the Node.js `readline` module.
*/
private static initReadline;
/**
* Checks if a string does contain anything but whitespace.
*
* @param value The string to check
*/
private static isFilled;
/**
* Disables the printing of `stdin` data to `stdout`.
*
* @param char The character that's currently going into `stdin`
*/
private static suppressStdinOutput;
/**
* Performs the actual interaction between user and terminal via `readline`.
*
* @param _ Question options
*/
private doAsk;
/**
* Ask for a string answer.
*
* @param question The (formatted) question to put
* @param defaultValue A default value to provide
* @param validator A validator callback
*/
ask(question: string, defaultValue?: string, validator?: AnswerValidator): Promise<string>;
/**
* Ask for a string answer, hide input chars.
*
* @param question The (formatted) question to put
* @param validator A validator callback
*/
askHidden(question: string, validator?: AnswerValidator): Promise<string>;
/**
* Ask for picking an option.
*
* @param question The (formatted) question to put
* @param choices A value-label map of options
* @param defaultValue A default value to provide
*/
choice(question: string, choices: StringHash, defaultValue?: string): Promise<string>;
/**
* Ask a yes/no question.
*
* @param question The (formatted) question to put
* @param defaultValue If the answer should default to "yes"
*/
confirm(question: string, defaultValue?: boolean): Promise<boolean>;
}