/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import type React from 'react'; import { Box, Text } from 'ink'; import { theme } from '../semantic-colors.js'; import { type SlashCommand, CommandKind } from '../commands/types.js'; import { t } from '../../i18n/index.js'; interface Help { commands: readonly SlashCommand[]; width?: number; } export const Help: React.FC = ({ commands, width }) => ( {/* Basics */} {t('Basics:')} {t('Add context')} :{' '} {t( 'Use {{symbol}} to specify files for context (e.g., {{example}}) to target specific files or folders.', { symbol: t('@'), example: t('@src/myFile.ts'), }, )} {t('Shell mode')} :{' '} {t( 'Execute shell commands via {{symbol}} (e.g., {{example1}}) or use natural language (e.g., {{example2}}).', { symbol: t('!'), example1: t('!npm run start'), example2: t('start server'), }, )} {/* Commands */} {t('Commands:')} {commands .filter((command) => command.description && !command.hidden) .map((command: SlashCommand) => ( {' '} {formatCommandLabel(command, '/')} {command.kind === CommandKind.MCP_PROMPT && ( [MCP] )} {command.description && ' - ' + command.description} {command.subCommands && command.subCommands .filter((subCommand) => !subCommand.hidden) .map((subCommand) => ( {' '} {formatCommandLabel(subCommand)} {subCommand.description && ' - ' + subCommand.description} ))} ))} {' '} !{' '} - {t('shell command')} [MCP] -{' '} {t('Model Context Protocol command (from external servers)')} {/* Shortcuts */} {t('Keyboard Shortcuts:')} Alt+Left/Right {' '} - {t('Jump through words in the input')} Ctrl+C {' '} - {t('Close dialogs, cancel requests, or quit application')} {process.platform === 'win32' ? 'Ctrl+Enter' : 'Ctrl+J'} {' '} -{' '} {process.platform === 'linux' ? t('New line (Alt+Enter works for certain linux distros)') : t('New line')} Ctrl+L {' '} - {t('Clear the screen')} {process.platform === 'darwin' ? 'Ctrl+X / Meta+Enter' : 'Ctrl+X'} {' '} - {t('Open input in external editor')} Enter {' '} - {t('Send message')} Esc {' '} - {t('Cancel operation / Clear input (double press)')} Shift+Tab {' '} - {t('Cycle approval modes')} Up/Down {' '} - {t('Cycle through your prompt history')} {t('For a full list of shortcuts, see {{docPath}}', { docPath: t('docs/keyboard-shortcuts.md'), })} ); /** * Builds a display label for a slash command, including any alternate names. */ function formatCommandLabel(command: SlashCommand, prefix = ''): string { const altNames = command.altNames?.filter(Boolean); const baseLabel = `${prefix}${command.name}`; if (!altNames || altNames.length === 0) { return baseLabel; } return `${baseLabel} (${altNames.join(', ')})`; }