mirror of
https://github.com/voideditor/void
synced 2026-05-23 17:38:23 +00:00
add support for stopping the terminal command
This commit is contained in:
parent
e2a7b0e1a0
commit
9a905f6cb2
1 changed files with 21 additions and 3 deletions
|
|
@ -264,25 +264,30 @@ export const ApplyButtonsHTML = ({
|
|||
|
||||
const isShellLanguage = language === 'bash' || language === 'shellscript'
|
||||
|
||||
const [isShellRunning, setIsShellRunning] = useState<boolean>(false)
|
||||
const interruptToolRef = useRef<(() => void) | null>(null)
|
||||
|
||||
const onClickSubmit = useCallback(async () => {
|
||||
if (currStreamStateRef.current === 'streaming') return
|
||||
if (currStreamStateRef.current === 'streaming' || isShellRunning) return
|
||||
|
||||
// For shell scripts, run in terminal instead of applying to file
|
||||
if (isShellLanguage) {
|
||||
try {
|
||||
setIsShellRunning(true)
|
||||
// Create a terminal if none exists or use terminal 1
|
||||
const terminalIds = terminalToolService.listPersistentTerminalIds()
|
||||
let terminalId = '1';
|
||||
if (!terminalIds.includes(terminalId)) {
|
||||
terminalId = await terminalToolService.createPersistentTerminal({ cwd: null })
|
||||
}
|
||||
await terminalToolService.runCommand(
|
||||
const { interrupt } = await terminalToolService.runCommand(
|
||||
codeStr,
|
||||
{ type: 'persistent', persistentTerminalId: terminalId }
|
||||
);
|
||||
await terminalToolService.focusPersistentTerminal(terminalId)
|
||||
interruptToolRef.current = interrupt
|
||||
metricsService.capture('Execute Shell', { length: codeStr.length })
|
||||
} catch (e) {
|
||||
setIsShellRunning(false)
|
||||
console.error('Failed to execute in terminal:', e)
|
||||
}
|
||||
return;
|
||||
|
|
@ -338,6 +343,19 @@ export const ApplyButtonsHTML = ({
|
|||
const currStreamState = currStreamStateRef.current
|
||||
console.log('currStreamState...', currStreamState)
|
||||
|
||||
if (isShellRunning) {
|
||||
return (
|
||||
<IconShell1
|
||||
Icon={X}
|
||||
onClick={() => {
|
||||
interruptToolRef.current?.();
|
||||
setIsShellRunning(false);
|
||||
}}
|
||||
{...tooltipPropsForApplyBlock({ tooltipName: 'Stop' })}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (currStreamState === 'streaming') {
|
||||
return <IconShell1
|
||||
Icon={Square}
|
||||
|
|
|
|||
Loading…
Reference in a new issue