2025-09-11 13:27:27 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { useCallback } from 'react';
|
|
|
|
|
import type React from 'react';
|
|
|
|
|
import { useKeypress } from '../hooks/useKeypress.js';
|
|
|
|
|
import { ShellExecutionService } from '@google/gemini-cli-core';
|
|
|
|
|
import { keyToAnsi, type Key } from '../hooks/keyToAnsi.js';
|
2026-01-30 09:53:09 -08:00
|
|
|
import { Command, keyMatchers } from '../keyMatchers.js';
|
2025-09-11 13:27:27 -07:00
|
|
|
|
|
|
|
|
export interface ShellInputPromptProps {
|
|
|
|
|
activeShellPtyId: number | null;
|
|
|
|
|
focus?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const ShellInputPrompt: React.FC<ShellInputPromptProps> = ({
|
|
|
|
|
activeShellPtyId,
|
|
|
|
|
focus = true,
|
|
|
|
|
}) => {
|
|
|
|
|
const handleShellInputSubmit = useCallback(
|
|
|
|
|
(input: string) => {
|
|
|
|
|
if (activeShellPtyId) {
|
|
|
|
|
ShellExecutionService.writeToPty(activeShellPtyId, input);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[activeShellPtyId],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const handleInput = useCallback(
|
|
|
|
|
(key: Key) => {
|
|
|
|
|
if (!focus || !activeShellPtyId) {
|
2026-01-30 09:53:09 -08:00
|
|
|
return false;
|
2025-09-11 13:27:27 -07:00
|
|
|
}
|
2026-01-30 09:53:09 -08:00
|
|
|
|
|
|
|
|
// Allow background shell toggle to bubble up
|
|
|
|
|
if (keyMatchers[Command.TOGGLE_BACKGROUND_SHELL](key)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-06 10:36:14 -08:00
|
|
|
// Allow unfocus to bubble up
|
|
|
|
|
if (keyMatchers[Command.UNFOCUS_SHELL_INPUT](key)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-11 13:27:27 -07:00
|
|
|
if (key.ctrl && key.shift && key.name === 'up') {
|
|
|
|
|
ShellExecutionService.scrollPty(activeShellPtyId, -1);
|
2026-01-30 09:53:09 -08:00
|
|
|
return true;
|
2025-09-11 13:27:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (key.ctrl && key.shift && key.name === 'down') {
|
|
|
|
|
ShellExecutionService.scrollPty(activeShellPtyId, 1);
|
2026-01-30 09:53:09 -08:00
|
|
|
return true;
|
2025-09-11 13:27:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ansiSequence = keyToAnsi(key);
|
|
|
|
|
if (ansiSequence) {
|
|
|
|
|
handleShellInputSubmit(ansiSequence);
|
2026-01-30 09:53:09 -08:00
|
|
|
return true;
|
2025-09-11 13:27:27 -07:00
|
|
|
}
|
2026-01-30 09:53:09 -08:00
|
|
|
|
|
|
|
|
return false;
|
2025-09-11 13:27:27 -07:00
|
|
|
},
|
|
|
|
|
[focus, handleShellInputSubmit, activeShellPtyId],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
useKeypress(handleInput, { isActive: focus });
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
};
|