UNPKG

2.46 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.default = void 0;
7
8function _ansiEscapes() {
9 const data = _interopRequireDefault(require('ansi-escapes'));
10
11 _ansiEscapes = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _chalk() {
19 const data = _interopRequireDefault(require('chalk'));
20
21 _chalk = function () {
22 return data;
23 };
24
25 return data;
26}
27
28function _jestUtil() {
29 const data = require('jest-util');
30
31 _jestUtil = function () {
32 return data;
33 };
34
35 return data;
36}
37
38function _interopRequireDefault(obj) {
39 return obj && obj.__esModule ? obj : {default: obj};
40}
41
42function _defineProperty(obj, key, value) {
43 if (key in obj) {
44 Object.defineProperty(obj, key, {
45 value: value,
46 enumerable: true,
47 configurable: true,
48 writable: true
49 });
50 } else {
51 obj[key] = value;
52 }
53 return obj;
54}
55
56const {CLEAR} = _jestUtil().specialChars;
57
58const usage = entity =>
59 `\n${_chalk().default.bold('Pattern Mode Usage')}\n` +
60 ` ${_chalk().default.dim('\u203A Press')} Esc ${_chalk().default.dim(
61 'to exit pattern mode.'
62 )}\n` +
63 ` ${_chalk().default.dim('\u203A Press')} Enter ` +
64 `${_chalk().default.dim(`to filter by a ${entity} regex pattern.`)}\n` +
65 `\n`;
66
67const usageRows = usage('').split('\n').length;
68
69class PatternPrompt {
70 constructor(pipe, prompt) {
71 _defineProperty(this, '_pipe', void 0);
72
73 _defineProperty(this, '_prompt', void 0);
74
75 _defineProperty(this, '_entityName', void 0);
76
77 _defineProperty(this, '_currentUsageRows', void 0);
78
79 // TODO: Should come in the constructor
80 this._entityName = '';
81 this._pipe = pipe;
82 this._prompt = prompt;
83 this._currentUsageRows = usageRows;
84 }
85
86 run(onSuccess, onCancel, options) {
87 this._pipe.write(_ansiEscapes().default.cursorHide);
88
89 this._pipe.write(CLEAR);
90
91 if (options && options.header) {
92 this._pipe.write(options.header + '\n');
93
94 this._currentUsageRows = usageRows + options.header.split('\n').length;
95 } else {
96 this._currentUsageRows = usageRows;
97 }
98
99 this._pipe.write(usage(this._entityName));
100
101 this._pipe.write(_ansiEscapes().default.cursorShow);
102
103 this._prompt.enter(this._onChange.bind(this), onSuccess, onCancel);
104 }
105
106 _onChange(_pattern, _options) {
107 this._pipe.write(_ansiEscapes().default.eraseLine);
108
109 this._pipe.write(_ansiEscapes().default.cursorLeft);
110 }
111}
112
113exports.default = PatternPrompt;