jest-watch-typeahead 0.1.0-2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,10 +1,30 @@
1
1
  ## master
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Features
6
+
7
+ - Add support for plugin config ([#13](https://github.com/jest-community/jest-watch-typeahead/pull/13))
8
+
9
+ ### Fixes
10
+
11
+ - Make matching case insensitive ([#18](https://github.com/jest-community/jest-watch-typeahead/pull/18))
12
+ - fix: migrate to use jest-watcher ([#6](https://github.com/jest-community/jest-watch-typeahead/pull/6))
13
+
14
+ ### Chore & Maintenance
15
+
16
+ - Upgrade Prettier to 1.13.7 ([#17](https://github.com/jest-community/jest-watch-typeahead/pull/17))
17
+ - New directory structure ([#14](https://github.com/jest-community/jest-watch-typeahead/pull/14))
18
+ - Move ansi-escapes to dependencies _23f22d4_
19
+ - Setup Travis and add tests ([#12](https://github.com/jest-community/jest-watch-typeahead/pull/12))
20
+
21
+ ## 0.1.0
22
+
3
23
  ### Features
4
24
 
5
- * Add test name typeahead ([#1](https://github.com/jest-community/jest-watch-typeahead/pull/1))
6
- * Rename to jest-watch-typeahead
25
+ - Add test name typeahead ([#1](https://github.com/jest-community/jest-watch-typeahead/pull/1))
26
+ - Rename to jest-watch-typeahead
7
27
 
8
- ### 0.0.1
28
+ ## 0.0.1
9
29
 
10
30
  Initial Release
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Rogelio Guzman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -51,6 +51,22 @@ module.exports = {
51
51
  };
52
52
  ```
53
53
 
54
+ ### Configuring your key and prompt name
55
+
56
+ ```js
57
+ module.exports = {
58
+ watchPlugins: [
59
+ [
60
+ 'jest-watch-typeahead/filename',
61
+ {
62
+ key: 'k',
63
+ prompt: 'do something with my custom prompt',
64
+ },
65
+ ],
66
+ ],
67
+ };
68
+ ```
69
+
54
70
  ### Run Jest in watch mode
55
71
 
56
72
  ```bash
@@ -4,10 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
-
9
- var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
10
-
11
7
  var _chalk = require('chalk');
12
8
 
13
9
  var _chalk2 = _interopRequireDefault(_chalk);
@@ -16,11 +12,9 @@ var _stringLength = require('string-length');
16
12
 
17
13
  var _stringLength2 = _interopRequireDefault(_stringLength);
18
14
 
19
- var _utils = require('./lib/utils');
20
-
21
- var _Prompt = require('./shared/Prompt');
15
+ var _jestWatcher = require('jest-watcher');
22
16
 
23
- var _Prompt2 = _interopRequireDefault(_Prompt);
17
+ var _utils = require('./lib/utils');
24
18
 
25
19
  var _pattern_mode_helpers = require('./shared/pattern_mode_helpers');
26
20
 
@@ -28,120 +22,84 @@ var _scroll2 = require('./shared/scroll');
28
22
 
29
23
  var _scroll3 = _interopRequireDefault(_scroll2);
30
24
 
31
- var _pattern_prompt = require('./shared/pattern_prompt');
32
-
33
- var _pattern_prompt2 = _interopRequireDefault(_pattern_prompt);
34
-
35
25
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
26
 
37
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27
+ class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
38
28
 
39
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
29
+ constructor(pipe, prompt) {
30
+ super(pipe, prompt);
31
+ this._entityName = 'filenames';
32
+ this._searchSources = [];
33
+ }
40
34
 
41
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
35
+ _onChange(pattern, options) {
36
+ super._onChange(pattern, options);
37
+ this._printTypeahead(pattern, options);
38
+ }
42
39
 
43
- var FileNamePatternPrompt = function (_PatternPrompt) {
44
- _inherits(FileNamePatternPrompt, _PatternPrompt);
40
+ _printTypeahead(pattern, options) {
41
+ const matchedTests = this._getMatchedTests(pattern);
42
+ const total = matchedTests.length;
43
+ const pipe = this._pipe;
44
+ const prompt = this._prompt;
45
45
 
46
- function FileNamePatternPrompt(pipe, prompt) {
47
- _classCallCheck(this, FileNamePatternPrompt);
46
+ (0, _jestWatcher.printPatternCaret)(pattern, pipe);
48
47
 
49
- var _this = _possibleConstructorReturn(this, (FileNamePatternPrompt.__proto__ || Object.getPrototypeOf(FileNamePatternPrompt)).call(this, pipe, prompt));
48
+ if (pattern) {
49
+ (0, _pattern_mode_helpers.printPatternMatches)(total, 'file', pipe);
50
50
 
51
- _this._entityName = 'filenames';
52
- _this._searchSources = [];
53
- return _this;
54
- }
51
+ const prefix = ` ${_chalk2.default.dim('\u203A')} `;
52
+ const padding = (0, _stringLength2.default)(prefix) + 2;
53
+ const width = (0, _utils.getTerminalWidth)();
55
54
 
56
- _createClass(FileNamePatternPrompt, [{
57
- key: '_onChange',
58
- value: function _onChange(pattern, options) {
59
- _get(FileNamePatternPrompt.prototype.__proto__ || Object.getPrototypeOf(FileNamePatternPrompt.prototype), '_onChange', this).call(this, pattern, options);
60
- this._printTypeahead(pattern, options);
61
- }
62
- }, {
63
- key: '_printTypeahead',
64
- value: function _printTypeahead(pattern, options) {
65
- var matchedTests = this._getMatchedTests(pattern);
66
- var total = matchedTests.length;
67
- var pipe = this._pipe;
68
- var prompt = this._prompt;
55
+ var _scroll = (0, _scroll3.default)(total, options);
69
56
 
70
- (0, _pattern_mode_helpers.printPatternCaret)(pattern, pipe);
57
+ const start = _scroll.start,
58
+ end = _scroll.end,
59
+ index = _scroll.index;
71
60
 
72
- if (pattern) {
73
- (0, _pattern_mode_helpers.printPatternMatches)(total, 'file', pipe);
74
61
 
75
- var prefix = ` ${_chalk2.default.dim('\u203A')} `;
76
- var padding = (0, _stringLength2.default)(prefix) + 2;
77
- var width = (0, _utils.getTerminalWidth)();
62
+ prompt.setPromptLength(total);
78
63
 
79
- var _scroll = (0, _scroll3.default)(total, options),
80
- start = _scroll.start,
81
- end = _scroll.end,
82
- index = _scroll.index;
64
+ matchedTests.slice(start, end).map(({ path, context }) => {
65
+ const filePath = (0, _utils.trimAndFormatPath)(padding, context.config, path, width);
66
+ return (0, _utils.highlight)(path, filePath, pattern, context.config.rootDir);
67
+ }).map((item, i) => (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt)).forEach(item => (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe));
83
68
 
84
- prompt.setTypeaheadLength(total);
85
-
86
- matchedTests.slice(start, end).map(function (_ref) {
87
- var path = _ref.path,
88
- context = _ref.context;
89
-
90
- var filePath = (0, _utils.trimAndFormatPath)(padding, context.config, path, width);
91
- return (0, _utils.highlight)(path, filePath, pattern, context.config.rootDir);
92
- }).map(function (item, i) {
93
- return (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt);
94
- }).forEach(function (item) {
95
- return (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe);
96
- });
97
-
98
- if (total > end) {
99
- (0, _pattern_mode_helpers.printMore)('file', pipe, total - end);
100
- }
101
- } else {
102
- (0, _pattern_mode_helpers.printStartTyping)('filename', pipe);
69
+ if (total > end) {
70
+ (0, _pattern_mode_helpers.printMore)('file', pipe, total - end);
103
71
  }
104
-
105
- (0, _pattern_mode_helpers.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
72
+ } else {
73
+ (0, _pattern_mode_helpers.printStartTyping)('filename', pipe);
106
74
  }
107
- }, {
108
- key: '_getMatchedTests',
109
- value: function _getMatchedTests(pattern) {
110
- var regex = void 0;
111
-
112
- try {
113
- regex = new RegExp(pattern, 'i');
114
- } catch (e) {
115
- regex = null;
116
- }
117
75
 
118
- var tests = [];
119
- if (regex) {
120
- this._searchSources.forEach(function (_ref2) {
121
- var testPaths = _ref2.testPaths,
122
- config = _ref2.config;
123
-
124
- tests = tests.concat(testPaths.filter(function (testPath) {
125
- return testPath.match(pattern);
126
- }).map(function (path) {
127
- return {
128
- path,
129
- context: { config }
130
- };
131
- }));
132
- });
133
- }
76
+ (0, _jestWatcher.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
77
+ }
78
+
79
+ _getMatchedTests(pattern) {
80
+ let regex;
134
81
 
135
- return tests;
82
+ try {
83
+ regex = new RegExp(pattern, 'i');
84
+ } catch (e) {
85
+ regex = null;
136
86
  }
137
- }, {
138
- key: 'updateSearchSources',
139
- value: function updateSearchSources(searchSources) {
140
- this._searchSources = searchSources;
87
+
88
+ let tests = [];
89
+ if (regex) {
90
+ this._searchSources.forEach(({ testPaths, config }) => {
91
+ tests = tests.concat(testPaths.filter(testPath => testPath.match(pattern)).map(path => ({
92
+ path,
93
+ context: { config }
94
+ })));
95
+ });
141
96
  }
142
- }]);
143
97
 
144
- return FileNamePatternPrompt;
145
- }(_pattern_prompt2.default);
98
+ return tests;
99
+ }
146
100
 
101
+ updateSearchSources(searchSources) {
102
+ this._searchSources = searchSources;
103
+ }
104
+ }
147
105
  exports.default = FileNamePatternPrompt;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var _jestWatcher = require("jest-watcher");
4
+
5
+ var _prompt = _interopRequireDefault(require("./prompt"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ class FileNamePlugin {
10
+ constructor({
11
+ stdin,
12
+ stdout,
13
+ config = {}
14
+ }) {
15
+ this._stdin = stdin;
16
+ this._stdout = stdout;
17
+ this._prompt = new _jestWatcher.Prompt();
18
+ this._projects = [];
19
+ this._usageInfo = {
20
+ key: config.key || 'p',
21
+ prompt: config.prompt || 'filter by a filename regex pattern'
22
+ };
23
+ }
24
+
25
+ apply(jestHooks) {
26
+ jestHooks.onFileChange(({
27
+ projects
28
+ }) => {
29
+ this._projects = projects;
30
+ });
31
+ }
32
+
33
+ onKey(key) {
34
+ this._prompt.put(key);
35
+ }
36
+
37
+ run(globalConfig, updateConfigAndRun) {
38
+ const p = new _prompt.default(this._stdout, this._prompt);
39
+ p.updateSearchSources(this._projects);
40
+ return new Promise((res, rej) => {
41
+ p.run(value => {
42
+ updateConfigAndRun({
43
+ mode: 'watch',
44
+ testPathPattern: value
45
+ });
46
+ res();
47
+ }, rej);
48
+ });
49
+ }
50
+
51
+ getUsageInfo() {
52
+ return this._usageInfo;
53
+ }
54
+
55
+ }
56
+
57
+ module.exports = FileNamePlugin;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+
10
+ var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
11
+
12
+ var _stringLength = _interopRequireDefault(require("string-length"));
13
+
14
+ var _jestWatcher = require("jest-watcher");
15
+
16
+ var _utils = require("../lib/utils");
17
+
18
+ var _pattern_mode_helpers = require("../lib/pattern_mode_helpers");
19
+
20
+ var _scroll2 = _interopRequireDefault(require("../lib/scroll"));
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
25
+ constructor(pipe, prompt) {
26
+ super(pipe, prompt);
27
+ this._entityName = 'filenames';
28
+ this._searchSources = [];
29
+ }
30
+
31
+ _onChange(pattern, options) {
32
+ super._onChange(pattern, options);
33
+
34
+ this._printTypeahead(pattern, options);
35
+ }
36
+
37
+ _printTypeahead(pattern, options) {
38
+ const matchedTests = this._getMatchedTests(pattern);
39
+
40
+ const total = matchedTests.length;
41
+ const pipe = this._pipe;
42
+ const prompt = this._prompt;
43
+ (0, _jestWatcher.printPatternCaret)(pattern, pipe);
44
+ pipe.write(_ansiEscapes.default.cursorLeft);
45
+
46
+ if (pattern) {
47
+ (0, _pattern_mode_helpers.printPatternMatches)(total, 'file', pipe);
48
+ const prefix = ` ${_chalk.default.dim('\u203A')} `;
49
+ const padding = (0, _stringLength.default)(prefix) + 2;
50
+ const width = (0, _utils.getTerminalWidth)(pipe);
51
+
52
+ const _scroll = (0, _scroll2.default)(total, options),
53
+ start = _scroll.start,
54
+ end = _scroll.end,
55
+ index = _scroll.index;
56
+
57
+ prompt.setPromptLength(total);
58
+ matchedTests.slice(start, end).map(({
59
+ path,
60
+ context
61
+ }) => {
62
+ const filePath = (0, _utils.trimAndFormatPath)(padding, context.config, path, width);
63
+ return (0, _utils.highlight)(path, filePath, pattern, context.config.rootDir);
64
+ }).map((item, i) => (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt)).forEach(item => (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe));
65
+
66
+ if (total > end) {
67
+ (0, _pattern_mode_helpers.printMore)('file', pipe, total - end);
68
+ }
69
+ } else {
70
+ (0, _pattern_mode_helpers.printStartTyping)('filename', pipe);
71
+ }
72
+
73
+ (0, _jestWatcher.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
74
+ }
75
+
76
+ _getMatchedTests(pattern) {
77
+ let regex;
78
+
79
+ try {
80
+ regex = new RegExp(pattern, 'i');
81
+ } catch (e) {
82
+ return [];
83
+ }
84
+
85
+ return this._searchSources.reduce((tests, {
86
+ testPaths,
87
+ config
88
+ }) => {
89
+ return tests.concat(testPaths.filter(testPath => regex.test(testPath)).map(path => ({
90
+ path,
91
+ context: {
92
+ config
93
+ }
94
+ })));
95
+ }, []);
96
+ }
97
+
98
+ updateSearchSources(searchSources) {
99
+ this._searchSources = searchSources;
100
+ }
101
+
102
+ }
103
+
104
+ exports.default = FileNamePatternPrompt;
@@ -1,10 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
-
5
- var _Prompt = require('./shared/Prompt');
6
-
7
- var _Prompt2 = _interopRequireDefault(_Prompt);
3
+ var _jestWatcher = require('jest-watcher');
8
4
 
9
5
  var _file_name_pattern_prompt = require('./file_name_pattern_prompt');
10
6
 
@@ -12,63 +8,46 @@ var _file_name_pattern_prompt2 = _interopRequireDefault(_file_name_pattern_promp
12
8
 
13
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
10
 
15
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
-
17
- var FileNamePlugin = function () {
18
- function FileNamePlugin(_ref) {
19
- var stdin = _ref.stdin,
20
- stdout = _ref.stdout;
21
-
22
- _classCallCheck(this, FileNamePlugin);
11
+ class FileNamePlugin {
23
12
 
13
+ constructor({
14
+ stdin,
15
+ stdout
16
+ }) {
24
17
  this._stdin = stdin;
25
18
  this._stdout = stdout;
26
- this._prompt = new _Prompt2.default();
19
+ this._prompt = new _jestWatcher.Prompt();
27
20
  this._projects = [];
28
21
  }
29
22
 
30
- _createClass(FileNamePlugin, [{
31
- key: 'apply',
32
- value: function apply(jestHooks) {
33
- var _this = this;
34
-
35
- jestHooks.onFileChange(function (_ref2) {
36
- var projects = _ref2.projects;
37
-
38
- _this._projects = projects;
39
- });
40
- }
41
- }, {
42
- key: 'onKey',
43
- value: function onKey(key) {
44
- this._prompt.put(key);
45
- }
46
- }, {
47
- key: 'run',
48
- value: function run(globalConfig, updateConfigAndRun) {
49
- var p = new _file_name_pattern_prompt2.default(this._stdout, this._prompt);
50
- p.updateSearchSources(this._projects);
51
- return new Promise(function (res, rej) {
52
- p.run(function (value) {
53
- updateConfigAndRun({ mode: 'watch', testPathPattern: value });
54
- res();
55
- }, rej);
56
- });
57
- }
23
+ apply(jestHooks) {
24
+ jestHooks.onFileChange(({ projects }) => {
25
+ this._projects = projects;
26
+ });
27
+ }
58
28
 
59
- // eslint-disable-next-line class-methods-use-this
29
+ onKey(key) {
30
+ this._prompt.put(key);
31
+ }
60
32
 
61
- }, {
62
- key: 'getUsageInfo',
63
- value: function getUsageInfo() {
64
- return {
65
- key: 'p',
66
- prompt: 'filter by a filename regex pattern'
67
- };
68
- }
69
- }]);
33
+ run(globalConfig, updateConfigAndRun) {
34
+ const p = new _file_name_pattern_prompt2.default(this._stdout, this._prompt);
35
+ p.updateSearchSources(this._projects);
36
+ return new Promise((res, rej) => {
37
+ p.run(value => {
38
+ updateConfigAndRun({ mode: 'watch', testPathPattern: value });
39
+ res();
40
+ }, rej);
41
+ });
42
+ }
70
43
 
71
- return FileNamePlugin;
72
- }();
44
+ // eslint-disable-next-line class-methods-use-this
45
+ getUsageInfo() {
46
+ return {
47
+ key: 'p',
48
+ prompt: 'filter by a filename regex pattern'
49
+ };
50
+ }
51
+ }
73
52
 
74
53
  module.exports = FileNamePlugin;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printPatternMatches = void 0;
7
+
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+
10
+ var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
11
+
12
+ var _jestWatcher = require("jest-watcher");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ const pluralize = (count, text) => count === 1 ? text : `${text}s`;
17
+
18
+ const printPatternMatches = (count, entity, pipe, extraText = '') => {
19
+ const pluralized = pluralize(count, entity);
20
+ const result = count ? `\n\n Pattern matches ${count} ${pluralized}` : `\n\n Pattern matches no ${pluralized}`;
21
+ pipe.write(result + extraText);
22
+ };
23
+
24
+ exports.printPatternMatches = printPatternMatches;
25
+
26
+ const printStartTyping = (entity, pipe) => {
27
+ pipe.write(`\n\n ${_chalk.default.italic.yellow(`Start typing to filter by a ${entity} regex pattern.`)}`);
28
+ };
29
+
30
+ exports.printStartTyping = printStartTyping;
31
+
32
+ const printMore = (entity, pipe, more) => {
33
+ pipe.write(`\n ${_chalk.default.dim(`...and ${more} more ${pluralize(more, entity)}`)}`);
34
+ };
35
+
36
+ exports.printMore = printMore;
37
+
38
+ const printTypeaheadItem = (item, pipe) => pipe.write(`\n ${_chalk.default.dim('\u203A')} ${item}`);
39
+
40
+ exports.printTypeaheadItem = printTypeaheadItem;
41
+
42
+ const 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
+
51
+ exports.formatTypeaheadSelection = formatTypeaheadSelection;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ const scroll = (size, {
9
+ offset,
10
+ max
11
+ }) => {
12
+ let start = 0;
13
+ let index = Math.min(offset, size);
14
+ const halfScreen = max / 2;
15
+
16
+ if (index <= halfScreen) {
17
+ start = 0;
18
+ } else {
19
+ if (size >= max) {
20
+ start = Math.min(index - halfScreen - 1, size - max);
21
+ }
22
+
23
+ index = Math.min(index - start, size);
24
+ }
25
+
26
+ return {
27
+ end: Math.min(size, start + max),
28
+ index,
29
+ start
30
+ };
31
+ };
32
+
33
+ var _default = scroll;
34
+ exports.default = _default;