mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Fix user input commands being echoed twice in terminal (#9959)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
parent
b67db15f8a
commit
e348634dbd
@ -22,8 +22,18 @@ const DEFAULT_TERMINAL_CONFIG: UseTerminalConfig = {
|
||||
commands: [],
|
||||
};
|
||||
|
||||
const renderCommand = (command: Command, terminal: Terminal) => {
|
||||
const { content } = command;
|
||||
const renderCommand = (
|
||||
command: Command,
|
||||
terminal: Terminal,
|
||||
isUserInput: boolean = false,
|
||||
) => {
|
||||
const { content, type } = command;
|
||||
|
||||
// Skip rendering user input commands that come from the event stream
|
||||
// as they've already been displayed in the terminal as the user typed
|
||||
if (type === "input" && isUserInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
terminal.writeln(
|
||||
parseTerminalOutput(content.replaceAll("\n", "\r\n").trim()),
|
||||
@ -123,7 +133,9 @@ export const useTerminal = ({
|
||||
if (commands[i].type === "input") {
|
||||
terminal.current.write("$ ");
|
||||
}
|
||||
renderCommand(commands[i], terminal.current);
|
||||
// Don't pass isUserInput=true here because we're initializing the terminal
|
||||
// and need to show all previous commands
|
||||
renderCommand(commands[i], terminal.current, false);
|
||||
}
|
||||
lastCommandIndex.current = commands.length;
|
||||
}
|
||||
@ -144,7 +156,9 @@ export const useTerminal = ({
|
||||
let lastCommandType = "";
|
||||
for (let i = lastCommandIndex.current; i < commands.length; i += 1) {
|
||||
lastCommandType = commands[i].type;
|
||||
renderCommand(commands[i], terminal.current);
|
||||
// Pass true for isUserInput to skip rendering user input commands
|
||||
// that have already been displayed as the user typed
|
||||
renderCommand(commands[i], terminal.current, true);
|
||||
}
|
||||
lastCommandIndex.current = commands.length;
|
||||
if (lastCommandType === "output") {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user