UNPKG

1.7 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printPatternMatches = void 0;
7
8var _chalk = _interopRequireDefault(require("chalk"));
9
10var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
11
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14const pluralize = (count, text) => count === 1 ? text : `${text}s`;
15
16const printPatternMatches = (count, entity, pipe, extraText = '') => {
17 const pluralized = pluralize(count, entity);
18 const result = count ? `\n\n Pattern matches ${count} ${pluralized}` : `\n\n Pattern matches no ${pluralized}`;
19 pipe.write(result + extraText);
20};
21
22exports.printPatternMatches = printPatternMatches;
23
24const printStartTyping = (entity, pipe) => {
25 pipe.write(`\n\n ${_chalk.default.italic.yellow(`Start typing to filter by a ${entity} regex pattern.`)}`);
26};
27
28exports.printStartTyping = printStartTyping;
29
30const printMore = (entity, pipe, more) => {
31 pipe.write(`\n ${_chalk.default.dim(`...and ${more} more ${pluralize(more, entity)}`)}`);
32};
33
34exports.printMore = printMore;
35
36const printTypeaheadItem = (item, pipe) => {
37 pipe.write(`\n ${_chalk.default.dim('\u203A')} ${item}`);
38};
39
40exports.printTypeaheadItem = printTypeaheadItem;
41
42const formatTypeaheadSelection = (item, index, activeIndex, prompt) => {
43 if (index === activeIndex) {
44 prompt.setPromptSelection((0, _stripAnsi.default)(item));
45 return _chalk.default.black.bgYellow((0, _stripAnsi.default)(item));
46 }
47
48 return item;
49};
50
51exports.formatTypeaheadSelection = formatTypeaheadSelection;
\No newline at end of file