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 6.0.0 to 7.0.0

dist/cjs/lib/make-theme.js

4

./dist/cjs/index.js

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.Separator = exports.createPrompt = exports.usePagination = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = void 0;
exports.Separator = exports.createPrompt = exports.usePagination = exports.makeTheme = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = void 0;
__exportStar(require('./lib/key.js'), exports);

@@ -32,2 +32,4 @@ var use_prefix_mjs_1 = require('./lib/use-prefix.js');

Object.defineProperty(exports, "useKeypress", { enumerable: true, get: function () { return use_keypress_mjs_1.useKeypress; } });
var make_theme_mjs_1 = require('./lib/make-theme.js');
Object.defineProperty(exports, "makeTheme", { enumerable: true, get: function () { return make_theme_mjs_1.makeTheme; } });
var use_pagination_mjs_1 = require('./lib/pagination/use-pagination.js');

@@ -34,0 +36,0 @@ Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return use_pagination_mjs_1.usePagination; } });

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.Separator = exports.createPrompt = exports.usePagination = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = void 0;
exports.Separator = exports.createPrompt = exports.usePagination = exports.makeTheme = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = void 0;
__exportStar(require('./lib/key.js'), exports);

@@ -32,2 +32,4 @@ var use_prefix_mjs_1 = require('./lib/use-prefix.js');

Object.defineProperty(exports, "useKeypress", { enumerable: true, get: function () { return use_keypress_mjs_1.useKeypress; } });
var make_theme_mjs_1 = require('./lib/make-theme.js');
Object.defineProperty(exports, "makeTheme", { enumerable: true, get: function () { return make_theme_mjs_1.makeTheme; } });
var use_pagination_mjs_1 = require('./lib/pagination/use-pagination.js');

@@ -34,0 +36,0 @@ Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return use_pagination_mjs_1.usePagination; } });

@@ -25,11 +25,2 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -46,9 +37,2 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const hook_engine_mjs_1 = require('./hook-engine.js');
// Take an AsyncPromptConfig and resolves all it's values.
function getPromptConfig(config) {
return __awaiter(this, void 0, void 0, function* () {
const message = typeof config.message === 'function' ? config.message() : config.message;
return Object.assign(Object.assign({}, config), { message: yield message });
});
}
function createPrompt(view) {

@@ -113,3 +97,3 @@ const prompt = (config, context) => {

try {
const nextView = view(resolvedConfig, done);
const nextView = view(config, done);
const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;

@@ -124,11 +108,8 @@ screen.render(content, bottomContent);

}
// TODO: we should display a loader while we get the default options.
getPromptConfig(config).then((resolvedConfig) => {
workLoop(resolvedConfig);
// Re-renders only happen when the state change; but the readline cursor could change position
// and that also requires a re-render (and a manual one because we mute the streams).
// We set the listener after the initial workLoop to avoid a double render if render triggered
// by a state change sets the cursor to the right position.
store.rl.input.on('keypress', checkCursorPos);
}, reject);
workLoop(config);
// Re-renders only happen when the state change; but the readline cursor could change position
// and that also requires a re-render (and a manual one because we mute the streams).
// We set the listener after the initial workLoop to avoid a double render if render triggered
// by a state change sets the cursor to the right position.
store.rl.input.on('keypress', checkCursorPos);
});

