Show progress indicator while command is executing

This commit is contained in:
Saoud Rizwan
2024-07-29 18:46:23 -04:00
parent d324afdf14
commit fd0b3a18f7
3 changed files with 44 additions and 24 deletions

View File

@@ -547,7 +547,7 @@ export class ClaudeDev {
} }
} catch (e) { } catch (e) {
if ((e as ExecaError).signal === "SIGINT") { if ((e as ExecaError).signal === "SIGINT") {
const line = `\nUser exited command early...` const line = `\nUser exited command...`
await this.say("command_output", line) await this.say("command_output", line)
result += line result += line
} else { } else {

View File

@@ -12,7 +12,8 @@ interface ChatRowProps {
syntaxHighlighterStyle: SyntaxHighlighterStyle syntaxHighlighterStyle: SyntaxHighlighterStyle
isExpanded: boolean isExpanded: boolean
onToggleExpand: () => void onToggleExpand: () => void
apiRequestFailedMessage?: string lastModifiedMessage?: ClaudeMessage
isLast: boolean
} }
const ChatRow: React.FC<ChatRowProps> = ({ const ChatRow: React.FC<ChatRowProps> = ({
@@ -20,15 +21,37 @@ const ChatRow: React.FC<ChatRowProps> = ({
syntaxHighlighterStyle, syntaxHighlighterStyle,
isExpanded, isExpanded,
onToggleExpand, onToggleExpand,
apiRequestFailedMessage, lastModifiedMessage,
isLast,
}) => { }) => {
const cost = message.text != null && message.say === "api_req_started" ? JSON.parse(message.text).cost : undefined const cost = message.text != null && message.say === "api_req_started" ? JSON.parse(message.text).cost : undefined
const apiRequestFailedMessage =
isLast && lastModifiedMessage?.ask === "api_req_failed" // if request is retried then the latest message is a api_req_retried
? lastModifiedMessage?.text
: undefined
const isCommandExecuting =
isLast && lastModifiedMessage?.ask === "command" && lastModifiedMessage?.text?.includes(COMMAND_OUTPUT_STRING)
const getIconAndTitle = (type: ClaudeAsk | ClaudeSay | undefined): [JSX.Element | null, JSX.Element | null] => { const getIconAndTitle = (type: ClaudeAsk | ClaudeSay | undefined): [JSX.Element | null, JSX.Element | null] => {
const normalColor = "var(--vscode-foreground)" const normalColor = "var(--vscode-foreground)"
const errorColor = "var(--vscode-errorForeground)" const errorColor = "var(--vscode-errorForeground)"
const successColor = "var(--vscode-testing-iconPassed)" const successColor = "var(--vscode-testing-iconPassed)"
const ProgressIndicator = (
<div
style={{
width: "16px",
height: "16px",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}>
<div style={{ transform: "scale(0.55)", transformOrigin: "center" }}>
<VSCodeProgressRing />
</div>
</div>
)
switch (type) { switch (type) {
case "request_limit_reached": case "request_limit_reached":
return [ return [
@@ -46,9 +69,13 @@ const ChatRow: React.FC<ChatRowProps> = ({
] ]
case "command": case "command":
return [ return [
isCommandExecuting ? (
ProgressIndicator
) : (
<span <span
className="codicon codicon-terminal" className="codicon codicon-terminal"
style={{ color: normalColor, marginBottom: "-1.5px" }}></span>, style={{ color: normalColor, marginBottom: "-1.5px" }}></span>
),
<span style={{ color: normalColor, fontWeight: "bold" }}> <span style={{ color: normalColor, fontWeight: "bold" }}>
Claude wants to execute this command: Claude wants to execute this command:
</span>, </span>,
@@ -71,18 +98,7 @@ const ChatRow: React.FC<ChatRowProps> = ({
className="codicon codicon-error" className="codicon codicon-error"
style={{ color: errorColor, marginBottom: "-1.5px" }}></span> style={{ color: errorColor, marginBottom: "-1.5px" }}></span>
) : ( ) : (
<div ProgressIndicator
style={{
width: "16px",
height: "16px",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}>
<div style={{ transform: "scale(0.55)", transformOrigin: "center" }}>
<VSCodeProgressRing />
</div>
</div>
), ),
cost ? ( cost ? (
<span style={{ color: normalColor, fontWeight: "bold" }}>API Request Complete</span> <span style={{ color: normalColor, fontWeight: "bold" }}>API Request Complete</span>
@@ -92,6 +108,13 @@ const ChatRow: React.FC<ChatRowProps> = ({
<span style={{ color: normalColor, fontWeight: "bold" }}>Making API Request...</span> <span style={{ color: normalColor, fontWeight: "bold" }}>Making API Request...</span>
), ),
] ]
case "followup":
return [
<span
className="codicon codicon-question"
style={{ color: normalColor, marginBottom: "-1.5px" }}></span>,
<span style={{ color: normalColor, fontWeight: "bold" }}>Claude has a question:</span>,
]
default: default:
return [null, null] return [null, null]
} }

View File

@@ -112,7 +112,7 @@ const ChatView = ({ messages, isHidden, vscodeThemeName, showAnnouncement, hideA
setTextAreaDisabled(false) setTextAreaDisabled(false)
setClaudeAsk("command_output") setClaudeAsk("command_output")
setEnableButtons(true) setEnableButtons(true)
setPrimaryButtonText("Exit Command Early") setPrimaryButtonText("Exit Command")
setSecondaryButtonText(undefined) setSecondaryButtonText(undefined)
break break
case "completion_result": case "completion_result":
@@ -394,11 +394,8 @@ const ChatView = ({ messages, isHidden, vscodeThemeName, showAnnouncement, hideA
syntaxHighlighterStyle={syntaxHighlighterStyle} syntaxHighlighterStyle={syntaxHighlighterStyle}
isExpanded={expandedRows[message.ts] || false} isExpanded={expandedRows[message.ts] || false}
onToggleExpand={() => toggleRowExpansion(message.ts)} onToggleExpand={() => toggleRowExpansion(message.ts)}
apiRequestFailedMessage={ lastModifiedMessage={modifiedMessages.at(-1)}
index === visibleMessages.length - 1 && modifiedMessages.at(-1)?.ask === "api_req_failed" // if request is retried then the latest message is a api_req_retried isLast={index === visibleMessages.length - 1}
? modifiedMessages.at(-1)?.text
: undefined
}
/> />
)} )}
/> />