inquirer-plugins 1.0.0-alpha.7 → 1.0.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.
Files changed (120) hide show
  1. package/README.md +5 -34
  2. package/dist/lib/_internal/plugins/table/table.d.ts +2 -0
  3. package/dist/lib/_internal/plugins/table/table.d.ts.map +1 -0
  4. package/dist/lib/_internal/plugins/table/table.js +1 -0
  5. package/dist/lib/_internal/plugins/table/types/columns.d.ts +21 -0
  6. package/dist/lib/_internal/plugins/table/types/columns.d.ts.map +1 -0
  7. package/dist/lib/_internal/plugins/table/types/columns.js +2 -0
  8. package/dist/lib/_internal/plugins/table/types/common.d.ts +25 -0
  9. package/dist/lib/_internal/plugins/table/types/common.d.ts.map +1 -0
  10. package/dist/lib/_internal/plugins/table/types/common.js +5 -0
  11. package/dist/lib/_internal/plugins/table/types/rows.d.ts +2 -0
  12. package/dist/lib/_internal/plugins/table/types/rows.d.ts.map +1 -0
  13. package/dist/lib/_internal/plugins/table/types/table.d.ts +27 -0
  14. package/dist/lib/_internal/plugins/table/types/table.d.ts.map +1 -0
  15. package/dist/lib/_internal/plugins/table/types.d.ts +27 -0
  16. package/dist/lib/_internal/plugins/table/types.d.ts.map +1 -0
  17. package/dist/lib/_internal/plugins/table/types.js +24 -0
  18. package/dist/lib/_internal/plugins/table/utils.d.ts +25 -0
  19. package/dist/lib/_internal/plugins/table/utils.d.ts.map +1 -0
  20. package/dist/lib/_internal/plugins/table/utils.js +179 -0
  21. package/dist/lib/_internal/plugins/table.d.ts +11 -0
  22. package/dist/lib/_internal/plugins/table.d.ts.map +1 -0
  23. package/dist/lib/_internal/plugins/table.js +173 -0
  24. package/dist/lib/_internal/types/chalk.d.ts +7 -0
  25. package/dist/lib/_internal/types/chalk.d.ts.map +1 -0
  26. package/dist/lib/_internal/types/chalk.js +1 -0
  27. package/dist/lib/_internal/types/inquirer.d.ts +6 -0
  28. package/dist/lib/_internal/types/inquirer.d.ts.map +1 -0
  29. package/dist/lib/_internal/types/inquirer.js +5 -0
  30. package/dist/lib/_internal/types/parse-types.d.ts +7 -0
  31. package/dist/lib/_internal/types/parse-types.d.ts.map +1 -0
  32. package/{src/_internal/types/parse-types.ts → dist/lib/_internal/types/parse-types.js} +1 -3
  33. package/dist/lib/_internal/types/table.d.ts +15 -0
  34. package/dist/lib/_internal/types/table.d.ts.map +1 -0
  35. package/dist/lib/_internal/types/table.js +1 -0
  36. package/dist/lib/_internal/utils/chalk.d.ts +12 -0
  37. package/dist/lib/_internal/utils/chalk.d.ts.map +1 -0
  38. package/dist/lib/_internal/utils/chalk.js +29 -0
  39. package/dist/lib/_internal/utils/columns.d.ts +7 -0
  40. package/dist/lib/_internal/utils/columns.d.ts.map +1 -0
  41. package/dist/lib/_internal/utils/columns.js +28 -0
  42. package/dist/lib/_internal/utils/common.d.ts +4 -0
  43. package/dist/lib/_internal/utils/common.d.ts.map +1 -0
  44. package/dist/lib/_internal/utils/common.js +3 -0
  45. package/dist/lib/_internal/utils/keypress.d.ts +12 -0
  46. package/dist/lib/_internal/utils/keypress.d.ts.map +1 -0
  47. package/dist/lib/_internal/utils/keypress.js +28 -0
  48. package/dist/lib/_internal/utils/parse-types.d.ts +4 -0
  49. package/dist/lib/_internal/utils/parse-types.d.ts.map +1 -0
  50. package/{src/_internal/utils/parse-types.ts → dist/lib/_internal/utils/parse-types.js} +3 -7
  51. package/dist/lib/_internal/utils/table/arrow-key.d.ts +14 -0
  52. package/dist/lib/_internal/utils/table/arrow-key.d.ts.map +1 -0
  53. package/dist/lib/_internal/utils/table/arrow-key.js +24 -0
  54. package/dist/lib/_internal/utils/table/cell.d.ts +3 -0
  55. package/dist/lib/_internal/utils/table/cell.d.ts.map +1 -0
  56. package/dist/lib/_internal/utils/table/cell.js +6 -0
  57. package/dist/lib/_internal/utils/table/columns.d.ts +3 -0
  58. package/dist/lib/_internal/utils/table/columns.d.ts.map +1 -0
  59. package/dist/lib/_internal/utils/table/columns.js +29 -0
  60. package/dist/lib/_internal/utils/table/pagenate.d.ts +4 -0
  61. package/dist/lib/_internal/utils/table/pagenate.d.ts.map +1 -0
  62. package/dist/lib/_internal/utils/table/pagenate.js +20 -0
  63. package/dist/lib/_internal/utils/table/rows.d.ts +3 -0
  64. package/dist/lib/_internal/utils/table/rows.d.ts.map +1 -0
  65. package/dist/lib/_internal/utils/table/rows.js +4 -0
  66. package/dist/lib/modules/table.d.ts +2 -0
  67. package/dist/lib/modules/table.d.ts.map +1 -0
  68. package/dist/lib/modules/table.js +1 -0
  69. package/dist/lib/modules/types/chalk.d.ts +2 -0
  70. package/dist/lib/modules/types/chalk.d.ts.map +1 -0
  71. package/dist/lib/modules/types/chalk.js +1 -0
  72. package/dist/{modules → lib/modules}/types/inquirer.d.ts +1 -0
  73. package/dist/lib/modules/types/inquirer.d.ts.map +1 -0
  74. package/dist/{modules → lib/modules}/types/parse-types.d.ts +1 -0
  75. package/dist/lib/modules/types/parse-types.d.ts.map +1 -0
  76. package/dist/lib/modules/types/table.d.ts +2 -0
  77. package/dist/lib/modules/types/table.d.ts.map +1 -0
  78. package/dist/lib/modules/types/table.js +1 -0
  79. package/package.json +27 -103
  80. package/LICENSE +0 -21
  81. package/dist/_internal/plugins/table/table.d.ts +0 -15
  82. package/dist/_internal/plugins/table/table.js +0 -77
  83. package/dist/_internal/plugins/table/types.d.ts +0 -47
  84. package/dist/_internal/plugins/table/types.js +0 -23
  85. package/dist/_internal/plugins/table/utils.d.ts +0 -3
  86. package/dist/_internal/plugins/table/utils.js +0 -22
  87. package/dist/_internal/plugins/table.d.ts +0 -49
  88. package/dist/_internal/plugins/table.js +0 -263
  89. package/dist/_internal/plugins/test.js +0 -50
  90. package/dist/_internal/types/inquirer.d.ts +0 -1
  91. package/dist/_internal/types/parse-types.d.ts +0 -6
  92. package/dist/_internal/types/parse-types.js +0 -5
  93. package/dist/_internal/utils/chalk.d.ts +0 -9
  94. package/dist/_internal/utils/chalk.js +0 -10
  95. package/dist/_internal/utils/keypress.d.ts +0 -4
  96. package/dist/_internal/utils/keypress.js +0 -20
  97. package/dist/_internal/utils/parse-types.d.ts +0 -3
  98. package/dist/_internal/utils/parse-types.js +0 -23
  99. package/dist/modules/table.d.ts +0 -2
  100. package/dist/modules/table.js +0 -2
  101. package/src/_internal/plugins/table/README.md +0 -117
  102. package/src/_internal/plugins/table/table.ts +0 -93
  103. package/src/_internal/plugins/table/types.ts +0 -74
  104. package/src/_internal/plugins/table/utils.ts +0 -25
  105. package/src/_internal/plugins/table.ts +0 -305
  106. package/src/_internal/plugins/test.ts +0 -76
  107. package/src/_internal/types/inquirer.ts +0 -1
  108. package/src/_internal/utils/chalk.ts +0 -13
  109. package/src/_internal/utils/keypress.ts +0 -23
  110. package/src/modules/table.ts +0 -2
  111. package/src/modules/types/inquirer.ts +0 -1
  112. package/src/modules/types/parse-types.ts +0 -1
  113. package/table/package.json +0 -6
  114. package/tsconfig.json +0 -27
  115. package/types/inquirer/package.json +0 -6
  116. package/types/parse-types/package.json +0 -6
  117. /package/dist/{_internal/plugins/test.d.ts → lib/_internal/plugins/table/types/rows.js} +0 -0
  118. /package/dist/{_internal/types/inquirer.js → lib/_internal/plugins/table/types/table.js} +0 -0
  119. /package/dist/{modules → lib/modules}/types/inquirer.js +0 -0
  120. /package/dist/{modules → lib/modules}/types/parse-types.js +0 -0
