Socket
Socket
Sign inDemoInstall

@inquirer/core

Package Overview
Dependencies
Maintainers
3
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inquirer/core - npm Package Compare versions

Comparing version 2.3.1 to 3.0.0

35

./dist/cjs/index.js

@@ -20,12 +20,14 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createPrompt = exports.useRef = exports.useKeypress = exports.useEffect = exports.useState = exports.usePrefix = void 0;
exports.createPrompt = exports.usePagination = exports.useRef = exports.useKeypress = exports.useEffect = exports.useState = exports.usePrefix = void 0;
const node_readline_1 = __importDefault(require("node:readline"));
const type_1 = require("@inquirer/type");
const chalk_1 = __importDefault(require("chalk"));
const cli_width_1 = __importDefault(require("cli-width"));
const mute_stream_1 = __importDefault(require("mute-stream"));
const screen_manager_mjs_1 = __importDefault(require('./lib/screen-manager.js'));
const options_mjs_1 = require('./lib/options.js');
const utils_mjs_1 = require('./lib/utils.js');
var prefix_mjs_1 = require('./lib/prefix.js');
Object.defineProperty(exports, "usePrefix", { enumerable: true, get: function () { return prefix_mjs_1.usePrefix; } });
__exportStar(require('./lib/key.js'), exports);
__exportStar(require('./lib/Paginator.js'), exports);
__exportStar(require('./lib/Separator.js'), exports);

@@ -137,2 +139,31 @@ const hooks = [];

exports.useRef = useRef;
function usePagination(output, { active, pageSize = 7, }) {
const state = useRef({
pointer: 0,
lastIndex: 0,
});
const rl = sessionRl;
if (!rl) {
throw new Error('usePagination must be used within a prompt');
}
const width = (0, cli_width_1.default)({ defaultWidth: 80, output: rl.output });
const lines = (0, utils_mjs_1.breakLines)(output, width).split('\n');
// Make sure there's enough lines to paginate
if (lines.length <= pageSize) {
return output;
}
const middleOfList = Math.floor(pageSize / 2);
// Move the pointer only when the user go down and limit it to the middle of the list
const { pointer: prevPointer, lastIndex } = state.current;
if (prevPointer < middleOfList && lastIndex < active && active - lastIndex < pageSize) {
state.current.pointer = Math.min(middleOfList, prevPointer + active - lastIndex);
}
state.current.lastIndex = active;
// Duplicate the lines so it give an infinite list look
const infinite = [lines, lines, lines].flat();
const topIndex = Math.max(0, active + lines.length - state.current.pointer);
const section = infinite.splice(topIndex, pageSize).join('\n');
return section + '\n' + chalk_1.default.dim('(Move up and down to reveal more choices)');
}
exports.usePagination = usePagination;
function createPrompt(view) {

@@ -139,0 +170,0 @@ const prompt = (config, context) => {

@@ -20,12 +20,14 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createPrompt = exports.useRef = exports.useKeypress = exports.useEffect = exports.useState = exports.usePrefix = void 0;
exports.createPrompt = exports.usePagination = exports.useRef = exports.useKeypress = exports.useEffect = exports.useState = exports.usePrefix = void 0;
const node_readline_1 = __importDefault(require("node:readline"));
const type_1 = require("@inquirer/type");
const chalk_1 = __importDefault(require("chalk"));
const cli_width_1 = __importDefault(require("cli-width"));
const mute_stream_1 = __importDefault(require("mute-stream"));
const screen_manager_mjs_1 = __importDefault(require('./lib/screen-manager.js'));
const options_mjs_1 = require('./lib/options.js');
const utils_mjs_1 = require('./lib/utils.js');
var prefix_mjs_1 = require('./lib/prefix.js');
Object.defineProperty(exports, "usePrefix", { enumerable: true, get: function () { return prefix_mjs_1.usePrefix; } });
__exportStar(require('./lib/key.js'), exports);
__exportStar(require('./lib/Paginator.js'), exports);
__exportStar(require('./lib/Separator.js'), exports);

@@ -137,2 +139,31 @@ const hooks = [];

exports.useRef = useRef;
function usePagination(output, { active, pageSize = 7, }) {
const state = useRef({
pointer: 0,
lastIndex: 0,
});
const rl = sessionRl;
if (!rl) {
throw new Error('usePagination must be used within a prompt');
}
const width = (0, cli_width_1.default)({ defaultWidth: 80, output: rl.output });
const lines = (0, utils_mjs_1.breakLines)(output, width).split('\n');
// Make sure there's enough lines to paginate
if (lines.length <= pageSize) {
return output;
}
const middleOfList = Math.floor(pageSize / 2);
// Move the pointer only when the user go down and limit it to the middle of the list
const { pointer: prevPointer, lastIndex } = state.current;
if (prevPointer < middleOfList && lastIndex < active && active - lastIndex < pageSize) {
state.current.pointer = Math.min(middleOfList, prevPointer + active - lastIndex);
}
state.current.lastIndex = active;
// Duplicate the lines so it give an infinite list look
const infinite = [lines, lines, lines].flat();
const topIndex = Math.max(0, active + lines.length - state.current.pointer);
const section = infinite.splice(topIndex, pageSize).join('\n');
return section + '\n' + chalk_1.default.dim('(Move up and down to reveal more choices)');
}
exports.usePagination = usePagination;
function createPrompt(view) {

@@ -139,0 +170,0 @@ const prompt = (config, context) => {

6

dist/cjs/lib/utils.js

@@ -17,6 +17,6 @@ "use strict";

.split('\n')
.map((line) => (0, wrap_ansi_1.default)(line, width, { trim: false, hard: true }).split('\n'))
.flat()
.map((line) => line.trimEnd())
.flatMap((line) => (0, wrap_ansi_1.default)(line, width, { trim: false, hard: true })
.split('\n')
.map((line) => line.trimEnd()))
.join('\n');
exports.breakLines = breakLines;

@@ -8,3 +8,2 @@ /// <reference types="node" />

export * from './lib/key.js';
export * from './lib/Paginator.js';
export * from './lib/Separator.js';

@@ -27,2 +26,6 @@ export type InquirerReadline = readline.ReadLine & {

};
export declare function usePagination(output: string, { active, pageSize, }: {
active: number;
pageSize?: number;
}): string;
export type AsyncPromptConfig = {

@@ -29,0 +32,0 @@ message: string | Promise<string> | (() => Promise<string>);

{
"name": "@inquirer/core",
"version": "2.3.1",
"version": "3.0.0",
"engines": {

@@ -100,3 +100,3 @@ "node": ">=14.18.0"

},
"gitHead": "b1b29c0b6da9420d739cd46704c205515de2db04"
"gitHead": "18144628b03b62c346cb7d9d55a2c526b1ed5d8a"
}

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