ez-cli-tools
Advanced tools
Comparing version 1.0.3 to 1.3.1
@@ -19,1 +19,3 @@ "use strict"; | ||
__exportStar(require("./src/options-cli.js"), exports); | ||
__exportStar(require("./src/progress.js"), exports); | ||
__exportStar(require("./src/write.js"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.colors = void 0; | ||
/** | ||
* A collection of color functions that can be used to colorize text for the output stream. | ||
* This assumes that the output stream supports ANSI color codes. | ||
*/ | ||
exports.colors = { | ||
@@ -5,0 +9,0 @@ red: colorize(31), |
@@ -5,2 +5,6 @@ "use strict"; | ||
const interface_js_1 = require("./interface.js"); | ||
/** | ||
* Erases the specified number of lines from the output stream. | ||
* @param n The number of lines to erase. | ||
*/ | ||
function eraseLines(n) { | ||
@@ -7,0 +11,0 @@ let eraser = ''; |
@@ -5,4 +5,14 @@ "use strict"; | ||
const promises_1 = require("node:readline/promises"); | ||
exports.input = process.stdin; | ||
exports.output = process.stdout; | ||
const node_process_1 = require("node:process"); | ||
/** | ||
* The standard input stream to use for reading user input. | ||
*/ | ||
exports.input = node_process_1.stdin; | ||
/** | ||
* The standard output stream to use for writing output. | ||
*/ | ||
exports.output = node_process_1.stdout; | ||
/** | ||
* The interface to use for reading user input and writing output. | ||
*/ | ||
exports.readlineInterface = (0, promises_1.createInterface)({ input: exports.input, output: exports.output }); |
@@ -18,2 +18,9 @@ "use strict"; | ||
}; | ||
/** | ||
* Asks the user to select one or more choices from a list. The user can use the arrow keys to navigate the list, the space key to select a choice, and the return key to submit their selection. | ||
* @param question The question to ask the user. | ||
* @param choices The choices to display to the user. | ||
* @param options SelectOptions The options for the select function. | ||
* @returns | ||
*/ | ||
function select(question, choices, options) { | ||
@@ -20,0 +27,0 @@ const opts = { ...defaultSelectOptions, ...(options ?? {}) }; |
@@ -5,4 +5,9 @@ "use strict"; | ||
const interface_js_1 = require("./interface.js"); | ||
/** | ||
* Asks a question and returns the user's input. | ||
* @param question The question to ask the user. A space will be appended to the end of the question. | ||
* @returns The user's input. | ||
*/ | ||
async function ask(question) { | ||
return interface_js_1.readlineInterface.question(question + ' '); | ||
} |
export * from './src/question-cli.js'; | ||
export * from './src/options-cli.js'; | ||
export * from './src/progress.js'; | ||
export * from './src/write.js'; |
@@ -0,1 +1,5 @@ | ||
/** | ||
* A collection of color functions that can be used to colorize text for the output stream. | ||
* This assumes that the output stream supports ANSI color codes. | ||
*/ | ||
export declare const colors: { | ||
@@ -13,1 +17,5 @@ red: (text: string) => string; | ||
}; | ||
/** | ||
* The available colors to use for text. | ||
*/ | ||
export type Color = keyof typeof colors; |
@@ -0,1 +1,5 @@ | ||
/** | ||
* Erases the specified number of lines from the output stream. | ||
* @param n The number of lines to erase. | ||
*/ | ||
export declare function eraseLines(n: number): void; |
@@ -0,7 +1,16 @@ | ||
/** | ||
* The standard input stream to use for reading user input. | ||
*/ | ||
export declare const input: NodeJS.ReadStream & { | ||
fd: 0; | ||
}; | ||
/** | ||
* The standard output stream to use for writing output. | ||
*/ | ||
export declare const output: NodeJS.WriteStream & { | ||
fd: 1; | ||
}; | ||
/** | ||
* The interface to use for reading user input and writing output. | ||
*/ | ||
export declare const readlineInterface: import("readline/promises").Interface; |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Options for the `select` function. | ||
* @property multiple Whether the user can select multiple choices. Defaults to `false`. | ||
* @property required Whether the user must select at least one choice. Defaults to `true`. | ||
* @property selectedIndicatorCharacter The character to use to indicate a selected choice. Defaults to `*`. | ||
* @property cursorCharacter The character to use to indicate the cursor. Defaults to `>`. | ||
*/ | ||
export interface SelectOptions { | ||
@@ -7,2 +14,9 @@ multiple?: boolean; | ||
} | ||
/** | ||
* Asks the user to select one or more choices from a list. The user can use the arrow keys to navigate the list, the space key to select a choice, and the return key to submit their selection. | ||
* @param question The question to ask the user. | ||
* @param choices The choices to display to the user. | ||
* @param options SelectOptions The options for the select function. | ||
* @returns | ||
*/ | ||
export declare function select(question: string, choices: string[], options?: SelectOptions): Promise<string[]>; |
@@ -0,1 +1,6 @@ | ||
/** | ||
* Asks a question and returns the user's input. | ||
* @param question The question to ask the user. A space will be appended to the end of the question. | ||
* @returns The user's input. | ||
*/ | ||
export declare function ask(question: string): Promise<string>; |
{ | ||
"name": "ez-cli-tools", | ||
"version": "1.0.3", | ||
"version": "1.3.1", | ||
"description": "Typescript first CLI tools for Node.js with zero dependencies", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -27,4 +27,25 @@ # EZ CLI Tools | ||
- [Writing](docs/write.md) | ||
- [Questions](docs/question.md) | ||
- [Single Select](docs/single-select.md) | ||
- [Multi Select](docs/multi-select.md) | ||
- [Progress](docs/progress.md) | ||
### Brief Example | ||
```ts | ||
import { writeLine, ask, select, printSpinner, endIntervalAndClearStatus } from 'ez-cli-tools'; | ||
import { setTimeout } from 'timers/promises'; | ||
(async () => { | ||
const name = await ask('What is your name?'); | ||
await writeLine(`Hello ${name}`); | ||
const game = await select('Shall we play a game?', ['Checkers', 'Chess', 'Tic-Tac-Toe', 'Global Thermonuclear War']); | ||
await writeLine(`Great! Let's play ${game}`); | ||
const intervalId = printSpinner(); | ||
await setTimeout(10000); // Normally you would be doing a long running operation here, which is why you would show a spinner | ||
endIntervalAndClearStatus(intervalId); | ||
await writeLine('An interesting game. The only winning move is not to play.'); | ||
})(); | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39703
30
833
51