|
| 1 | +import React, { useState } from "react" |
| 2 | +import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react" |
| 3 | +import { useExtensionState } from "@/context/ExtensionStateContext" |
| 4 | +import { vscode } from "@/utils/vscode" |
| 5 | + |
| 6 | +export const TerminalSettingsSection: React.FC = () => { |
| 7 | + const { shellIntegrationTimeout, setShellIntegrationTimeout } = useExtensionState() |
| 8 | + const [inputValue, setInputValue] = useState((shellIntegrationTimeout / 1000).toString()) |
| 9 | + const [inputError, setInputError] = useState<string | null>(null) |
| 10 | + |
| 11 | + const handleTimeoutChange = (event: Event) => { |
| 12 | + const target = event.target as HTMLInputElement |
| 13 | + const value = target.value |
| 14 | + |
| 15 | + setInputValue(value) |
| 16 | + |
| 17 | + const seconds = parseFloat(value) |
| 18 | + if (isNaN(seconds) || seconds <= 0) { |
| 19 | + setInputError("Please enter a positive number") |
| 20 | + return |
| 21 | + } |
| 22 | + |
| 23 | + setInputError(null) |
| 24 | + const timeout = Math.round(seconds * 1000) // Convert to milliseconds |
| 25 | + |
| 26 | + // Update local state |
| 27 | + setShellIntegrationTimeout(timeout) |
| 28 | + |
| 29 | + // Send to extension |
| 30 | + vscode.postMessage({ |
| 31 | + type: "updateTerminalConnectionTimeout", |
| 32 | + shellIntegrationTimeout: timeout, |
| 33 | + }) |
| 34 | + } |
| 35 | + |
| 36 | + const handleInputBlur = () => { |
| 37 | + // If there was an error, reset the input to the current valid value |
| 38 | + if (inputError) { |
| 39 | + setInputValue((shellIntegrationTimeout / 1000).toString()) |
| 40 | + setInputError(null) |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + return ( |
| 45 | + <div |
| 46 | + id="terminal-settings-section" |
| 47 | + style={{ marginBottom: 20, borderTop: "1px solid var(--vscode-panel-border)", paddingTop: 15 }}> |
| 48 | + <h3 style={{ color: "var(--vscode-foreground)", margin: "0 0 10px 0", fontSize: "14px" }}>Terminal Settings</h3> |
| 49 | + <div style={{ marginBottom: 15 }}> |
| 50 | + <div style={{ marginBottom: 8 }}> |
| 51 | + <label style={{ fontWeight: "500", display: "block", marginBottom: 5 }}> |
| 52 | + Shell integration timeout (seconds) |
| 53 | + </label> |
| 54 | + <div style={{ display: "flex", alignItems: "center" }}> |
| 55 | + <VSCodeTextField |
| 56 | + style={{ width: "100%" }} |
| 57 | + value={inputValue} |
| 58 | + placeholder="Enter timeout in seconds" |
| 59 | + onChange={(event) => handleTimeoutChange(event as Event)} |
| 60 | + onBlur={handleInputBlur} |
| 61 | + /> |
| 62 | + </div> |
| 63 | + {inputError && ( |
| 64 | + <div style={{ color: "var(--vscode-errorForeground)", fontSize: "12px", marginTop: 5 }}>{inputError}</div> |
| 65 | + )} |
| 66 | + </div> |
| 67 | + <p style={{ fontSize: "12px", color: "var(--vscode-descriptionForeground)", margin: 0 }}> |
| 68 | + Set how long Cline waits for shell integration to activate before executing commands. Increase this value if |
| 69 | + you experience terminal connection timeouts. |
| 70 | + </p> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + ) |
| 74 | +} |
| 75 | + |
| 76 | +export default TerminalSettingsSection |
0 commit comments