@@ -1,77 +0,0 @@
1
- import { PARSE_TYPES } from '../../types/parse-types.js';
2
- import { trim, error } from '../../utils/chalk.js';
3
- import { parse } from '../../utils/parse-types.js';
4
- export class TableClass {
5
- columns = [];
6
- rows = [];
7
- constructor(columns, rows) {
8
- this.columns = columns;
9
- this.rows = rows.map(columns => columns.map(value => `${value}`));
10
- }
11
- get header() {
12
- return this.columns.map(({ name }) => `${name}`);
13
- }
14
- getColumnType(columnIndex) {
15
- if (!(columnIndex in this.columns)) {
16
- return PARSE_TYPES.input;
17
- }
18
- return this.columns[columnIndex].type;
19
- }
20
- getParser(columnIndex) {
21
- return this.columns[columnIndex].parser || ((txt, _inputs, _answers) => txt);
22
- }
23
- getValidator(columnIndex) {
24
- return (this.columns[columnIndex].validate ||
25
- ((_txt, _inputs, _answers) => ({ isValid: true, message: '' })));
26
- }
27
- updateRow(rowIndex, columnIndex, value, answers) {
28
- if (!(rowIndex in this.rows)) {
29
- return error(`row index (${rowIndex}) not found`);
30
- }
31
- const columns = this.rows[rowIndex];
32
- if (!(columnIndex in columns)) {
33
- return error(`column index (${columnIndex}) not found`);
34
- }
35
- const validateResult = this.getValidator(columnIndex)(value, this.getRaw(), answers);
36
- if (!validateResult.isValid) {
37
- return validateResult.message;
38
- }
39
- const parser = this.getParser(columnIndex);
40
- const parsed = parser(value, this.getRaw(), answers);
41
- columns[columnIndex] = `${parsed}`;
42
- return '';
43
- }
44
- getValue(rowIndex, columnIndex) {
45
- if (!(rowIndex in this.rows)) {
46
- return '';
47
- }
48
- const columns = this.rows[rowIndex];
49
- if (!(columnIndex in columns)) {
50
- return '';
51
- }
52
- return columns[columnIndex];
53
- }
54
- getRaw() {
55
- const result = [];
56
- for (let i = 0; i < this.rows.length; i++) {
57
- result.push({});
58
- for (let ii = 0; ii < (this.rows[i] || []).length; ii++) {
59
- const { value: key } = this.columns[ii];
60
- result[i][key] = trim(this.rows[i][ii]);
61
- }
62
- }
63
- return result;
64
- }
65
- getResult(answers) {
66
- const result = [];
67
- for (let i = 0; i < this.rows.length; i++) {
68
- result.push({});
69
- for (let ii = 0; ii < (this.rows[i] || []).length; ii++) {
70
- const { value: key, type, parser } = this.columns[ii];
71
- const value = trim(this.rows[i][ii]);
72
- result[i][key] = parser ? parser(value, this.getRaw(), answers) : parse(value, type);
73
- }
74
- }
75
- return result;
76
- }
77
- }
@@ -1,47 +0,0 @@
1
- import { ChalkInstance } from 'chalk';
2
- import { Answers } from 'inquirer';
3
- import { ParseType } from '../../types/parse-types.js';
4
- export declare const DEFAULT_PAGE_SIZE = 5;
5
- export declare const INDEX_ERRORS: Readonly<{
6
- readonly excess: "excess";
7
- readonly disabled: "disabled";
8
- }>;
9
- export interface DefaultOptions extends Required<Omit<TableQuestion, 'type' | 'name' | 'colors'>> {
10
- colors: Colors;
11
- }
12
- export declare const DEFAULT_OPTIONS: DefaultOptions;
13
- export interface RequiredOptions extends Required<Omit<TableQuestion, 'colors'>> {
14
- colors: Colors;
15
- }
16
- export interface Colors {
17
- selected: ChalkInstance;
18
- editable: ChalkInstance;
19
- editing: ChalkInstance;
20
- }
21
- export interface ValidateResult {
22
- isValid: boolean;
23
- message: string;
24
- }
25
- export interface TableQuestion {
26
- type: string;
27
- name: string;
28
- message?: string | ChalkInstance;
29
- description?: string | ChalkInstance;
30
- escapeMessage?: string | ChalkInstance;
31
- confirmMessage?: string | ChalkInstance;
32
- disableColumnIndexes?: number[];
33
- colors?: Partial<Colors>;
34
- columns: Column[];
35
- rows: Cell[][];
36
- validate?: (...args: any[]) => ValidateResult;
37
- pageSize?: number;
38
- }
39
- export interface Column {
40
- name: string | ChalkInstance;
41
- value: string;
42
- type: ParseType;
43
- validate?: (input: string, raws: RawInputs, answers: Answers) => ValidateResult;
44
- parser?: (input: any, raws: RawInputs, answers: Answers) => any;
45
- }
46
- export type Cell = number | string | boolean;
47
- export type RawInputs = Record<string, string>[];
@@ -1,23 +0,0 @@
1
- import chalk from 'chalk';
2
- import { hop, success, warn } from '../../utils/chalk.js';
3
- export const DEFAULT_PAGE_SIZE = 5;
4
- export const INDEX_ERRORS = Object.freeze({
5
- excess: 'excess',
6
- disabled: 'disabled',
7
- });
8
- export const DEFAULT_OPTIONS = {
9
- message: '',
10
- description: '',
11
- escapeMessage: chalk.red('Press ESC again to exit!'),
12
- confirmMessage: chalk.red('Press ENTER again to confirm!'),
13
- disableColumnIndexes: [],
14
- colors: {
15
- selected: warn,
16
- editable: success,
17
- editing: hop,
18
- },
19
- columns: [],
20
- rows: [],
21
- pageSize: DEFAULT_PAGE_SIZE,
22
- validate: () => ({ isValid: true, message: '' }),
23
- };
@@ -1,3 +0,0 @@
1
- export declare const isNoChoiceOfIndex: (maxIndex: number, disableIndexes: number[]) => boolean;
2
- export declare const gateValidateColumnIndexError: (index: number, maxIndex: number, disableIndexes: number[]) => false | "disabled" | "excess";
3
- export declare const getNextIndex: (index: number, maxIndex: number, num: number) => number;
@@ -1,22 +0,0 @@
1
- import { INDEX_ERRORS } from '../../plugins/table/types.js';
2
- export const isNoChoiceOfIndex = (maxIndex, disableIndexes) => {
3
- return disableIndexes.length > maxIndex && [...Array(maxIndex).keys()].every(index => disableIndexes.includes(index));
4
- };
5
- export const gateValidateColumnIndexError = (index, maxIndex, disableIndexes) => {
6
- if (index > maxIndex || index < 0) {
7
- return INDEX_ERRORS.excess;
8
- }
9
- if (disableIndexes.includes(index)) {
10
- return INDEX_ERRORS.disabled;
11
- }
12
- return false;
13
- };
14
- export const getNextIndex = (index, maxIndex, num) => {
15
- if (index > maxIndex) {
16
- return 0;
17
- }
18
- if (index < 0) {
19
- return maxIndex;
20
- }
21
- return index > maxIndex ? 0 : index + num;
22
- };
@@ -1,49 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { Interface as ReadLineInterface, Key } from 'readline';
3
- import { Question, Answers } from 'inquirer';
4
- import Base from 'inquirer/lib/prompts/base.js';
5
- import { Done } from '../types/inquirer.js';
6
- import { TableClass } from './table/table.js';
7
- import { RequiredOptions, TableQuestion } from './table/types.js';
8
- export declare class TablePlugin extends Base {
9
- table: TableClass;
10
- options: RequiredOptions;
11
- done: Done;
12
- pointerIndexes: {
13
- row: number;
14
- column: number;
15
- };
16
- isNextCloses: {
17
- escape: boolean;
18
- };
19
- editing: boolean;
20
- temporaryBackup: string | null;
21
- purTyping: string;
22
- answers: Answers;
23
- constructor(question: Question<TableQuestion>, readLine: ReadLineInterface, answers: Answers);
24
- getCurrentValues(): Record<string, import("./table/types.js").Cell>[];
25
- isEditable(index: number): boolean;
26
- _run(callback: Done): this;
27
- get maxPageIndex(): number;
28
- get maxRowIndex(): number;
29
- get maxColumnIndex(): number;
30
- onDownKey(): void;
31
- onUpKey(): void;
32
- updateColumnIndex(num: number): void;
33
- onLeftKey(): void;
34
- onRightKey(): void;
35
- clear(): void;
36
- onEnd(state: any): void;
37
- validate(): import("./table/types.js").ValidateResult;
38
- onError(_state: any): void;
39
- updateChoice(value: string): string;
40
- get currentValue(): string;
41
- onEditPress(key: Key): void;
42
- getShowRowIndex(): {
43
- rowIndexFrom: number;
44
- rowIndexTo: number;
45
- };
46
- isSelected(rowIndex: number, columnIndex: number): boolean;
47
- getColor(_value: string, isSelected: boolean, isEditable: boolean): string;
48
- render(isDisconnect?: boolean, message?: string): void;
49
- }
@@ -1,263 +0,0 @@
1
- import cliCursor from 'cli-cursor';
2
- import Table from 'cli-table3';
3
- import Base from 'inquirer/lib/prompts/base.js';
4
- import observe from 'inquirer/lib/utils/events.js';
5
- import { map } from 'rxjs/operators';
6
- import { dim, error } from '../utils/chalk.js';
7
- import { getKeypressValue, getBackspaceText } from '../utils/keypress.js';
8
- import { TableClass } from './table/table.js';
9
- import { DEFAULT_OPTIONS } from './table/types.js';
10
- import { isNoChoiceOfIndex, gateValidateColumnIndexError, getNextIndex } from './table/utils.js';
11
- export class TablePlugin extends Base {
12
- table = new TableClass([], []);
13
- options;
14
- done;
15
- pointerIndexes = {
16
- row: 0,
17
- column: 0,
18
- };
19
- isNextCloses = {
20
- escape: false,
21
- };
22
- editing = false;
23
- temporaryBackup = null;
24
- purTyping = '';
25
- answers = [];
26
- constructor(question, readLine, answers) {
27
- super({ ...question, validate: () => false }, readLine, answers);
28
- this.options = {
29
- ...DEFAULT_OPTIONS,
30
- ...this.opt,
31
- validate: question.validate || DEFAULT_OPTIONS.validate,
32
- };
33
- this.answers = answers;
34
- this.table = new TableClass(this.options.columns, this.options.rows);
35
- if (isNoChoiceOfIndex(this.maxColumnIndex, this.options.disableColumnIndexes)) {
36
- throw new Error('disableColumnIndexes contains all of index.');
37
- }
38
- this.pointerIndexes.row = 0;
39
- this.updateColumnIndex(1);
40
- }
41
- getCurrentValues() {
42
- return this.table.getResult(this.answers);
43
- }
44
- isEditable(index) {
45
- return !this.options.disableColumnIndexes.includes(index);
46
- }
47
- _run(callback) {
48
- this.done = callback;
49
- const events = observe(this.rl);
50
- const validation = this.handleSubmitEvents(events.line.pipe(map(this.getCurrentValues.bind(this))));
51
- validation.success.forEach(this.onEnd.bind(this));
52
- validation.error.forEach(this.onError.bind(this));
53
- events.keypress.forEach(({ key }) => {
54
- if (key.name !== 'escape') {
55
- this.isNextCloses.escape = false;
56
- }
57
- if (!this.editing) {
58
- switch (key.name) {
59
- case 'down':
60
- return this.onDownKey();
61
- case 'up':
62
- return this.onUpKey();
63
- case 'left':
64
- return this.onLeftKey();
65
- case 'right':
66
- return this.onRightKey();
67
- case 'escape':
68
- if (!this.isNextCloses.escape) {
69
- this.isNextCloses.escape = true;
70
- return this.render();
71
- }
72
- else {
73
- this.render();
74
- return this.onEnd(false);
75
- }
76
- default:
77
- if (this.isEditable(this.pointerIndexes.column)) {
78
- this.editing = true;
79
- this.clear();
80
- this.onEditPress(key);
81
- }
82
- }
83
- }
84
- else {
85
- return this.onEditPress(key);
86
- }
87
- });
88
- cliCursor.hide();
89
- this.render();
90
- return this;
91
- }
92
- get maxPageIndex() {
93
- return this.options.pageSize - 1;
94
- }
95
- get maxRowIndex() {
96
- return this.table.rows.length - 1;
97
- }
98
- get maxColumnIndex() {
99
- return this.table.columns.length - 1;
100
- }
101
- onDownKey() {
102
- if (this.pointerIndexes.row < this.maxRowIndex) {
103
- ++this.pointerIndexes.row;
104
- }
105
- this.render();
106
- }
107
- onUpKey() {
108
- if (this.pointerIndexes.row > 0) {
109
- --this.pointerIndexes.row;
110
- }
111
- this.render();
112
- }
113
- updateColumnIndex(num) {
114
- let index = this.pointerIndexes.column;
115
- for (let c = 0; c <= this.maxColumnIndex; c++) {
116
- index = getNextIndex(index, this.maxColumnIndex, num);
117
- const error = gateValidateColumnIndexError(index, this.maxColumnIndex, this.options.disableColumnIndexes);
118
- if (!error) {
119
- break;
120
- }
121
- }
122
- this.pointerIndexes.column = index;
123
- }
124
- onLeftKey() {
125
- this.updateColumnIndex(-1);
126
- this.render();
127
- }
128
- onRightKey() {
129
- this.updateColumnIndex(1);
130
- this.render();
131
- }
132
- clear() {
133
- this.temporaryBackup = null;
134
- this.purTyping = '';
135
- }
136
- onEnd(state) {
137
- this.render(true);
138
- this.status = 'answered';
139
- this.screen.done();
140
- cliCursor.show();
141
- if (state) {
142
- return this.done({
143
- state,
144
- result: this.getCurrentValues(),
145
- });
146
- }
147
- else {
148
- return this.done({
149
- state,
150
- });
151
- }
152
- }
153
- validate() {
154
- return this.options.validate(this.getCurrentValues(), this.answers);
155
- }
156
- onError(_state) {
157
- if (this.editing) {
158
- this.editing = false;
159
- this.render();
160
- }
161
- else {
162
- if (this.validate().isValid) {
163
- return this.onEnd(true);
164
- }
165
- else {
166
- return this.render();
167
- }
168
- }
169
- }
170
- updateChoice(value) {
171
- return this.table.updateRow(this.pointerIndexes.row, this.pointerIndexes.column, value, this.answers);
172
- }
173
- get currentValue() {
174
- return this.table.getValue(this.pointerIndexes.row, this.pointerIndexes.column);
175
- }
176
- onEditPress(key) {
177
- if (this.temporaryBackup === null) {
178
- this.temporaryBackup = this.currentValue;
179
- }
180
- let value = this.purTyping;
181
- switch (key.name) {
182
- case 'escape':
183
- this.purTyping = '';
184
- value = this.temporaryBackup;
185
- this.editing = false;
186
- break;
187
- case 'delete':
188
- this.purTyping = '';
189
- value = this.purTyping;
190
- break;
191
- case 'backspace': {
192
- this.purTyping = getBackspaceText(this.purTyping);
193
- value = this.purTyping;
194
- break;
195
- }
196
- default:
197
- this.purTyping = `${this.purTyping}${getKeypressValue(key)}`;
198
- value = this.purTyping;
199
- break;
200
- }
201
- const message = this.updateChoice(value);
202
- this.render(false, message);
203
- }
204
- getShowRowIndex() {
205
- const middleOfPage = Math.floor(this.options.pageSize / 2);
206
- let rowIndexFrom = Math.max(0, this.pointerIndexes.row - middleOfPage);
207
- const rowIndexTo = Math.min(this.maxRowIndex, rowIndexFrom + this.maxPageIndex);
208
- rowIndexFrom = Math.min(rowIndexFrom, rowIndexTo - (this.options.pageSize - 1));
209
- return { rowIndexFrom, rowIndexTo };
210
- }
211
- isSelected(rowIndex, columnIndex) {
212
- return this.pointerIndexes.row === rowIndex && this.pointerIndexes.column === columnIndex;
213
- }
214
- getColor(_value, isSelected, isEditable) {
215
- const value = isEditable ? _value : dim(_value);
216
- if (!isSelected) {
217
- return value;
218
- }
219
- if (this.editing) {
220
- return isEditable ? this.options.colors.editing(value) : this.options.colors.selected(value);
221
- }
222
- return isEditable ? this.options.colors.editable(value) : this.options.colors.selected(value);
223
- }
224
- render(isDisconnect = false, message = '') {
225
- let content = this.getQuestion();
226
- let bottomContent = '';
227
- content += this.options.description ? `\n${this.options.description}` : '';
228
- const { rowIndexFrom, rowIndexTo } = this.getShowRowIndex();
229
- const table = new Table({
230
- head: this.table.header,
231
- });
232
- for (let i = 0; i < this.table.rows.length; i++) {
233
- if (i < rowIndexFrom || i > rowIndexTo) {
234
- continue;
235
- }
236
- const columnValues = [];
237
- for (let ii = 0; ii < (this.table.rows[i] || []).length; ii++) {
238
- const isEditable = this.isEditable(ii);
239
- const value = this.table.rows[i][ii];
240
- const parser = this.table.getParser(ii);
241
- columnValues.push(this.getColor(parser(value, this.table.getRaw(), this.answers), this.isSelected(i, ii), isEditable));
242
- }
243
- table.push(columnValues);
244
- }
245
- content += '\n\n' + table.toString();
246
- if (!isDisconnect) {
247
- const validateResult = this.validate();
248
- if (!this.editing && validateResult.isValid) {
249
- bottomContent = this.options.confirmMessage;
250
- }
251
- if (!validateResult.isValid) {
252
- bottomContent = validateResult.message || error('Something went wrong.');
253
- }
254
- }
255
- if (this.isNextCloses.escape) {
256
- bottomContent = this.options.escapeMessage;
257
- }
258
- if (message) {
259
- bottomContent = message;
260
- }
261
- this.screen.render(content, bottomContent);
262
- }
263
- }
@@ -1,50 +0,0 @@
1
- import chalk from 'chalk';
2
- import inquirer from 'inquirer';
3
- import { success, warn, hop, cyan, error } from '../utils/chalk.js';
4
- import { TablePlugin } from './table.js';
5
- const run = async () => {
6
- inquirer.registerPrompt('table-input', TablePlugin);
7
- const question = {
8
- type: 'table-input',
9
- name: 'settings',
10
- message: 'SETTINGS',
11
- description: `You can edit data.`,
12
- disableColumnIndexes: [0],
13
- colors: {
14
- selected: warn,
15
- editable: success,
16
- editing: hop,
17
- },
18
- columns: [
19
- { name: cyan.bold('ID'), value: 'id', type: 'input' },
20
- { name: cyan.bold('title'), value: 'title', type: 'input', parser: (input) => /\.md$/.test(input) ? input : `${input}.md` },
21
- { name: cyan.bold('count'), value: 'cnt', type: 'number', validate: (input) => {
22
- const isValid = input !== '0';
23
- return {
24
- isValid,
25
- message: isValid ? '' : error('should be more than 0')
26
- };
27
- }
28
- },
29
- { name: cyan.bold('IS LOCK'), value: 'lock', type: 'confirm' },
30
- ],
31
- rows: [
32
- [chalk.bold('ABCD'), 'hoge', 0, true],
33
- [chalk.bold('EFG'), 'foo', 1, false]
34
- ],
35
- validate: (inputs, _answers) => {
36
- const isValid = inputs.every((i) => Object.values(i).every(v => `${v}`.length));
37
- return {
38
- isValid,
39
- message: isValid ? '' : 'not allow empty input',
40
- };
41
- },
42
- };
43
- const answers = await inquirer.prompt([
44
- question,
45
- ]);
46
- console.log('answers', JSON.stringify(answers, null, 2));
47
- };
48
- run().then(() => {
49
- console.log('--- end ---');
50
- });
@@ -1 +0,0 @@
1
- export type Done = (value: any) => void;
@@ -1,6 +0,0 @@
1
- export declare const PARSE_TYPES: Readonly<{
2
- readonly input: "input";
3
- readonly number: "number";
4
- readonly confirm: "confirm";
5
- }>;
6
- export type ParseType = (typeof PARSE_TYPES)[keyof typeof PARSE_TYPES];
@@ -1,5 +0,0 @@
1
- export const PARSE_TYPES = Object.freeze({
2
- input: 'input',
3
- number: 'number',
4
- confirm: 'confirm',
5
- });
@@ -1,9 +0,0 @@
1
- export declare const trim: (txt: string) => string;
2
- export declare const success: import("chalk").ChalkInstance;
3
- export declare const warn: import("chalk").ChalkInstance;
4
- export declare const info: import("chalk").ChalkInstance;
5
- export declare const error: import("chalk").ChalkInstance;
6
- export declare const hop: import("chalk").ChalkInstance;
7
- export declare const cyan: import("chalk").ChalkInstance;
8
- export declare const bold: import("chalk").ChalkInstance;
9
- export declare const dim: import("chalk").ChalkInstance;
@@ -1,10 +0,0 @@
1
- import chalk from 'chalk';
2
- export const trim = (txt) => txt.replace(/\u001b\[[0-9;]*m/g, '');
3
- export const success = chalk.green;
4
- export const warn = chalk.hex('#FFA500');
5
- export const info = chalk.hex('#77CFF5');
6
- export const error = chalk.red;
7
- export const hop = chalk.hex('#F577F5');
8
- export const cyan = chalk.cyan;
9
- export const bold = chalk.bold;
10
- export const dim = chalk.dim;
@@ -1,4 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { Key } from 'readline';
3
- export declare const getKeypressValue: (key: Key) => string | undefined;
4
- export declare const getBackspaceText: (str: string) => string;
@@ -1,20 +0,0 @@
1
- export const getKeypressValue = (key) => {
2
- switch (key.name) {
3
- case 'escape':
4
- case 'delete':
5
- case 'backspace':
6
- case 'down':
7
- case 'up':
8
- case 'left':
9
- case 'right':
10
- return '';
11
- default:
12
- return key.sequence;
13
- }
14
- };
15
- export const getBackspaceText = (str) => {
16
- if (!str) {
17
- return '';
18
- }
19
- return str.slice(0, -1);
20
- };
@@ -1,3 +0,0 @@
1
- import { ParseType } from '../types/parse-types.js';
2
- export declare const parse: (value: string, type: ParseType) => string | number | boolean;
3
- export declare const parseView: (value: string, type: ParseType) => string | number | boolean;
@@ -1,23 +0,0 @@
1
- import { isNumber } from 'my-gadgetry/type-check';
2
- import { PARSE_TYPES } from '../types/parse-types.js';
3
- const BOOL_VALUES = Object.freeze(['Y', 'y', 'yes', 'YES', 'x', 'v', 'o', 'true']);
4
- export const parse = (value, type) => {
5
- switch (type) {
6
- case PARSE_TYPES.number:
7
- return isNumber(value, true) ? Number(value) : 0;
8
- case PARSE_TYPES.confirm:
9
- return BOOL_VALUES.includes(value);
10
- default:
11
- return value;
12
- }
13
- };
14
- export const parseView = (value, type) => {
15
- switch (type) {
16
- case PARSE_TYPES.number:
17
- return value ? Number(value) : 0;
18
- case PARSE_TYPES.confirm:
19
- return value === 'true';
20
- default:
21
- return value;
22
- }
23
- };
@@ -1,2 +0,0 @@
1
- export * from '../_internal/plugins/table.js';
2
- export * from '../_internal/plugins/table/types.js';
@@ -1,2 +0,0 @@
1
- export * from '../_internal/plugins/table.js';
2
- export * from '../_internal/plugins/table/types.js';