2025-04-18 17:44:24 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-08-26 00:04:53 +02:00
|
|
|
import type React from 'react';
|
|
|
|
|
import { useCallback, useEffect, useState, useRef } from 'react';
|
2025-06-27 10:57:32 -07:00
|
|
|
import { Box, Text } from 'ink';
|
2025-08-07 16:11:35 -07:00
|
|
|
import { theme } from '../semantic-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-08-26 00:04:53 +02:00
|
|
|
import type { TextBuffer } from './shared/text-buffer.js';
|
|
|
|
|
import { logicalPosToOffset } from './shared/text-buffer.js';
|
2025-08-21 16:04:04 +08:00
|
|
|
import { cpSlice, cpLen, toCodePoints } from '../utils/textUtils.js';
|
2025-05-20 16:50:32 -07:00
|
|
|
import chalk from 'chalk';
|
|
|
|
|
import stringWidth from 'string-width';
|
2025-06-17 22:17:16 -04:00
|
|
|
import { useShellHistory } from '../hooks/useShellHistory.js';
|
2025-08-04 00:53:24 +05:00
|
|
|
import { useReverseSearchCompletion } from '../hooks/useReverseSearchCompletion.js';
|
2025-08-04 13:35:26 -07:00
|
|
|
import { useCommandCompletion } from '../hooks/useCommandCompletion.js';
|
2025-08-26 00:04:53 +02:00
|
|
|
import type { Key } from '../hooks/useKeypress.js';
|
|
|
|
|
import { useKeypress } from '../hooks/useKeypress.js';
|
2025-08-09 16:03:17 +09:00
|
|
|
import { keyMatchers, Command } from '../keyMatchers.js';
|
2025-08-26 00:04:53 +02:00
|
|
|
import type { CommandContext, SlashCommand } from '../commands/types.js';
|
|
|
|
|
import type { Config } from '@google/gemini-cli-core';
|
2025-09-02 09:21:55 -07:00
|
|
|
import { parseInputForHighlighting } from '../utils/highlight.js';
|
2025-07-12 00:06:49 -04:00
|
|
|
import {
|
|
|
|
|
clipboardHasImage,
|
|
|
|
|
saveClipboardImage,
|
|
|
|
|
cleanupOldClipboardImages,
|
|
|
|
|
} from '../utils/clipboardUtils.js';
|
2025-08-25 22:11:27 +02:00
|
|
|
import * as path from 'node:path';
|
2025-08-28 20:52:14 +00:00
|
|
|
import { SCREEN_READER_USER_PREFIX } from '../textConstants.js';
|
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-07-07 16:45:44 -04:00
|
|
|
config: Config;
|
2025-07-20 16:57:34 -04:00
|
|
|
slashCommands: readonly SlashCommand[];
|
2025-07-07 16:45:44 -04:00
|
|
|
commandContext: CommandContext;
|
2025-05-20 16:50:32 -07:00
|
|
|
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-08-10 06:26:43 +08:00
|
|
|
onEscapePromptChange?: (showPrompt: boolean) => void;
|
2025-07-25 15:36:42 -07:00
|
|
|
vimHandleInput?: (key: Key) => boolean;
|
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-07-07 16:45:44 -04:00
|
|
|
commandContext,
|
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-08-10 06:26:43 +08:00
|
|
|
onEscapePromptChange,
|
2025-07-25 15:36:42 -07:00
|
|
|
vimHandleInput,
|
2025-04-30 08:31:32 -07:00
|
|
|
}) => {
|
2025-06-03 23:01:26 -07:00
|
|
|
const [justNavigatedHistory, setJustNavigatedHistory] = useState(false);
|
2025-08-10 06:26:43 +08:00
|
|
|
const [escPressCount, setEscPressCount] = useState(0);
|
|
|
|
|
const [showEscapePrompt, setShowEscapePrompt] = useState(false);
|
|
|
|
|
const escapeTimerRef = useRef<NodeJS.Timeout | null>(null);
|
2025-07-18 14:54:10 -07:00
|
|
|
|
2025-07-31 05:38:20 +09:00
|
|
|
const [dirs, setDirs] = useState<readonly string[]>(
|
|
|
|
|
config.getWorkspaceContext().getDirectories(),
|
|
|
|
|
);
|
|
|
|
|
const dirsChanged = config.getWorkspaceContext().getDirectories();
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (dirs.length !== dirsChanged.length) {
|
|
|
|
|
setDirs(dirsChanged);
|
|
|
|
|
}
|
|
|
|
|
}, [dirs.length, dirsChanged]);
|
2025-08-04 00:53:24 +05:00
|
|
|
const [reverseSearchActive, setReverseSearchActive] = useState(false);
|
|
|
|
|
const [textBeforeReverseSearch, setTextBeforeReverseSearch] = useState('');
|
|
|
|
|
const [cursorPosition, setCursorPosition] = useState<[number, number]>([
|
|
|
|
|
0, 0,
|
|
|
|
|
]);
|
2025-08-20 10:55:47 +09:00
|
|
|
const shellHistory = useShellHistory(config.getProjectRoot(), config.storage);
|
2025-08-04 00:53:24 +05:00
|
|
|
const historyData = shellHistory.history;
|
2025-07-31 05:38:20 +09:00
|
|
|
|
2025-08-04 13:35:26 -07:00
|
|
|
const completion = useCommandCompletion(
|
2025-07-24 21:41:35 -07:00
|
|
|
buffer,
|
2025-07-31 05:38:20 +09:00
|
|
|
dirs,
|
2025-05-20 16:50:32 -07:00
|
|
|
config.getTargetDir(),
|
|
|
|
|
slashCommands,
|
2025-07-07 16:45:44 -04:00
|
|
|
commandContext,
|
2025-08-04 00:53:24 +05:00
|
|
|
reverseSearchActive,
|
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
|
|
|
);
|
|
|
|
|
|
2025-08-04 00:53:24 +05:00
|
|
|
const reverseSearchCompletion = useReverseSearchCompletion(
|
|
|
|
|
buffer,
|
|
|
|
|
historyData,
|
|
|
|
|
reverseSearchActive,
|
|
|
|
|
);
|
2025-05-20 16:50:32 -07:00
|
|
|
const resetCompletionState = completion.resetCompletionState;
|
2025-08-04 00:53:24 +05:00
|
|
|
const resetReverseSearchCompletionState =
|
|
|
|
|
reverseSearchCompletion.resetCompletionState;
|
2025-05-20 16:50:32 -07:00
|
|
|
|
2025-08-10 06:26:43 +08:00
|
|
|
const resetEscapeState = useCallback(() => {
|
|
|
|
|
if (escapeTimerRef.current) {
|
|
|
|
|
clearTimeout(escapeTimerRef.current);
|
|
|
|
|
escapeTimerRef.current = null;
|
|
|
|
|
}
|
|
|
|
|
setEscPressCount(0);
|
|
|
|
|
setShowEscapePrompt(false);
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
// Notify parent component about escape prompt state changes
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (onEscapePromptChange) {
|
|
|
|
|
onEscapePromptChange(showEscapePrompt);
|
|
|
|
|
}
|
|
|
|
|
}, [showEscapePrompt, onEscapePromptChange]);
|
|
|
|
|
|
|
|
|
|
// Clear escape prompt timer on unmount
|
|
|
|
|
useEffect(
|
|
|
|
|
() => () => {
|
|
|
|
|
if (escapeTimerRef.current) {
|
|
|
|
|
clearTimeout(escapeTimerRef.current);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
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-08-04 00:53:24 +05:00
|
|
|
resetReverseSearchCompletionState();
|
2025-05-13 16:23:14 -07:00
|
|
|
},
|
2025-08-04 00:53:24 +05:00
|
|
|
[
|
|
|
|
|
onSubmit,
|
|
|
|
|
buffer,
|
|
|
|
|
resetCompletionState,
|
|
|
|
|
shellModeActive,
|
|
|
|
|
shellHistory,
|
|
|
|
|
resetReverseSearchCompletionState,
|
|
|
|
|
],
|
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-07-18 01:30:39 +03:00
|
|
|
isActive:
|
|
|
|
|
(!completion.showSuggestions || completion.suggestions.length === 1) &&
|
|
|
|
|
!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();
|
2025-08-04 00:53:24 +05:00
|
|
|
resetReverseSearchCompletionState();
|
2025-06-03 23:01:26 -07:00
|
|
|
setJustNavigatedHistory(false);
|
|
|
|
|
}
|
|
|
|
|
}, [
|
|
|
|
|
justNavigatedHistory,
|
|
|
|
|
buffer.text,
|
|
|
|
|
resetCompletionState,
|
|
|
|
|
setJustNavigatedHistory,
|
2025-08-04 00:53:24 +05:00
|
|
|
resetReverseSearchCompletionState,
|
2025-06-03 23:01:26 -07:00
|
|
|
]);
|
|
|
|
|
|
2025-07-12 00:06:49 -04:00
|
|
|
// Handle clipboard image pasting with Ctrl+V
|
|
|
|
|
const handleClipboardImage = useCallback(async () => {
|
|
|
|
|
try {
|
|
|
|
|
if (await clipboardHasImage()) {
|
|
|
|
|
const imagePath = await saveClipboardImage(config.getTargetDir());
|
|
|
|
|
if (imagePath) {
|
|
|
|
|
// Clean up old images
|
|
|
|
|
cleanupOldClipboardImages(config.getTargetDir()).catch(() => {
|
|
|
|
|
// Ignore cleanup errors
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Get relative path from current directory
|
|
|
|
|
const relativePath = path.relative(config.getTargetDir(), imagePath);
|
|
|
|
|
|
|
|
|
|
// Insert @path reference at cursor position
|
|
|
|
|
const insertText = `@${relativePath}`;
|
|
|
|
|
const currentText = buffer.text;
|
|
|
|
|
const [row, col] = buffer.cursor;
|
|
|
|
|
|
|
|
|
|
// Calculate offset from row/col
|
|
|
|
|
let offset = 0;
|
|
|
|
|
for (let i = 0; i < row; i++) {
|
|
|
|
|
offset += buffer.lines[i].length + 1; // +1 for newline
|
|
|
|
|
}
|
|
|
|
|
offset += col;
|
|
|
|
|
|
|
|
|
|
// Add spaces around the path if needed
|
|
|
|
|
let textToInsert = insertText;
|
|
|
|
|
const charBefore = offset > 0 ? currentText[offset - 1] : '';
|
|
|
|
|
const charAfter =
|
|
|
|
|
offset < currentText.length ? currentText[offset] : '';
|
|
|
|
|
|
|
|
|
|
if (charBefore && charBefore !== ' ' && charBefore !== '\n') {
|
|
|
|
|
textToInsert = ' ' + textToInsert;
|
|
|
|
|
}
|
|
|
|
|
if (!charAfter || (charAfter !== ' ' && charAfter !== '\n')) {
|
|
|
|
|
textToInsert = textToInsert + ' ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Insert at cursor position
|
|
|
|
|
buffer.replaceRangeByOffset(offset, offset, textToInsert);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error handling clipboard image:', error);
|
|
|
|
|
}
|
|
|
|
|
}, [buffer, config]);
|
|
|
|
|
|
2025-06-27 10:57:32 -07:00
|
|
|
const handleInput = useCallback(
|
|
|
|
|
(key: Key) => {
|
2025-07-25 20:26:13 +00:00
|
|
|
/// We want to handle paste even when not focused to support drag and drop.
|
|
|
|
|
if (!focus && !key.paste) {
|
2025-05-20 16:50:32 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-19 13:41:08 -07:00
|
|
|
if (key.paste) {
|
|
|
|
|
// Ensure we never accidentally interpret paste as regular input.
|
|
|
|
|
buffer.handleInput(key);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-25 15:36:42 -07:00
|
|
|
if (vimHandleInput && vimHandleInput(key)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 06:26:43 +08:00
|
|
|
// Reset ESC count and hide prompt on any non-ESC key
|
|
|
|
|
if (key.name !== 'escape') {
|
|
|
|
|
if (escPressCount > 0 || showEscapePrompt) {
|
|
|
|
|
resetEscapeState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-07 16:45:44 -04:00
|
|
|
if (
|
|
|
|
|
key.sequence === '!' &&
|
|
|
|
|
buffer.text === '' &&
|
|
|
|
|
!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-07-07 16:45:44 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.ESCAPE](key)) {
|
2025-08-04 00:53:24 +05:00
|
|
|
if (reverseSearchActive) {
|
|
|
|
|
setReverseSearchActive(false);
|
|
|
|
|
reverseSearchCompletion.resetCompletionState();
|
|
|
|
|
buffer.setText(textBeforeReverseSearch);
|
|
|
|
|
const offset = logicalPosToOffset(
|
|
|
|
|
buffer.lines,
|
|
|
|
|
cursorPosition[0],
|
|
|
|
|
cursorPosition[1],
|
|
|
|
|
);
|
|
|
|
|
buffer.moveToOffset(offset);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-07-07 16:45:44 -04:00
|
|
|
if (shellModeActive) {
|
|
|
|
|
setShellModeActive(false);
|
2025-08-10 06:26:43 +08:00
|
|
|
resetEscapeState();
|
2025-07-07 16:45:44 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (completion.showSuggestions) {
|
|
|
|
|
completion.resetCompletionState();
|
2025-08-10 06:26:43 +08:00
|
|
|
resetEscapeState();
|
2025-07-07 16:45:44 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2025-08-10 06:26:43 +08:00
|
|
|
|
|
|
|
|
// Handle double ESC for clearing input
|
|
|
|
|
if (escPressCount === 0) {
|
|
|
|
|
if (buffer.text === '') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setEscPressCount(1);
|
|
|
|
|
setShowEscapePrompt(true);
|
|
|
|
|
if (escapeTimerRef.current) {
|
|
|
|
|
clearTimeout(escapeTimerRef.current);
|
|
|
|
|
}
|
|
|
|
|
escapeTimerRef.current = setTimeout(() => {
|
|
|
|
|
resetEscapeState();
|
|
|
|
|
}, 500);
|
|
|
|
|
} else {
|
|
|
|
|
// clear input and immediately reset state
|
|
|
|
|
buffer.setText('');
|
|
|
|
|
resetCompletionState();
|
|
|
|
|
resetEscapeState();
|
|
|
|
|
}
|
|
|
|
|
return;
|
2025-07-07 16:45:44 -04:00
|
|
|
}
|
|
|
|
|
|
2025-08-09 16:03:17 +09:00
|
|
|
if (shellModeActive && keyMatchers[Command.REVERSE_SEARCH](key)) {
|
2025-08-04 00:53:24 +05:00
|
|
|
setReverseSearchActive(true);
|
|
|
|
|
setTextBeforeReverseSearch(buffer.text);
|
|
|
|
|
setCursorPosition(buffer.cursor);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.CLEAR_SCREEN](key)) {
|
2025-07-07 16:45:44 -04:00
|
|
|
onClearScreen();
|
|
|
|
|
return;
|
2025-05-18 01:18:32 -07:00
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
|
2025-08-04 00:53:24 +05:00
|
|
|
if (reverseSearchActive) {
|
|
|
|
|
const {
|
|
|
|
|
activeSuggestionIndex,
|
|
|
|
|
navigateUp,
|
|
|
|
|
navigateDown,
|
|
|
|
|
showSuggestions,
|
|
|
|
|
suggestions,
|
|
|
|
|
} = reverseSearchCompletion;
|
|
|
|
|
|
|
|
|
|
if (showSuggestions) {
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.NAVIGATION_UP](key)) {
|
2025-08-04 00:53:24 +05:00
|
|
|
navigateUp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.NAVIGATION_DOWN](key)) {
|
2025-08-04 00:53:24 +05:00
|
|
|
navigateDown();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.ACCEPT_SUGGESTION_REVERSE_SEARCH](key)) {
|
2025-08-04 00:53:24 +05:00
|
|
|
reverseSearchCompletion.handleAutocomplete(activeSuggestionIndex);
|
|
|
|
|
reverseSearchCompletion.resetCompletionState();
|
|
|
|
|
setReverseSearchActive(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.SUBMIT_REVERSE_SEARCH](key)) {
|
2025-08-04 00:53:24 +05:00
|
|
|
const textToSubmit =
|
|
|
|
|
showSuggestions && activeSuggestionIndex > -1
|
|
|
|
|
? suggestions[activeSuggestionIndex].value
|
|
|
|
|
: buffer.text;
|
|
|
|
|
handleSubmitAndClear(textToSubmit);
|
|
|
|
|
reverseSearchCompletion.resetCompletionState();
|
|
|
|
|
setReverseSearchActive(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prevent up/down from falling through to regular history navigation
|
2025-08-09 16:03:17 +09:00
|
|
|
if (
|
|
|
|
|
keyMatchers[Command.NAVIGATION_UP](key) ||
|
|
|
|
|
keyMatchers[Command.NAVIGATION_DOWN](key)
|
|
|
|
|
) {
|
2025-08-04 00:53:24 +05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-18 00:55:29 -04:00
|
|
|
// If the command is a perfect match, pressing enter should execute it.
|
2025-08-09 16:03:17 +09:00
|
|
|
if (completion.isPerfectMatch && keyMatchers[Command.RETURN](key)) {
|
2025-07-18 00:55:29 -04:00
|
|
|
handleSubmitAndClear(buffer.text);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-20 16:50:32 -07:00
|
|
|
if (completion.showSuggestions) {
|
2025-07-18 01:30:39 +03:00
|
|
|
if (completion.suggestions.length > 1) {
|
2025-08-10 07:28:28 +09:00
|
|
|
if (keyMatchers[Command.COMPLETION_UP](key)) {
|
2025-07-18 01:30:39 +03:00
|
|
|
completion.navigateUp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-10 07:28:28 +09:00
|
|
|
if (keyMatchers[Command.COMPLETION_DOWN](key)) {
|
2025-07-18 01:30:39 +03:00
|
|
|
completion.navigateDown();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
}
|
2025-07-07 16:45:44 -04:00
|
|
|
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.ACCEPT_SUGGESTION](key)) {
|
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
|
2025-07-07 16:45:44 -04:00
|
|
|
? 0 // Default to the first if none is active
|
2025-05-20 16:50:32 -07:00
|
|
|
: completion.activeSuggestionIndex;
|
|
|
|
|
if (targetIndex < completion.suggestions.length) {
|
2025-07-24 21:41:35 -07:00
|
|
|
completion.handleAutocomplete(targetIndex);
|
2025-05-07 12:30:32 -07:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2025-07-18 01:30:39 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-21 16:04:04 +08:00
|
|
|
// Handle Tab key for ghost text acceptance
|
|
|
|
|
if (
|
|
|
|
|
key.name === 'tab' &&
|
|
|
|
|
!completion.showSuggestions &&
|
|
|
|
|
completion.promptCompletion.text
|
|
|
|
|
) {
|
|
|
|
|
completion.promptCompletion.accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-18 01:30:39 +03:00
|
|
|
if (!shellModeActive) {
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.HISTORY_UP](key)) {
|
2025-07-18 01:30:39 +03:00
|
|
|
inputHistory.navigateUp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.HISTORY_DOWN](key)) {
|
2025-07-18 01:30:39 +03:00
|
|
|
inputHistory.navigateDown();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Handle arrow-up/down for history on single-line or at edges
|
|
|
|
|
if (
|
2025-08-09 16:03:17 +09:00
|
|
|
keyMatchers[Command.NAVIGATION_UP](key) &&
|
2025-07-18 01:30:39 +03:00
|
|
|
(buffer.allVisualLines.length === 1 ||
|
|
|
|
|
(buffer.visualCursor[0] === 0 && buffer.visualScrollRow === 0))
|
|
|
|
|
) {
|
|
|
|
|
inputHistory.navigateUp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (
|
2025-08-09 16:03:17 +09:00
|
|
|
keyMatchers[Command.NAVIGATION_DOWN](key) &&
|
2025-07-18 01:30:39 +03:00
|
|
|
(buffer.allVisualLines.length === 1 ||
|
|
|
|
|
buffer.visualCursor[0] === buffer.allVisualLines.length - 1)
|
|
|
|
|
) {
|
|
|
|
|
inputHistory.navigateDown();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-14 17:33:37 -07:00
|
|
|
} else {
|
2025-08-09 16:03:17 +09:00
|
|
|
// Shell History Navigation
|
|
|
|
|
if (keyMatchers[Command.NAVIGATION_UP](key)) {
|
2025-07-18 01:30:39 +03:00
|
|
|
const prevCommand = shellHistory.getPreviousCommand();
|
|
|
|
|
if (prevCommand !== null) buffer.setText(prevCommand);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.NAVIGATION_DOWN](key)) {
|
2025-07-18 01:30:39 +03:00
|
|
|
const nextCommand = shellHistory.getNextCommand();
|
|
|
|
|
if (nextCommand !== null) buffer.setText(nextCommand);
|
|
|
|
|
return;
|
2025-07-07 16:45:44 -04:00
|
|
|
}
|
2025-07-18 01:30:39 +03:00
|
|
|
}
|
2025-08-09 16:03:17 +09:00
|
|
|
|
|
|
|
|
if (keyMatchers[Command.SUBMIT](key)) {
|
2025-07-18 01:30:39 +03:00
|
|
|
if (buffer.text.trim()) {
|
|
|
|
|
const [row, col] = buffer.cursor;
|
|
|
|
|
const line = buffer.lines[row];
|
|
|
|
|
const charBefore = col > 0 ? cpSlice(line, col - 1, col) : '';
|
|
|
|
|
if (charBefore === '\\') {
|
|
|
|
|
buffer.backspace();
|
|
|
|
|
buffer.newline();
|
|
|
|
|
} else {
|
|
|
|
|
handleSubmitAndClear(buffer.text);
|
2025-07-07 16:45:44 -04:00
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
}
|
2025-07-18 01:30:39 +03:00
|
|
|
return;
|
2025-05-20 16:50:32 -07:00
|
|
|
}
|
|
|
|
|
|
2025-07-07 16:45:44 -04:00
|
|
|
// Newline insertion
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.NEWLINE](key)) {
|
2025-07-07 16:45:44 -04:00
|
|
|
buffer.newline();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ctrl+A (Home) / Ctrl+E (End)
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.HOME](key)) {
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.move('home');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.END](key)) {
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.move('end');
|
2025-07-16 00:35:58 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Ctrl+C (Clear input)
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.CLEAR_INPUT](key)) {
|
2025-07-16 00:35:58 -03:00
|
|
|
if (buffer.text.length > 0) {
|
|
|
|
|
buffer.setText('');
|
|
|
|
|
resetCompletionState();
|
|
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-07 16:45:44 -04:00
|
|
|
// Kill line commands
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.KILL_LINE_RIGHT](key)) {
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.killLineRight();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.KILL_LINE_LEFT](key)) {
|
2025-05-20 16:50:32 -07:00
|
|
|
buffer.killLineLeft();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-07 16:45:44 -04:00
|
|
|
// External editor
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.OPEN_EXTERNAL_EDITOR](key)) {
|
2025-07-07 16:45:44 -04:00
|
|
|
buffer.openInExternalEditor();
|
2025-05-20 16:50:32 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-12 00:06:49 -04:00
|
|
|
// Ctrl+V for clipboard image paste
|
2025-08-09 16:03:17 +09:00
|
|
|
if (keyMatchers[Command.PASTE_CLIPBOARD_IMAGE](key)) {
|
2025-07-12 00:06:49 -04:00
|
|
|
handleClipboardImage();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-21 17:54:44 -04:00
|
|
|
// Fall back to the text buffer's default input handling for all other keys
|
2025-06-27 10:57:32 -07:00
|
|
|
buffer.handleInput(key);
|
2025-08-21 16:04:04 +08:00
|
|
|
|
|
|
|
|
// Clear ghost text when user types regular characters (not navigation/control keys)
|
|
|
|
|
if (
|
|
|
|
|
completion.promptCompletion.text &&
|
|
|
|
|
key.sequence &&
|
|
|
|
|
key.sequence.length === 1 &&
|
|
|
|
|
!key.ctrl &&
|
|
|
|
|
!key.meta
|
|
|
|
|
) {
|
|
|
|
|
completion.promptCompletion.clear();
|
|
|
|
|
}
|
2025-04-19 19:45:42 +01:00
|
|
|
},
|
2025-06-27 10:57:32 -07:00
|
|
|
[
|
|
|
|
|
focus,
|
|
|
|
|
buffer,
|
|
|
|
|
completion,
|
|
|
|
|
shellModeActive,
|
|
|
|
|
setShellModeActive,
|
|
|
|
|
onClearScreen,
|
|
|
|
|
inputHistory,
|
|
|
|
|
handleSubmitAndClear,
|
|
|
|
|
shellHistory,
|
2025-08-04 00:53:24 +05:00
|
|
|
reverseSearchCompletion,
|
2025-07-12 00:06:49 -04:00
|
|
|
handleClipboardImage,
|
2025-07-16 00:35:58 -03:00
|
|
|
resetCompletionState,
|
2025-08-10 06:26:43 +08:00
|
|
|
escPressCount,
|
|
|
|
|
showEscapePrompt,
|
|
|
|
|
resetEscapeState,
|
2025-07-25 15:36:42 -07:00
|
|
|
vimHandleInput,
|
2025-08-04 00:53:24 +05:00
|
|
|
reverseSearchActive,
|
|
|
|
|
textBeforeReverseSearch,
|
|
|
|
|
cursorPosition,
|
2025-06-27 10:57:32 -07:00
|
|
|
],
|
2025-04-19 19:45:42 +01:00
|
|
|
);
|
2025-04-18 17:06:16 +01:00
|
|
|
|
2025-08-13 13:32:54 -04:00
|
|
|
useKeypress(handleInput, {
|
|
|
|
|
isActive: true,
|
|
|
|
|
});
|
2025-06-27 10:57:32 -07:00
|
|
|
|
2025-05-20 16:50:32 -07:00
|
|
|
const linesToRender = buffer.viewportVisualLines;
|
|
|
|
|
const [cursorVisualRowAbsolute, cursorVisualColAbsolute] =
|
|
|
|
|
buffer.visualCursor;
|
|
|
|
|
const scrollVisualRow = buffer.visualScrollRow;
|
|
|
|
|
|
2025-08-21 16:04:04 +08:00
|
|
|
const getGhostTextLines = useCallback(() => {
|
|
|
|
|
if (
|
|
|
|
|
!completion.promptCompletion.text ||
|
|
|
|
|
!buffer.text ||
|
|
|
|
|
!completion.promptCompletion.text.startsWith(buffer.text)
|
|
|
|
|
) {
|
|
|
|
|
return { inlineGhost: '', additionalLines: [] };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ghostSuffix = completion.promptCompletion.text.slice(
|
|
|
|
|
buffer.text.length,
|
|
|
|
|
);
|
|
|
|
|
if (!ghostSuffix) {
|
|
|
|
|
return { inlineGhost: '', additionalLines: [] };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const currentLogicalLine = buffer.lines[buffer.cursor[0]] || '';
|
|
|
|
|
const cursorCol = buffer.cursor[1];
|
|
|
|
|
|
|
|
|
|
const textBeforeCursor = cpSlice(currentLogicalLine, 0, cursorCol);
|
|
|
|
|
const usedWidth = stringWidth(textBeforeCursor);
|
|
|
|
|
const remainingWidth = Math.max(0, inputWidth - usedWidth);
|
|
|
|
|
|
|
|
|
|
const ghostTextLinesRaw = ghostSuffix.split('\n');
|
|
|
|
|
const firstLineRaw = ghostTextLinesRaw.shift() || '';
|
|
|
|
|
|
|
|
|
|
let inlineGhost = '';
|
|
|
|
|
let remainingFirstLine = '';
|
|
|
|
|
|
|
|
|
|
if (stringWidth(firstLineRaw) <= remainingWidth) {
|
|
|
|
|
inlineGhost = firstLineRaw;
|
|
|
|
|
} else {
|
|
|
|
|
const words = firstLineRaw.split(' ');
|
|
|
|
|
let currentLine = '';
|
|
|
|
|
let wordIdx = 0;
|
|
|
|
|
for (const word of words) {
|
|
|
|
|
const prospectiveLine = currentLine ? `${currentLine} ${word}` : word;
|
|
|
|
|
if (stringWidth(prospectiveLine) > remainingWidth) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
currentLine = prospectiveLine;
|
|
|
|
|
wordIdx++;
|
|
|
|
|
}
|
|
|
|
|
inlineGhost = currentLine;
|
|
|
|
|
if (words.length > wordIdx) {
|
|
|
|
|
remainingFirstLine = words.slice(wordIdx).join(' ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const linesToWrap = [];
|
|
|
|
|
if (remainingFirstLine) {
|
|
|
|
|
linesToWrap.push(remainingFirstLine);
|
|
|
|
|
}
|
|
|
|
|
linesToWrap.push(...ghostTextLinesRaw);
|
|
|
|
|
const remainingGhostText = linesToWrap.join('\n');
|
|
|
|
|
|
|
|
|
|
const additionalLines: string[] = [];
|
|
|
|
|
if (remainingGhostText) {
|
|
|
|
|
const textLines = remainingGhostText.split('\n');
|
|
|
|
|
for (const textLine of textLines) {
|
|
|
|
|
const words = textLine.split(' ');
|
|
|
|
|
let currentLine = '';
|
|
|
|
|
|
|
|
|
|
for (const word of words) {
|
|
|
|
|
const prospectiveLine = currentLine ? `${currentLine} ${word}` : word;
|
|
|
|
|
const prospectiveWidth = stringWidth(prospectiveLine);
|
|
|
|
|
|
|
|
|
|
if (prospectiveWidth > inputWidth) {
|
|
|
|
|
if (currentLine) {
|
|
|
|
|
additionalLines.push(currentLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let wordToProcess = word;
|
|
|
|
|
while (stringWidth(wordToProcess) > inputWidth) {
|
|
|
|
|
let part = '';
|
|
|
|
|
const wordCP = toCodePoints(wordToProcess);
|
|
|
|
|
let partWidth = 0;
|
|
|
|
|
let splitIndex = 0;
|
|
|
|
|
for (let i = 0; i < wordCP.length; i++) {
|
|
|
|
|
const char = wordCP[i];
|
|
|
|
|
const charWidth = stringWidth(char);
|
|
|
|
|
if (partWidth + charWidth > inputWidth) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
part += char;
|
|
|
|
|
partWidth += charWidth;
|
|
|
|
|
splitIndex = i + 1;
|
|
|
|
|
}
|
|
|
|
|
additionalLines.push(part);
|
|
|
|
|
wordToProcess = cpSlice(wordToProcess, splitIndex);
|
|
|
|
|
}
|
|
|
|
|
currentLine = wordToProcess;
|
|
|
|
|
} else {
|
|
|
|
|
currentLine = prospectiveLine;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (currentLine) {
|
|
|
|
|
additionalLines.push(currentLine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { inlineGhost, additionalLines };
|
|
|
|
|
}, [
|
|
|
|
|
completion.promptCompletion.text,
|
|
|
|
|
buffer.text,
|
|
|
|
|
buffer.lines,
|
|
|
|
|
buffer.cursor,
|
|
|
|
|
inputWidth,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const { inlineGhost, additionalLines } = getGhostTextLines();
|
|
|
|
|
|
2025-04-17 18:06:21 -04:00
|
|
|
return (
|
2025-05-20 16:50:32 -07:00
|
|
|
<>
|
|
|
|
|
<Box
|
|
|
|
|
borderStyle="round"
|
2025-08-07 16:11:35 -07:00
|
|
|
borderColor={
|
|
|
|
|
shellModeActive ? theme.status.warning : theme.border.focused
|
|
|
|
|
}
|
2025-05-20 16:50:32 -07:00
|
|
|
paddingX={1}
|
|
|
|
|
>
|
|
|
|
|
<Text
|
2025-08-07 16:11:35 -07:00
|
|
|
color={shellModeActive ? theme.status.warning : theme.text.accent}
|
2025-05-20 16:50:32 -07:00
|
|
|
>
|
2025-08-04 00:53:24 +05:00
|
|
|
{shellModeActive ? (
|
|
|
|
|
reverseSearchActive ? (
|
2025-08-21 22:29:15 +00:00
|
|
|
<Text
|
|
|
|
|
color={theme.text.link}
|
|
|
|
|
aria-label={SCREEN_READER_USER_PREFIX}
|
|
|
|
|
>
|
|
|
|
|
(r:){' '}
|
|
|
|
|
</Text>
|
2025-08-04 00:53:24 +05:00
|
|
|
) : (
|
|
|
|
|
'! '
|
|
|
|
|
)
|
|
|
|
|
) : (
|
|
|
|
|
'> '
|
|
|
|
|
)}
|
2025-05-20 16:50:32 -07:00
|
|
|
</Text>
|
|
|
|
|
<Box flexGrow={1} flexDirection="column">
|
|
|
|
|
{buffer.text.length === 0 && placeholder ? (
|
2025-06-06 13:44:11 -07:00
|
|
|
focus ? (
|
2025-08-15 20:18:31 -07:00
|
|
|
<Text>
|
2025-06-06 13:44:11 -07:00
|
|
|
{chalk.inverse(placeholder.slice(0, 1))}
|
2025-08-07 16:11:35 -07:00
|
|
|
<Text color={theme.text.secondary}>{placeholder.slice(1)}</Text>
|
2025-06-06 13:44:11 -07:00
|
|
|
</Text>
|
|
|
|
|
) : (
|
2025-08-07 16:11:35 -07:00
|
|
|
<Text color={theme.text.secondary}>{placeholder}</Text>
|
2025-06-06 13:44:11 -07:00
|
|
|
)
|
2025-05-20 16:50:32 -07:00
|
|
|
) : (
|
2025-08-21 16:04:04 +08:00
|
|
|
linesToRender
|
|
|
|
|
.map((lineText, visualIdxInRenderedSet) => {
|
2025-09-02 09:21:55 -07:00
|
|
|
const tokens = parseInputForHighlighting(lineText);
|
2025-08-21 16:04:04 +08:00
|
|
|
const cursorVisualRow =
|
|
|
|
|
cursorVisualRowAbsolute - scrollVisualRow;
|
|
|
|
|
const isOnCursorLine =
|
|
|
|
|
focus && visualIdxInRenderedSet === cursorVisualRow;
|
|
|
|
|
|
2025-09-02 09:21:55 -07:00
|
|
|
const renderedLine: React.ReactNode[] = [];
|
|
|
|
|
let charCount = 0;
|
2025-08-21 16:04:04 +08:00
|
|
|
|
2025-09-02 09:21:55 -07:00
|
|
|
tokens.forEach((token, tokenIdx) => {
|
|
|
|
|
let display = token.text;
|
|
|
|
|
if (isOnCursorLine) {
|
|
|
|
|
const relativeVisualColForHighlight =
|
|
|
|
|
cursorVisualColAbsolute;
|
|
|
|
|
const tokenStart = charCount;
|
|
|
|
|
const tokenEnd = tokenStart + cpLen(token.text);
|
2025-08-21 16:04:04 +08:00
|
|
|
|
2025-09-02 09:21:55 -07:00
|
|
|
if (
|
|
|
|
|
relativeVisualColForHighlight >= tokenStart &&
|
|
|
|
|
relativeVisualColForHighlight < tokenEnd
|
|
|
|
|
) {
|
|
|
|
|
const charToHighlight = cpSlice(
|
|
|
|
|
token.text,
|
|
|
|
|
relativeVisualColForHighlight - tokenStart,
|
|
|
|
|
relativeVisualColForHighlight - tokenStart + 1,
|
|
|
|
|
);
|
2025-08-21 16:04:04 +08:00
|
|
|
const highlighted = chalk.inverse(charToHighlight);
|
|
|
|
|
display =
|
2025-09-02 09:21:55 -07:00
|
|
|
cpSlice(
|
|
|
|
|
token.text,
|
|
|
|
|
0,
|
|
|
|
|
relativeVisualColForHighlight - tokenStart,
|
|
|
|
|
) +
|
2025-08-21 16:04:04 +08:00
|
|
|
highlighted +
|
2025-09-02 09:21:55 -07:00
|
|
|
cpSlice(
|
|
|
|
|
token.text,
|
|
|
|
|
relativeVisualColForHighlight - tokenStart + 1,
|
|
|
|
|
);
|
2025-08-21 16:04:04 +08:00
|
|
|
}
|
2025-09-02 09:21:55 -07:00
|
|
|
charCount = tokenEnd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const color =
|
|
|
|
|
token.type === 'command' || token.type === 'file'
|
|
|
|
|
? theme.text.accent
|
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
|
|
renderedLine.push(
|
|
|
|
|
<Text key={`token-${tokenIdx}`} color={color}>
|
|
|
|
|
{display}
|
|
|
|
|
</Text>,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
const currentLineGhost = isOnCursorLine ? inlineGhost : '';
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
isOnCursorLine &&
|
|
|
|
|
cursorVisualColAbsolute === cpLen(lineText)
|
|
|
|
|
) {
|
|
|
|
|
if (!currentLineGhost) {
|
|
|
|
|
renderedLine.push(
|
|
|
|
|
<Text key="cursor-end">{chalk.inverse(' ')}</Text>,
|
|
|
|
|
);
|
2025-05-20 16:50:32 -07:00
|
|
|
}
|
|
|
|
|
}
|
2025-08-21 16:04:04 +08:00
|
|
|
|
|
|
|
|
const showCursorBeforeGhost =
|
|
|
|
|
focus &&
|
2025-09-02 09:21:55 -07:00
|
|
|
isOnCursorLine &&
|
|
|
|
|
cursorVisualColAbsolute === cpLen(lineText) &&
|
2025-08-21 16:04:04 +08:00
|
|
|
currentLineGhost;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Text key={`line-${visualIdxInRenderedSet}`}>
|
2025-09-02 09:21:55 -07:00
|
|
|
{renderedLine}
|
2025-08-21 16:04:04 +08:00
|
|
|
{showCursorBeforeGhost && chalk.inverse(' ')}
|
|
|
|
|
{currentLineGhost && (
|
|
|
|
|
<Text color={theme.text.secondary}>
|
|
|
|
|
{currentLineGhost}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
</Text>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
.concat(
|
|
|
|
|
additionalLines.map((ghostLine, index) => {
|
|
|
|
|
const padding = Math.max(
|
|
|
|
|
0,
|
|
|
|
|
inputWidth - stringWidth(ghostLine),
|
|
|
|
|
);
|
|
|
|
|
return (
|
|
|
|
|
<Text
|
|
|
|
|
key={`ghost-line-${index}`}
|
|
|
|
|
color={theme.text.secondary}
|
|
|
|
|
>
|
|
|
|
|
{ghostLine}
|
|
|
|
|
{' '.repeat(padding)}
|
|
|
|
|
</Text>
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
)
|
2025-05-20 16:50:32 -07:00
|
|
|
)}
|
|
|
|
|
</Box>
|
2025-04-19 12:38:09 -04:00
|
|
|
</Box>
|
2025-05-20 16:50:32 -07:00
|
|
|
{completion.showSuggestions && (
|
2025-08-07 15:55:53 -07:00
|
|
|
<Box paddingRight={2}>
|
2025-05-20 16:50:32 -07:00
|
|
|
<SuggestionsDisplay
|
|
|
|
|
suggestions={completion.suggestions}
|
|
|
|
|
activeIndex={completion.activeSuggestionIndex}
|
|
|
|
|
isLoading={completion.isLoadingSuggestions}
|
|
|
|
|
width={suggestionsWidth}
|
|
|
|
|
scrollOffset={completion.visibleStartIndex}
|
|
|
|
|
userInput={buffer.text}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
2025-08-04 00:53:24 +05:00
|
|
|
{reverseSearchActive && (
|
2025-08-07 15:55:53 -07:00
|
|
|
<Box paddingRight={2}>
|
2025-08-04 00:53:24 +05:00
|
|
|
<SuggestionsDisplay
|
|
|
|
|
suggestions={reverseSearchCompletion.suggestions}
|
|
|
|
|
activeIndex={reverseSearchCompletion.activeSuggestionIndex}
|
|
|
|
|
isLoading={reverseSearchCompletion.isLoadingSuggestions}
|
|
|
|
|
width={suggestionsWidth}
|
|
|
|
|
scrollOffset={reverseSearchCompletion.visibleStartIndex}
|
|
|
|
|
userInput={buffer.text}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
2025-05-20 16:50:32 -07:00
|
|
|
</>
|
2025-04-17 18:06:21 -04:00
|
|
|
);
|
2025-04-18 18:08:43 -04:00
|
|
|
};
|