2025-04-18 17:44:24 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-06-03 23:01:26 -07:00
|
|
|
import React, { useCallback, useEffect, useState } from 'react';
|
2025-06-27 10:57:32 -07:00
|
|
|
import { Box, Text } from 'ink';
|
2025-04-19 12:38:09 -04:00
|
|
|
import { Colors } from '../colors.js';
|
2025-05-20 16:50:32 -07:00
|
|
|
import { SuggestionsDisplay } from './SuggestionsDisplay.js';
|
2025-05-13 16:23:14 -07:00
|
|
|
import { useInputHistory } from '../hooks/useInputHistory.js';
|
2025-06-19 20:17:23 +00:00
|
|
|
import { TextBuffer } from './shared/text-buffer.js';
|
|
|
|
|
import { cpSlice, cpLen } from '../utils/textUtils.js';
|
2025-05-20 16:50:32 -07:00
|
|
|
import chalk from 'chalk';
|
|
|
|
|
import stringWidth from 'string-width';
|
|
|
|
|
import process from 'node:process';
|
2025-06-17 22:17:16 -04:00
|
|
|
import { useShellHistory } from '../hooks/useShellHistory.js';
|
2025-05-20 16:50:32 -07:00
|
|
|
import { useCompletion } from '../hooks/useCompletion.js';
|
2025-06-27 10:57:32 -07:00
|
|
|
import { useKeypress, Key } from '../hooks/useKeypress.js';
|
2025-05-20 16:50:32 -07:00
|
|
|
import { isAtCommand, isSlashCommand } from '../utils/commandUtils.js';
|
|
|
|
|
import { SlashCommand } from '../hooks/slashCommandProcessor.js';
|
2025-06-25 05:41:11 -07:00
|
|
|
import { Config } from '@google/gemini-cli-core';
|
2025-04-18 11:12:18 -07:00
|
|
|
|
2025-06-03 23:01:26 -07:00
|
|
|
export interface InputPromptProps {
|
2025-06-13 09:59:09 -07:00
|
|
|
buffer: TextBuffer;
|
2025-04-17 18:06:21 -04:00
|
|
|
onSubmit: (value: string) => void;
|
2025-05-13 16:23:14 -07:00
|
|
|
userMessages: readonly string[];
|
2025-05-14 17:33:37 -07:00
|
|
|
onClearScreen: () => void;
|
2025-05-20 16:50:32 -07:00
|
|
|
config: Config; // Added config for useCompletion
|
|
|
|
|
slashCommands: SlashCommand[]; // Added slashCommands for useCompletion
|
|
|
|
|
placeholder?: string;
|
|
|
|
|
focus?: boolean;
|
2025-06-13 09:59:09 -07:00
|
|
|
inputWidth: number;
|
|
|
|
|
suggestionsWidth: number;
|
2025-05-18 01:18:32 -07:00
|
|
|
shellModeActive: boolean;
|
|
|
|
|
setShellModeActive: (value: boolean) => void;
|
2025-05-13 11:24:04 -07:00
|
|
|
}
|
|
|
|
|
|
2025-04-30 08:31:32 -07:00
|
|
|
export const InputPrompt: React.FC<InputPromptProps> = ({
|
2025-06-13 09:59:09 -07:00
|
|
|
buffer,
|
2025-04-30 08:31:32 -07:00
|
|
|
onSubmit,
|
2025-05-13 16:23:14 -07:00
|
|
|
userMessages,
|
2025-05-14 17:33:37 -07:00
|
|
|
onClearScreen,
|
2025-05-20 16:50:32 -07:00
|
|
|
config,
|
|
|
|
|
slashCommands,
|
2025-06-06 13:44:11 -07:00
|
|
|
placeholder = ' Type your message or @path/to/file',
|
2025-05-20 16:50:32 -07:00
|
|
|
focus = true,
|
2025-06-13 09:59:09 -07:00
|
|
|
inputWidth,
|
|
|
|
|
suggestionsWidth,
|
2025-05-18 01:18:32 -07:00
|
|
|
shellModeActive,
|
|
|
|
|
setShellModeActive,
|
2025-04-30 08:31:32 -07:00
|
|
|
}) => {
|
2025-06-03 23:01:26 -07:00
|
|
|
const [justNavigatedHistory, setJustNavigatedHistory] = useState(false);
|
|
|
|
|
|
2025-05-20 16:50:32 -07:00
|
|
|
const completion = useCompletion(
|
|
|
|
|
buffer.text,
|
|
|
|
|
config.getTargetDir(),
|
|
|
|
|
isAtCommand(buffer.text) || isSlashCommand(buffer.text),
|
|
|
|
|
slashCommands,
|
Ignore folders files (#651)
# Add .gitignore-Aware File Filtering to gemini-cli
This pull request introduces .gitignore-based file filtering to the gemini-cli, ensuring that git-ignored files are automatically excluded from file-related operations and suggestions throughout the CLI. The update enhances usability, reduces noise from build artifacts and dependencies, and provides new configuration options for fine-tuning file discovery.
Key Improvements
.gitignore File Filtering
All @ (at) commands, file completions, and core discovery tools now honor .gitignore patterns by default.
Git-ignored files (such as node_modules/, dist/, .env, and .git) are excluded from results unless explicitly overridden.
The behavior can be customized via a new fileFiltering section in settings.json, including options for:
Turning .gitignore respect on/off.
Adding custom ignore patterns.
Allowing or excluding build artifacts.
Configuration & Documentation Updates
settings.json schema extended with fileFiltering options.
Documentation updated to explain new filtering controls and usage patterns.
Testing
New and updated integration/unit tests for file filtering logic, configuration merging, and edge cases.
Test coverage ensures .gitignore filtering works as intended across different workflows.
Internal Refactoring
Core file discovery logic refactored for maintainability and extensibility.
Underlying tools (ls, glob, read-many-files) now support git-aware filtering out of the box.
Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
config,
|
2025-05-20 16:50:32 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const resetCompletionState = completion.resetCompletionState;
|
2025-06-17 22:17:16 -04:00
|
|
|
const shellHistory = useShellHistory(config.getProjectRoot());
|
2025-05-20 16:50:32 -07:00
|
|
|
|
|
|
|
|
const handleSubmitAndClear = useCallback(
|
2025-05-13 16:23:14 -07:00
|
|
|
(submittedValue: string) => {
|
2025-06-17 22:17:16 -04:00
|
|
|
if (shellModeActive) {
|
|
|
|
|
shellHistory.addCommandToHistory(submittedValue);
|
|
|
|
|
}
|
2025-05-30 15:16:06 -07:00
|
|
|
// Clear the buffer *before* calling onSubmit to prevent potential re-submission
|
|
|
|
|
// if onSubmit triggers a re-render while the buffer still holds the old value.
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.setText('');
|
2025-05-30 15:16:06 -07:00
|
|
|
onSubmit(submittedValue);
|
2025-05-20 16:50:32 -07:00
|
|
|
resetCompletionState();
|
2025-05-13 16:23:14 -07:00
|
|
|
},
|
2025-06-17 22:17:16 -04:00
|
|
|
[onSubmit, buffer, resetCompletionState, shellModeActive, shellHistory],
|
2025-05-20 16:50:32 -07:00
|
|
|
);
|
|
|
|
|
|
2025-06-03 23:01:26 -07:00
|
|
|
const customSetTextAndResetCompletionSignal = useCallback(
|
|
|
|
|
(newText: string) => {
|
|
|
|
|
buffer.setText(newText);
|
|
|
|
|
setJustNavigatedHistory(true);
|
|
|
|
|
},
|
|
|
|
|
[buffer, setJustNavigatedHistory],
|
|
|
|
|
);
|
|
|
|
|
|
2025-05-13 16:23:14 -07:00
|
|
|
const inputHistory = useInputHistory({
|
|
|
|
|
userMessages,
|
2025-05-20 16:50:32 -07:00
|
|
|
onSubmit: handleSubmitAndClear,
|
2025-06-17 22:17:16 -04:00
|
|
|
isActive: !completion.showSuggestions && !shellModeActive,
|
2025-05-20 16:50:32 -07:00
|
|
|
currentQuery: buffer.text,
|
2025-06-03 23:01:26 -07:00
|
|
|
onChange: customSetTextAndResetCompletionSignal,
|
2025-05-13 16:23:14 -07:00
|
|
|
});
|
|
|
|
|
|
2025-06-03 23:01:26 -07:00
|
|
|
// Effect to reset completion if history navigation just occurred and set the text
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (justNavigatedHistory) {
|
|
|
|
|
resetCompletionState();
|
|
|
|
|
setJustNavigatedHistory(false);
|
|
|
|
|
}
|
|
|
|
|
}, [
|
|
|
|
|
justNavigatedHistory,
|
|
|
|
|
buffer.text,
|
|
|
|
|
resetCompletionState,
|
|
|
|
|
setJustNavigatedHistory,
|
|
|
|
|
]);
|
|
|
|
|
|
2025-05-20 16:50:32 -07:00
|
|
|
const completionSuggestions = completion.suggestions;
|
2025-05-07 12:30:32 -07:00
|
|
|
const handleAutocomplete = useCallback(
|
|
|
|
|
(indexToUse: number) => {
|
2025-05-20 16:50:32 -07:00
|
|
|
if (indexToUse < 0 || indexToUse >= completionSuggestions.length) {
|
2025-05-07 12:30:32 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
const query = buffer.text;
|
2025-07-01 15:51:43 -07:00
|
|
|
const suggestion = completionSuggestions[indexToUse].value;
|
2025-04-30 08:31:32 -07:00
|
|
|
|
2025-05-20 16:50:32 -07:00
|
|
|
if (query.trimStart().startsWith('/')) {
|
2025-06-15 11:40:39 -07:00
|
|
|
const parts = query.trimStart().substring(1).split(' ');
|
|
|
|
|
const commandName = parts[0];
|
2025-05-07 12:30:32 -07:00
|
|
|
const slashIndex = query.indexOf('/');
|
|
|
|
|
const base = query.substring(0, slashIndex + 1);
|
2025-06-15 11:40:39 -07:00
|
|
|
|
|
|
|
|
const command = slashCommands.find((cmd) => cmd.name === commandName);
|
2025-07-05 17:23:39 +02:00
|
|
|
// Make sure completion isn't the original command when command.completion hasn't happened yet.
|
2025-07-01 15:51:43 -07:00
|
|
|
if (command && command.completion && suggestion !== commandName) {
|
|
|
|
|
const newValue = `${base}${commandName} ${suggestion}`;
|
|
|
|
|
if (newValue === query) {
|
|
|
|
|
handleSubmitAndClear(newValue);
|
|
|
|
|
} else {
|
|
|
|
|
buffer.setText(newValue);
|
|
|
|
|
}
|
2025-06-15 11:40:39 -07:00
|
|
|
} else {
|
2025-07-01 15:51:43 -07:00
|
|
|
const newValue = base + suggestion;
|
2025-07-07 15:43:27 -04:00
|
|
|
if (newValue === query) {
|
|
|
|
|
handleSubmitAndClear(newValue);
|
|
|
|
|
} else {
|
|
|
|
|
buffer.setText(newValue);
|
|
|
|
|
}
|
2025-06-15 11:40:39 -07:00
|
|
|
}
|
2025-05-07 12:30:32 -07:00
|
|
|
} else {
|
|
|
|
|
const atIndex = query.lastIndexOf('@');
|
|
|
|
|
if (atIndex === -1) return;
|
|
|
|
|
const pathPart = query.substring(atIndex + 1);
|
|
|
|
|
const lastSlashIndexInPath = pathPart.lastIndexOf('/');
|
2025-05-20 16:50:32 -07:00
|
|
|
let autoCompleteStartIndex = atIndex + 1;
|
|
|
|
|
if (lastSlashIndexInPath !== -1) {
|
|
|
|
|
autoCompleteStartIndex += lastSlashIndexInPath + 1;
|
2025-05-07 12:30:32 -07:00
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.replaceRangeByOffset(
|
|
|
|
|
autoCompleteStartIndex,
|
|
|
|
|
buffer.text.length,
|
2025-07-01 15:51:43 -07:00
|
|
|
suggestion,
|
2025-05-20 16:50:32 -07:00
|
|
|
);
|
2025-05-07 12:30:32 -07:00
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
resetCompletionState();
|
2025-05-07 12:30:32 -07:00
|
|
|
},
|
2025-06-15 11:40:39 -07:00
|
|
|
[
|
|
|
|
|
resetCompletionState,
|
|
|
|
|
handleSubmitAndClear,
|
|
|
|
|
buffer,
|
|
|
|
|
completionSuggestions,
|
|
|
|
|
slashCommands,
|
|
|
|
|
],
|
2025-05-07 12:30:32 -07:00
|
|
|
);
|
2025-04-30 08:31:32 -07:00
|
|
|
|
2025-06-27 10:57:32 -07:00
|
|
|
const handleInput = useCallback(
|
|
|
|
|
(key: Key) => {
|
2025-05-20 16:50:32 -07:00
|
|
|
if (!focus) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const query = buffer.text;
|
|
|
|
|
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.sequence === '!' && query === '' && !completion.showSuggestions) {
|
2025-05-18 01:18:32 -07:00
|
|
|
setShellModeActive(!shellModeActive);
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.setText(''); // Clear the '!' from input
|
2025-05-18 01:18:32 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
|
|
|
|
|
if (completion.showSuggestions) {
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.name === 'up') {
|
2025-05-20 16:50:32 -07:00
|
|
|
completion.navigateUp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.name === 'down') {
|
2025-05-20 16:50:32 -07:00
|
|
|
completion.navigateDown();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.name === 'tab') {
|
2025-05-20 16:50:32 -07:00
|
|
|
if (completion.suggestions.length > 0) {
|
2025-05-07 12:30:32 -07:00
|
|
|
const targetIndex =
|
2025-05-20 16:50:32 -07:00
|
|
|
completion.activeSuggestionIndex === -1
|
|
|
|
|
? 0
|
|
|
|
|
: completion.activeSuggestionIndex;
|
|
|
|
|
if (targetIndex < completion.suggestions.length) {
|
2025-05-07 12:30:32 -07:00
|
|
|
handleAutocomplete(targetIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.name === 'return') {
|
2025-05-20 16:50:32 -07:00
|
|
|
if (completion.activeSuggestionIndex >= 0) {
|
|
|
|
|
handleAutocomplete(completion.activeSuggestionIndex);
|
|
|
|
|
} else if (query.trim()) {
|
|
|
|
|
handleSubmitAndClear(query);
|
2025-05-07 12:30:32 -07:00
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
return;
|
2025-04-19 19:45:42 +01:00
|
|
|
}
|
2025-05-14 17:33:37 -07:00
|
|
|
} else {
|
|
|
|
|
// Keybindings when suggestions are not shown
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.ctrl && key.name === 'l') {
|
2025-05-14 17:33:37 -07:00
|
|
|
onClearScreen();
|
2025-06-27 10:57:32 -07:00
|
|
|
return;
|
2025-05-14 17:33:37 -07:00
|
|
|
}
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.ctrl && key.name === 'p') {
|
2025-05-14 17:33:37 -07:00
|
|
|
inputHistory.navigateUp();
|
2025-06-27 10:57:32 -07:00
|
|
|
return;
|
2025-05-14 17:33:37 -07:00
|
|
|
}
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.ctrl && key.name === 'n') {
|
2025-05-14 17:33:37 -07:00
|
|
|
inputHistory.navigateDown();
|
2025-06-27 10:57:32 -07:00
|
|
|
return;
|
2025-05-14 17:33:37 -07:00
|
|
|
}
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.name === 'escape') {
|
2025-05-20 22:45:10 -07:00
|
|
|
if (shellModeActive) {
|
|
|
|
|
setShellModeActive(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
completion.resetCompletionState();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ctrl+A (Home)
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.ctrl && key.name === 'a') {
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.move('home');
|
|
|
|
|
buffer.moveToOffset(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Ctrl+E (End)
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.ctrl && key.name === 'e') {
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.move('end');
|
|
|
|
|
buffer.moveToOffset(cpLen(buffer.text));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Ctrl+L (Clear Screen)
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.ctrl && key.name === 'l') {
|
2025-05-20 16:50:32 -07:00
|
|
|
onClearScreen();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Ctrl+P (History Up)
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.ctrl && key.name === 'p' && !completion.showSuggestions) {
|
2025-05-20 16:50:32 -07:00
|
|
|
inputHistory.navigateUp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Ctrl+N (History Down)
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.ctrl && key.name === 'n' && !completion.showSuggestions) {
|
2025-05-20 16:50:32 -07:00
|
|
|
inputHistory.navigateDown();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Core text editing from MultilineTextEditor's useInput
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.ctrl && key.name === 'k') {
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.killLineRight();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.ctrl && key.name === 'u') {
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.killLineLeft();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const isCtrlX =
|
2025-06-27 10:57:32 -07:00
|
|
|
(key.ctrl && (key.name === 'x' || key.sequence === '\x18')) ||
|
|
|
|
|
key.sequence === '\x18';
|
2025-05-20 16:50:32 -07:00
|
|
|
const isCtrlEFromEditor =
|
2025-06-27 10:57:32 -07:00
|
|
|
(key.ctrl && (key.name === 'e' || key.sequence === '\x05')) ||
|
|
|
|
|
key.sequence === '\x05' ||
|
2025-05-20 16:50:32 -07:00
|
|
|
(!key.ctrl &&
|
2025-06-27 10:57:32 -07:00
|
|
|
key.name === 'e' &&
|
|
|
|
|
key.sequence.length === 1 &&
|
|
|
|
|
key.sequence.charCodeAt(0) === 5);
|
2025-05-20 16:50:32 -07:00
|
|
|
|
|
|
|
|
if (isCtrlX || isCtrlEFromEditor) {
|
2025-06-27 10:57:32 -07:00
|
|
|
if (isCtrlEFromEditor && !(key.ctrl && key.name === 'e')) {
|
2025-05-20 16:50:32 -07:00
|
|
|
// Avoid double handling Ctrl+E
|
|
|
|
|
buffer.openInExternalEditor();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (isCtrlX) {
|
|
|
|
|
buffer.openInExternalEditor();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
process.env['TEXTBUFFER_DEBUG'] === '1' ||
|
|
|
|
|
process.env['TEXTBUFFER_DEBUG'] === 'true'
|
|
|
|
|
) {
|
2025-06-27 10:57:32 -07:00
|
|
|
console.log('[InputPromptCombined] event', { key });
|
2025-05-20 16:50:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ctrl+Enter for newline, Enter for submit
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.name === 'return') {
|
2025-06-17 10:03:05 -07:00
|
|
|
const [row, col] = buffer.cursor;
|
|
|
|
|
const line = buffer.lines[row];
|
|
|
|
|
const charBefore = col > 0 ? cpSlice(line, col - 1, col) : '';
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.ctrl || key.meta || charBefore === '\\' || key.paste) {
|
2025-06-17 10:03:05 -07:00
|
|
|
// Ctrl+Enter or escaped newline
|
|
|
|
|
if (charBefore === '\\') {
|
|
|
|
|
buffer.backspace();
|
|
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.newline();
|
|
|
|
|
} else {
|
|
|
|
|
// Enter for submit
|
|
|
|
|
if (query.trim()) {
|
|
|
|
|
handleSubmitAndClear(query);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Standard arrow navigation within the buffer
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.name === 'up' && !completion.showSuggestions) {
|
2025-06-17 22:17:16 -04:00
|
|
|
if (shellModeActive) {
|
|
|
|
|
const prevCommand = shellHistory.getPreviousCommand();
|
|
|
|
|
if (prevCommand !== null) {
|
|
|
|
|
buffer.setText(prevCommand);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
if (
|
2025-06-03 23:01:26 -07:00
|
|
|
(buffer.allVisualLines.length === 1 || // Always navigate for single line
|
|
|
|
|
(buffer.visualCursor[0] === 0 && buffer.visualScrollRow === 0)) &&
|
2025-05-20 16:50:32 -07:00
|
|
|
inputHistory.navigateUp
|
|
|
|
|
) {
|
|
|
|
|
inputHistory.navigateUp();
|
|
|
|
|
} else {
|
|
|
|
|
buffer.move('up');
|
|
|
|
|
}
|
|
|
|
|
return;
|
2025-04-19 19:45:42 +01:00
|
|
|
}
|
2025-06-27 10:57:32 -07:00
|
|
|
if (key.name === 'down' && !completion.showSuggestions) {
|
2025-06-17 22:17:16 -04:00
|
|
|
if (shellModeActive) {
|
|
|
|
|
const nextCommand = shellHistory.getNextCommand();
|
|
|
|
|
if (nextCommand !== null) {
|
|
|
|
|
buffer.setText(nextCommand);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
if (
|
2025-06-03 23:01:26 -07:00
|
|
|
(buffer.allVisualLines.length === 1 || // Always navigate for single line
|
|
|
|
|
buffer.visualCursor[0] === buffer.allVisualLines.length - 1) &&
|
2025-05-20 16:50:32 -07:00
|
|
|
inputHistory.navigateDown
|
|
|
|
|
) {
|
|
|
|
|
inputHistory.navigateDown();
|
|
|
|
|
} else {
|
|
|
|
|
buffer.move('down');
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fallback to buffer's default input handling
|
2025-06-27 10:57:32 -07:00
|
|
|
buffer.handleInput(key);
|
2025-04-19 19:45:42 +01:00
|
|
|
},
|
2025-06-27 10:57:32 -07:00
|
|
|
[
|
|
|
|
|
focus,
|
|
|
|
|
buffer,
|
|
|
|
|
completion,
|
|
|
|
|
shellModeActive,
|
|
|
|
|
setShellModeActive,
|
|
|
|
|
onClearScreen,
|
|
|
|
|
inputHistory,
|
|
|
|
|
handleAutocomplete,
|
|
|
|
|
handleSubmitAndClear,
|
|
|
|
|
shellHistory,
|
|
|
|
|
],
|
2025-04-19 19:45:42 +01:00
|
|
|
);
|
2025-04-18 17:06:16 +01:00
|
|
|
|
2025-06-27 10:57:32 -07:00
|
|
|
useKeypress(handleInput, { isActive: focus });
|
|
|
|
|
|
2025-05-20 16:50:32 -07:00
|
|
|
const linesToRender = buffer.viewportVisualLines;
|
|
|
|
|
const [cursorVisualRowAbsolute, cursorVisualColAbsolute] =
|
|
|
|
|
buffer.visualCursor;
|
|
|
|
|
const scrollVisualRow = buffer.visualScrollRow;
|
|
|
|
|
|
2025-04-17 18:06:21 -04:00
|
|
|
return (
|
2025-05-20 16:50:32 -07:00
|
|
|
<>
|
|
|
|
|
<Box
|
|
|
|
|
borderStyle="round"
|
|
|
|
|
borderColor={shellModeActive ? Colors.AccentYellow : Colors.AccentBlue}
|
|
|
|
|
paddingX={1}
|
|
|
|
|
>
|
|
|
|
|
<Text
|
|
|
|
|
color={shellModeActive ? Colors.AccentYellow : Colors.AccentPurple}
|
|
|
|
|
>
|
|
|
|
|
{shellModeActive ? '! ' : '> '}
|
|
|
|
|
</Text>
|
|
|
|
|
<Box flexGrow={1} flexDirection="column">
|
|
|
|
|
{buffer.text.length === 0 && placeholder ? (
|
2025-06-06 13:44:11 -07:00
|
|
|
focus ? (
|
|
|
|
|
<Text>
|
|
|
|
|
{chalk.inverse(placeholder.slice(0, 1))}
|
|
|
|
|
<Text color={Colors.Gray}>{placeholder.slice(1)}</Text>
|
|
|
|
|
</Text>
|
|
|
|
|
) : (
|
|
|
|
|
<Text color={Colors.Gray}>{placeholder}</Text>
|
|
|
|
|
)
|
2025-05-20 16:50:32 -07:00
|
|
|
) : (
|
|
|
|
|
linesToRender.map((lineText, visualIdxInRenderedSet) => {
|
|
|
|
|
const cursorVisualRow = cursorVisualRowAbsolute - scrollVisualRow;
|
2025-06-13 09:59:09 -07:00
|
|
|
let display = cpSlice(lineText, 0, inputWidth);
|
2025-05-20 16:50:32 -07:00
|
|
|
const currentVisualWidth = stringWidth(display);
|
2025-06-13 09:59:09 -07:00
|
|
|
if (currentVisualWidth < inputWidth) {
|
|
|
|
|
display = display + ' '.repeat(inputWidth - currentVisualWidth);
|
2025-05-20 16:50:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (visualIdxInRenderedSet === cursorVisualRow) {
|
|
|
|
|
const relativeVisualColForHighlight = cursorVisualColAbsolute;
|
|
|
|
|
if (relativeVisualColForHighlight >= 0) {
|
|
|
|
|
if (relativeVisualColForHighlight < cpLen(display)) {
|
|
|
|
|
const charToHighlight =
|
|
|
|
|
cpSlice(
|
|
|
|
|
display,
|
|
|
|
|
relativeVisualColForHighlight,
|
|
|
|
|
relativeVisualColForHighlight + 1,
|
|
|
|
|
) || ' ';
|
|
|
|
|
const highlighted = chalk.inverse(charToHighlight);
|
|
|
|
|
display =
|
|
|
|
|
cpSlice(display, 0, relativeVisualColForHighlight) +
|
|
|
|
|
highlighted +
|
|
|
|
|
cpSlice(display, relativeVisualColForHighlight + 1);
|
|
|
|
|
} else if (
|
|
|
|
|
relativeVisualColForHighlight === cpLen(display) &&
|
2025-06-13 09:59:09 -07:00
|
|
|
cpLen(display) === inputWidth
|
2025-05-20 16:50:32 -07:00
|
|
|
) {
|
|
|
|
|
display = display + chalk.inverse(' ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<Text key={`line-${visualIdxInRenderedSet}`}>{display}</Text>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
2025-04-19 12:38:09 -04:00
|
|
|
</Box>
|
2025-05-20 16:50:32 -07:00
|
|
|
{completion.showSuggestions && (
|
|
|
|
|
<Box>
|
|
|
|
|
<SuggestionsDisplay
|
|
|
|
|
suggestions={completion.suggestions}
|
|
|
|
|
activeIndex={completion.activeSuggestionIndex}
|
|
|
|
|
isLoading={completion.isLoadingSuggestions}
|
|
|
|
|
width={suggestionsWidth}
|
|
|
|
|
scrollOffset={completion.visibleStartIndex}
|
|
|
|
|
userInput={buffer.text}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2025-04-17 18:06:21 -04:00
|
|
|
);
|
2025-04-18 18:08:43 -04:00
|
|
|
};
|