Skip to content

Commit 8d443c6

Browse files
committed
feat(options): add hint for all actions available for each input
1 parent 80ebb82 commit 8d443c6

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/cli/ui/components/options.ui.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { convertGBToMB } from '../../../utils/unit-conversions.js';
88
import { RESULT_TYPE_INFO } from '../../../constants/messages.constants.js';
99
import { IConfig } from '../../../cli/interfaces/config.interface.js';
1010
import { COLORS } from '../../../constants/cli.constants.js';
11+
import { OPTIONS_HINTS_BY_TYPE } from '../../../constants/options.constants.js';
1112

1213
type OptionType = 'checkbox' | 'dropdown' | 'input';
1314

@@ -187,6 +188,7 @@ export class OptionsUi extends BaseUi implements InteractiveUi {
187188

188189
render(): void {
189190
this.clear();
191+
this.printHintMessage();
190192
let currentRow = MARGINS.ROW_RESULTS_START;
191193

192194
this.printAt(colors.bold.bgYellow.black(' OPTIONS '), {
@@ -236,6 +238,24 @@ export class OptionsUi extends BaseUi implements InteractiveUi {
236238
}
237239
}
238240

241+
private printHintMessage() {
242+
const optionSelected = this.options[this.selectedIndex];
243+
244+
const hintText =
245+
optionSelected.type === 'input' && this.isEditing
246+
? OPTIONS_HINTS_BY_TYPE['input-exit']
247+
: OPTIONS_HINTS_BY_TYPE[optionSelected.type];
248+
249+
if (!hintText) {
250+
return;
251+
}
252+
253+
this.printAt(hintText, {
254+
x: 15,
255+
y: MARGINS.ROW_RESULTS_START,
256+
});
257+
}
258+
239259
clear(): void {
240260
for (let row = MARGINS.ROW_RESULTS_START; row < this.terminal.rows; row++) {
241261
this.clearLine(row);

src/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from './sort.result.js';
55
export * from './spinner.constants.js';
66
export * from './update.constants.js';
77
export * from './recursive-rmdir-node-support.constants.js';
8+
export * from './options.constants.js';

src/constants/options.constants.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import colors from 'colors';
2+
3+
export const OPTIONS_HINTS_BY_TYPE = {
4+
input: colors.gray(
5+
`${colors.bold.underline('SPACE')} or ${colors.bold.underline('ENTER')} to edit.`,
6+
),
7+
'input-exit': colors.gray(
8+
`${colors.bold.underline('ENTER')} to confirm. ${colors.bold.underline('ESC')} To cancel.`,
9+
),
10+
dropdown: colors.gray(
11+
`${colors.bold.underline('SPACE')}/${colors.bold.underline('SHIFT')}+${colors.bold.underline('SPACE')} to navigate.`,
12+
),
13+
checkbox: colors.gray(
14+
`${colors.bold.underline('SPACE')} or ${colors.bold.underline('ENTER')} to toggle.`,
15+
),
16+
};

0 commit comments

Comments
 (0)