New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ez-cli-tools

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ez-cli-tools - npm Package Compare versions

Comparing version 1.3.2 to 2.0.0

6

dist/cjs/src/eraser.js

@@ -5,2 +5,4 @@ "use strict";

const interface_js_1 = require("./interface.js");
const ESC = '\x1B'; // escape character
const CSI = `${ESC}[`; // control sequence introducer
/**

@@ -13,6 +15,6 @@ * Erases the specified number of lines from the output stream.

for (let i = 0; i < n; i++) {
eraser += `\x1B[2K${i < n - 1 ? '\x1B[1A' : ''}`;
eraser += `${CSI}2K${i < n - 1 ? `${CSI}1A` : ''}`;
}
eraser += '\x1B[0G';
eraser += `${CSI}0G`;
interface_js_1.output.write(eraser);
}

@@ -11,9 +11,3 @@ "use strict";

const eraser_js_1 = require("./eraser.js");
const defaultSelectOptions = {
multiple: false,
required: true,
selectedIndicatorCharacter: '*',
cursorCharacter: '>',
renderMenu: true,
};
const Keypress = 'keypress';
/**

@@ -26,11 +20,26 @@ * 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 {boolean} [options.required=true] Whether the user must select at least one choice.
* @param {string} [options.selectedIndicatorCharacter='*'] The character to use to indicate a selected choice.
* @param {string} [options.cursorCharacter='>'] The character to use to indicate the cursor.
* @param {string} [options.cursor='>'] The string to use to indicate the cursor. Mutually exclusive with `hoverStyle`.
* @param {string} [options.selectedStyle='[*]'] The string to use to indicate a selected choice.
* @param {string} [options.unselectedStyle='[ ]'] The string to use to indicate an unselected choice.
* @param {string} [options.hoverStyle=] The string to use to indicate the cursor when hovering over a choice. Mutually exclusive with `cursor`.
* @returns
*/
function select(question, choices, options) {
const defaultSelectOptions = {
multiple: false,
required: true,
selectedStyle: '[*]',
unselectedStyle: '[ ]',
renderMenu: true,
};
const opts = { ...defaultSelectOptions, ...(options ?? {}) };
(0, node_assert_1.default)(opts.multiple === true || opts.multiple === false, 'multiple must be a boolean');
(0, node_assert_1.default)(opts.selectedIndicatorCharacter.length === 1, 'selectedIndicatorCharacter must be a single character');
(0, node_assert_1.default)(opts.cursorCharacter.length === 1, 'cursorCharacter must be a single character');
const cursor = (opts.cursor === undefined || opts.cursor === null) && (opts.hoverStyle === undefined || opts.hoverStyle === null)
? '>'
: opts.cursor;
const hoverStyle = cursor !== null && cursor !== undefined ? undefined : opts.hoverStyle;
(0, node_assert_1.default)(cursor !== undefined || cursor !== null || hoverStyle !== undefined || hoverStyle !== null, 'cursor or hoverStyle must be defined');
(0, node_assert_1.default)(!(cursor !== undefined && cursor !== null && hoverStyle !== undefined && hoverStyle !== null), 'cursor and hoverStyle are mutually exclusive');
opts.cursor = cursor;
opts.hoverStyle = hoverStyle;
return new Promise((resolve) => {

@@ -45,7 +54,7 @@ const selectChoices = {

selectChoices.cursorIndex = Math.min(selectChoices.choices.length - 1, selectChoices.cursorIndex + 1);
displaySelectMenu(selectChoices, opts);
drawSelectMenu(selectChoices, opts);
break;
case 'up':
selectChoices.cursorIndex = Math.max(0, selectChoices.cursorIndex - 1);
displaySelectMenu(selectChoices, opts);
drawSelectMenu(selectChoices, opts);
break;

@@ -59,3 +68,3 @@ case 'return':

}
interface_js_1.readlineInterface.removeListener('keypress', keypressListener);
interface_js_1.input.removeListener(Keypress, keypressListener);
interface_js_1.readlineInterface.pause();

@@ -70,3 +79,3 @@ return resolve(selectedChoices);

selectedChoice.isSelected = !selectedChoice.isSelected;
displaySelectMenu(selectChoices, opts);
drawSelectMenu(selectChoices, opts);
break;

@@ -76,7 +85,7 @@ }

interface_js_1.readlineInterface.write(question + '\n');
displaySelectMenu(selectChoices, opts);
interface_js_1.input.on('keypress', keypressListener);
drawSelectMenu(selectChoices, opts);
interface_js_1.input.on(Keypress, keypressListener);
});
}
function displaySelectMenu(selectChoices, opts) {
function drawSelectMenu(selectChoices, opts) {
if (opts.renderMenu) {

@@ -89,15 +98,25 @@ opts.renderMenu = false;

const padding = padInput();
const cursor = colors_js_1.colors.blue(opts.cursorCharacter);
const selectedIndicator = colors_js_1.colors.green(opts.selectedIndicatorCharacter);
const selectedIndicator = colors_js_1.colors.green(opts.selectedStyle);
const unselectedIndicator = opts.unselectedStyle;
for (let i = 0; i < selectChoices.choices.length; i++) {
const choice = selectChoices.choices[i];
(0, node_assert_1.default)(choice, 'choice must be defined');
const choiceText = choice?.isSelected ? `[${selectedIndicator}] ${choice.text}` : `[ ] ${choice.text}`;
const displayChoice = i === selectChoices.cursorIndex ? `${cursor} ${choiceText}` : ` ${choiceText}`;
const drawableChoice = choiceToDraw(selectedIndicator, unselectedIndicator, choice.isSelected, i === selectChoices.cursorIndex, choice.text, opts.cursor ? colors_js_1.colors.blue(opts.cursor) : undefined, opts.hoverStyle ? colors_js_1.colors.blue(opts.hoverStyle) : undefined);
const tail = i !== selectChoices.choices.length - 1 ? '\n' : '';
interface_js_1.readlineInterface.write(`${padding}${displayChoice}${tail}`);
interface_js_1.readlineInterface.write(`${padding}${drawableChoice}${tail}`);
}
}
function choiceToDraw(selectedIndicator, unselectedIndicator, isSelected, isHovered, text, cursor, hoverStyle) {
if (cursor) {
const choice = isSelected ? `${selectedIndicator} ${text}` : `${unselectedIndicator} ${text}`;
return isHovered ? `${cursor} ${choice}` : `${padInput(cursor.length - 9)} ${choice}`;
}
(0, node_assert_1.default)(hoverStyle, 'hoverStyle must be defined');
if (isSelected) {
return `${selectedIndicator} ${text}`;
}
return isHovered ? `${hoverStyle} ${text}` : `${unselectedIndicator} ${text}`;
}
function padInput(n = 5) {
return ' '.repeat(n);
}

@@ -11,3 +11,5 @@ "use strict";

async function ask(question) {
return interface_js_1.readlineInterface.question(question + ' ');
const answer = await interface_js_1.readlineInterface.question(question + ' ');
interface_js_1.readlineInterface.pause();
return answer;
}

@@ -5,4 +5,6 @@ /**

* @property {boolean} [required=true] Whether the user must select at least one choice.
* @property {string} [selectedIndicatorCharacter='*'] The character to use to indicate a selected choice.
* @property {string} [cursorCharacter='>'] The character to use to indicate the cursor.
* @property {string} [cursor='>'] The string to use to indicate the cursor. Mutually exclusive with `hoverStyle`.
* @property {string} [selectedStyle='[*]'] The string to use to indicate a selected choice.
* @property {string} [unselectedStyle='[ ]'] The string to use to indicate an unselected choice.
* @property {string} [hoverStyle=] The string to use to indicate the cursor when hovering over a choice. Mutually exclusive with `cursor`.
*/

@@ -12,4 +14,6 @@ export interface SelectOptions {

required?: boolean;
selectedIndicatorCharacter?: string;
cursorCharacter?: string;
cursor?: string;
selectedStyle?: string;
unselectedStyle?: string;
hoverStyle?: string;
}

@@ -23,6 +27,8 @@ /**

* @param {boolean} [options.required=true] Whether the user must select at least one choice.
* @param {string} [options.selectedIndicatorCharacter='*'] The character to use to indicate a selected choice.
* @param {string} [options.cursorCharacter='>'] The character to use to indicate the cursor.
* @param {string} [options.cursor='>'] The string to use to indicate the cursor. Mutually exclusive with `hoverStyle`.
* @param {string} [options.selectedStyle='[*]'] The string to use to indicate a selected choice.
* @param {string} [options.unselectedStyle='[ ]'] The string to use to indicate an unselected choice.
* @param {string} [options.hoverStyle=] The string to use to indicate the cursor when hovering over a choice. Mutually exclusive with `cursor`.
* @returns
*/
export declare function select(question: string, choices: string[], options?: SelectOptions): Promise<string[]>;
{
"name": "ez-cli-tools",
"version": "1.3.2",
"version": "2.0.0",
"description": "Typescript first CLI tools for Node.js with zero dependencies",

@@ -5,0 +5,0 @@ "repository": {

@@ -41,11 +41,11 @@ # EZ CLI Tools

const name = await ask('What is your name?');
await writeLine(`Hello ${name}`);
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}`);
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.');
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc