Skip to content

Commit

Permalink
show/hide terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
LinceMathew committed Aug 20, 2024
1 parent 5acd77e commit 811bb6d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
11 changes: 8 additions & 3 deletions src/panels/RequestPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class Lama2Panel {
private readonly _extensionUri: vscode.Uri
private _disposables: vscode.Disposable[] = []
private rfile: string = ""
private rlog: string = ""

private constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) {
this._panel = panel
Expand Down Expand Up @@ -72,8 +73,9 @@ export class Lama2Panel {
status: "starting",
})

const { cmd, rflag, rfile } = getLama2Command()
const { cmd, rflag, rfile, rlog } = getLama2Command()

Check failure on line 76 in src/panels/RequestPanel.ts

View workflow job for this annotation

GitHub Actions / build

Property 'cmd' does not exist on type '{ cmd: string; rflag: string; rfile: string; rlog: string | null; } | null'.

Check failure on line 76 in src/panels/RequestPanel.ts

View workflow job for this annotation

GitHub Actions / build

Property 'rflag' does not exist on type '{ cmd: string; rflag: string; rfile: string; rlog: string | null; } | null'.

Check failure on line 76 in src/panels/RequestPanel.ts

View workflow job for this annotation

GitHub Actions / build

Property 'rfile' does not exist on type '{ cmd: string; rflag: string; rfile: string; rlog: string | null; } | null'.

Check failure on line 76 in src/panels/RequestPanel.ts

View workflow job for this annotation

GitHub Actions / build

Property 'rlog' does not exist on type '{ cmd: string; rflag: string; rfile: string; rlog: string | null; } | null'.
this.rfile = rfile
this.rlog = rlog
this.setLama2Watch(rflag)

// Execute command and capture output
Expand Down Expand Up @@ -159,9 +161,12 @@ export class Lama2Panel {
await vscode.workspace.fs.delete(vscode.Uri.file(output))
}
} catch (error) {
console.error("Error processing Lama2 output:", error)
console.log(this.rlog)
const stderr = await vscode.workspace.fs.readFile(vscode.Uri.file(this.rlog));
const stderrString = new TextDecoder().decode(stderr);
console.error("Error processing Lama2 output:", stderrString);
this.handleCommandError(
error instanceof Error ? error.message : "An error occurred while processing the Lama2 output"
error instanceof Error ? stderrString : "An error occurred while processing the Lama2 output"
)
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/utilities/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function getLama2Command() {
console.log('getLama2Command');
let randomNameFile: string | null = null;
let randomNameFlag: string | null = null;
let randomNameLog: string | null = null;
let cmd: string | null = null;
const windowsBasePath = 'C:\\ProgramData\\.lama2';
const randomNameBase = generateRandomName(8);
Expand All @@ -63,18 +64,18 @@ export function getLama2Command() {
} else {
randomNameFlag = `/tmp/${randomNameBase}.flag`;
randomNameFile = `/tmp/${randomNameBase}.json`;
cmd = `l2 -o ${randomNameFile} ${currentFilePath}; touch ${randomNameFlag}`;
randomNameLog = `/tmp/${randomNameBase}.log`;
cmd = `l2 -o ${randomNameFile} ${currentFilePath} 2> >(tee ${randomNameLog}); touch ${randomNameFlag}`;
}

return {
cmd: cmd,
rflag: randomNameFlag,
rfile: randomNameFile,
rlog: randomNameLog
};
} catch (error) {
console.error('Error generating Lama2 command:', error);
return null;
}
catch (error) {
console.error('Failed to generate Lama2 command', error);
throw new Error('Failed to generate Lama2 command');
}

}
26 changes: 15 additions & 11 deletions webview/src/pages/Response.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import JsonView from "@/modules/JsonView";
import HtmlView from "@/modules/HtmlView";
import Metadata from "@/modules/Metadata";
import Error from "@/modules/Error";
import { Button } from "primereact/button"

interface HeaderItem {
header: string;
value: string;
header: string
value: string
}

interface ApiMetrics {
status: string;
time: string;
size: string;
status: string
time: string
size: string
}

declare global {
Expand All @@ -41,6 +42,7 @@ const Response: React.FC = () => {
})
const [headers, setHeaders] = useState<HeaderItem[]>([])
const [error, setError] = useState<string | null>(null)
const [showTerminal, setShowTerminal] = useState<boolean>(false)

const toggleIcon = (icon: string) => {
setHighlightedIcon(icon)
Expand All @@ -67,8 +69,8 @@ const Response: React.FC = () => {

if (message.status === "starting") {
setIsLoading(true)
setError(null)
return
setError(null)
return
}

if (message.status === "error") {
Expand Down Expand Up @@ -142,18 +144,20 @@ const Response: React.FC = () => {
)
}

const toggleTerminal = () => {
vscode.postMessage({ command: "toggleTerminal" })
setShowTerminal(!showTerminal)
}

if (error) {
return (
<div className="error-container">
<Error error={error} />
<Button label={showTerminal ? "Hide Terminal" : "Show Terminal"} onClick={toggleTerminal} />
</div>
)
}

const toggleTerminal = () => {
vscode.postMessage({ command: "toggleTerminal" })
}

const responseContent = (
<>
<div className="meta-icon-section">
Expand Down
2 changes: 2 additions & 0 deletions webview/src/styles/custom-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@

.error-container {
display: flex;
flex-direction: column;
justify-content: center;
gap: 10px;
align-items: center;
width: 100vw;
position: fixed;
Expand Down

0 comments on commit 811bb6d

Please sign in to comment.