@@ -135,0 +116,0 @@ });

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePagination = void 0;
const chalk_1 = __importDefault(require("chalk"));
const use_ref_mjs_1 = require('../use-ref.js');
const utils_mjs_1 = require('../utils.js');
const make_theme_mjs_1 = require('../make-theme.js');
const lines_mjs_1 = require('./lines.js');
const position_mjs_1 = require('./position.js');
function usePagination({ items, active, renderItem, pageSize, loop = true, }) {
function usePagination({ items, active, renderItem, pageSize, loop = true, theme: defaultTheme, }) {
const state = (0, use_ref_mjs_1.useRef)({ position: 0, lastActive: 0 });
const theme = (0, make_theme_mjs_1.makeTheme)(defaultTheme);
const position = loop

@@ -38,3 +36,3 @@ ? (0, position_mjs_1.infinite)({

if (items.length > pageSize) {
return `${visibleLines}\n${chalk_1.default.dim('(Use arrow keys to reveal more choices)')}`;
return `${visibleLines}\n${theme.style.help('(Use arrow keys to reveal more choices)')}`;
}

@@ -41,0 +39,0 @@ return visibleLines;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePrefix = void 0;
const chalk_1 = __importDefault(require("chalk"));
const cli_spinners_1 = __importDefault(require("cli-spinners"));
const use_state_mjs_1 = require('./use-state.js');
const use_effect_mjs_1 = require('./use-effect.js');
const spinner = cli_spinners_1.default.dots;
function usePrefix(isLoading = false) {
const make_theme_mjs_1 = require('./make-theme.js');
function usePrefix({ isLoading = false, theme, }) {
const [tick, setTick] = (0, use_state_mjs_1.useState)(0);
const { prefix, spinner } = (0, make_theme_mjs_1.makeTheme)(theme);
(0, use_effect_mjs_1.useEffect)(() => {

@@ -24,6 +20,6 @@ if (isLoading) {

const frame = tick % spinner.frames.length;
return chalk_1.default.yellow(spinner.frames[frame]);
return spinner.frames[frame];
}
return chalk_1.default.green('?');
return prefix;
}
exports.usePrefix = usePrefix;

@@ -8,5 +8,7 @@ export * from './lib/key.js';

export { useKeypress } from './lib/use-keypress.js';
export { makeTheme } from './lib/make-theme.js';
export type { Theme } from './lib/theme.js';
export { usePagination } from './lib/pagination/use-pagination.js';
export { createPrompt, type PromptConfig, type AsyncPromptConfig, } from './lib/create-prompt.js';
export { createPrompt } from './lib/create-prompt.js';
export { Separator } from './lib/Separator.js';
export { type InquirerReadline } from './lib/read-line.type.js';
import { type Prompt, type Prettify } from '@inquirer/type';
export type AsyncPromptConfig = {
message: string | Promise<string> | (() => Promise<string>);
};
export type PromptConfig<Config> = Prettify<AsyncPromptConfig & Config>;
type ResolvedPromptConfig = {
message: string;
};
type ViewFunction<Value, Config> = (config: Prettify<Config & ResolvedPromptConfig>, done: (value: Value) => void) => string | [string, string | undefined];
export declare function createPrompt<Value, Config extends AsyncPromptConfig>(view: ViewFunction<Value, Config>): Prompt<Value, Config>;
type ViewFunction<Value, Config> = (config: Prettify<Config>, done: (value: Value) => void) => string | [string, string | undefined];
export declare function createPrompt<Value, Config>(view: ViewFunction<Value, Config>): Prompt<Value, Config>;
export {};

@@ -1,4 +0,5 @@

import { type Prettify } from '@inquirer/type';
import type { Prettify } from '@inquirer/type';
import { type Theme } from '../theme.js';
import { type Layout } from './lines.js';
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, theme: defaultTheme, }: {
items: readonly T[];

@@ -13,2 +14,3 @@ /** The index of the active item. */

loop?: boolean;
theme?: Theme;
}): string;

@@ -1,1 +0,5 @@

export declare function usePrefix(isLoading?: boolean): string;
import { type Theme } from './theme.js';
export declare function usePrefix({ isLoading, theme, }: {
isLoading?: boolean;
theme?: Theme;
}): string;
{
"name": "@inquirer/core",
"version": "6.0.0",
"version": "7.0.0",
"engines": {
"node": ">=14.18.0"
"node": ">=18"
},

@@ -60,5 +60,5 @@ "description": "Core Inquirer prompt API",

"dependencies": {
"@inquirer/type": "^1.1.6",
"@inquirer/type": "^1.2.0",
"@types/mute-stream": "^0.0.4",
"@types/node": "^20.10.7",
"@types/node": "^20.11.16",
"@types/wrap-ansi": "^3.0.0",

@@ -77,3 +77,3 @@ "ansi-escapes": "^4.3.2",

"devDependencies": {
"@inquirer/testing": "^2.1.10"
"@inquirer/testing": "^2.1.11"
},

@@ -100,3 +100,3 @@ "scripts": {

},
"gitHead": "4dee2b11d89a7c8a698c9eeda546ba8092b84f64"
"gitHead": "44016a40bc9e93455dfdb9fa6c25c27c1c109bd3"
}

@@ -31,3 +31,3 @@ # `@inquirer/core`

const [value, setValue] = useState('');
const prefix = usePrefix();
const prefix = usePrefix({});

@@ -145,2 +145,3 @@ useKeypress((key, rl) => {

loop: config.loop,
theme, config.theme,
});

@@ -152,2 +153,71 @@

### Theming
Theming utilities will allow you to expose customization of the prompt style. Inquirer also has a few standard theme values shared across all the official prompts.
To allow standard customization:
```ts
import { createPrompt, usePrefix, makeTheme, type Theme } from '@inquirer/core';
import type { PartialDeep } from '@inquirer/type';
type PromptConfig = {
theme?: PartialDeep<Theme>;
};
export default createPrompt<string, PromptConfig>((config, done) => {
const theme = makeTheme(config.theme);
const prefix = usePrefix({ isLoading, theme });
return `${prefix} ${theme.style.highlight('hello')}`;
});
```
To setup a custom theme:
```ts
import { createPrompt, makeTheme, type Theme } from '@inquirer/core';
import type { PartialDeep } from '@inquirer/type';
type PromptTheme = {};
const promptTheme: PromptTheme = {
icon: '!',
};
type PromptConfig = {
theme?: PartialDeep<Theme<PromptTheme>>;
};
export default createPrompt<string, PromptConfig>((config, done) => {
const theme = makeTheme(promptTheme, config.theme);
const prefix = usePrefix({ isLoading, theme });
return `${prefix} ${theme.icon}`;
});
```
The [default theme keys cover](https://github.com/SBoudrias/Inquirer.js/blob/theme/packages/core/src/lib/theme.mts):
```ts
type DefaultTheme = {
prefix: string;
spinner: {
interval: number;
frames: string[];
};
style: {
answer: (text: string) => string;
message: (text: string) => string;
error: (text: string) => string;
defaultAnswer: (text: string) => string;
help: (text: string) => string;
highlight: (text: string) => string;
key: (text: string) => string;
};
};
```
# License

@@ -154,0 +224,0 @@

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

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