Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/core/src/server/cliShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import type { CliShortcut, NormalizedConfig } from '../types/config';
export const isCliShortcutsEnabled = (config: NormalizedConfig): boolean =>
config.dev.cliShortcuts && isTTY('stdin');

// Normalize user input so shortcuts are case-insensitive
// and still work with accidental surrounding whitespace.
export const normalizeShortcutInput = (input: string): string =>
input.trim().toLowerCase();

export async function setupCliShortcuts({
help = true,
openPage,
Expand Down Expand Up @@ -84,6 +89,8 @@ export async function setupCliShortcuts({
});

rl.on('line', (input) => {
input = normalizeShortcutInput(input);

if (input === 'h') {
let message = `\n ${color.bold(color.blue('Shortcuts:'))}\n`;
for (const shortcut of shortcuts) {
Expand Down
8 changes: 8 additions & 0 deletions packages/core/tests/cliShortcuts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { normalizeShortcutInput } from '../src/server/cliShortcuts';

test('normalizeShortcutInput', () => {
expect(normalizeShortcutInput('h')).toBe('h');
expect(normalizeShortcutInput(' H ')).toBe('h');
expect(normalizeShortcutInput('\to\t')).toBe('o');
expect(normalizeShortcutInput(' Q')).toBe('q');
});
Loading