-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jan Lauber <[email protected]>
- Loading branch information
Showing
20 changed files
with
635 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<script lang="ts"> | ||
import { onDestroy, onMount } from "svelte"; | ||
import darkTheme from "$lib/stores/theme"; | ||
import { terminal_size } from "$lib/stores/terminal"; | ||
import { Terminal } from "xterm"; | ||
import { FitAddon } from "xterm-addon-fit"; | ||
export let podName: string; | ||
export let projectId: string; | ||
const terminal = new Terminal({ | ||
convertEol: true, | ||
disableStdin: false, | ||
cursorBlink: true, | ||
fontFamily: "monospace", | ||
fontSize: 14, | ||
theme: $darkTheme | ||
? { | ||
foreground: "#d2d2d2", | ||
background: "#2B3441", | ||
cursor: "#adadad", | ||
black: "#000000", | ||
red: "#d81e00", | ||
green: "#5ea702", | ||
yellow: "#cfae00", | ||
blue: "#427ab3", | ||
magenta: "#89658e", | ||
cyan: "#00a7aa", | ||
white: "#dbded8", | ||
brightBlack: "#686a66", | ||
brightRed: "#f54235", | ||
brightGreen: "#99e343", | ||
brightYellow: "#fdeb61", | ||
brightBlue: "#84b0d8", | ||
brightMagenta: "#bc94b7", | ||
brightCyan: "#37e6e8", | ||
brightWhite: "#f1f1f0" | ||
} | ||
: { | ||
foreground: "#d2d2d2", | ||
background: "#2B3441", | ||
cursor: "#adadad", | ||
black: "#000000", | ||
red: "#d81e00", | ||
green: "#5ea702", | ||
yellow: "#cfae00", | ||
blue: "#427ab3", | ||
magenta: "#89658e", | ||
cyan: "#00a7aa", | ||
white: "#dbded8", | ||
brightBlack: "#686a66", | ||
brightRed: "#f54235", | ||
brightGreen: "#99e343", | ||
brightYellow: "#fdeb61", | ||
brightBlue: "#84b0d8", | ||
brightMagenta: "#bc94b7", | ||
brightCyan: "#37e6e8", | ||
brightWhite: "#f1f1f0" | ||
}, | ||
scrollOnUserInput: true | ||
}); | ||
let socket: WebSocket; | ||
const fitAddon = new FitAddon(); | ||
terminal.loadAddon(fitAddon); | ||
const connectWebSocket = () => { | ||
let host = window.location.host; | ||
if (host.includes("localhost")) { | ||
host = "localhost:8090"; | ||
} | ||
const protocol = window.location.protocol === "https:" ? "wss" : "ws"; | ||
socket = new WebSocket(`${protocol}://${host}/ws/k8s/terminal`); | ||
socket.binaryType = "arraybuffer"; | ||
socket.onopen = () => { | ||
const message = JSON.stringify({ projectId, podName }); | ||
socket.send(message); | ||
terminal.onData((data) => { | ||
socket.send(new TextEncoder().encode(data)); | ||
}); | ||
}; | ||
socket.onmessage = (event: MessageEvent) => { | ||
if (event.data instanceof ArrayBuffer) { | ||
terminal.write(new TextDecoder().decode(event.data)); | ||
} | ||
}; | ||
socket.onerror = (error: Event) => { | ||
const errorMessage = (error as ErrorEvent).message || "An error occurred"; | ||
terminal.write(`\r\nWebSocket error: ${errorMessage}\r\n`); | ||
}; | ||
socket.onclose = () => { | ||
terminal.write("\r\nWebSocket closed. Attempting to reconnect...\r\n"); | ||
setTimeout(connectWebSocket, 5000); | ||
}; | ||
}; | ||
terminal.onResize((size) => { | ||
const terminal_size = { | ||
cols: size.cols, | ||
rows: size.rows, | ||
y: size.rows, | ||
x: size.cols | ||
}; | ||
if (socket.readyState === WebSocket.OPEN) { | ||
socket.send(new TextEncoder().encode("\x01" + JSON.stringify(terminal_size))); | ||
} | ||
}); | ||
let div: HTMLDivElement; | ||
onMount(() => { | ||
connectWebSocket(); | ||
terminal.open(div); | ||
setTimeout(() => { | ||
fitAddon.fit(); | ||
}, 300); | ||
}); | ||
onDestroy(() => { | ||
socket?.close(); | ||
terminal.dispose(); | ||
}); | ||
export const update_height = () => { | ||
fitAddon.fit(); | ||
}; | ||
$: { | ||
$terminal_size; | ||
setTimeout(() => { | ||
update_height(); | ||
}, 300); | ||
} | ||
</script> | ||
|
||
<div bind:this={div} style="height: 100%; width: 100%;" /> | ||
|
||
<style> | ||
div { | ||
height: 100%; | ||
width: 100%; | ||
} | ||
div :global(.xterm) { | ||
height: 100%; | ||
padding: 5px; | ||
} | ||
div :global(.xterm-viewport) { | ||
overflow-y: hidden !important; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script lang="ts"> | ||
import darkTheme from "$lib/stores/theme"; | ||
import type { ComponentType, SvelteComponent } from "svelte"; | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export let Console: ComponentType<SvelteComponent>; | ||
export let podName: string; | ||
export let projectId: string; | ||
</script> | ||
|
||
{#key $darkTheme} | ||
<div class="h-full overflow-y-auto"> | ||
<svelte:component this={Console} {podName} {projectId} /> | ||
</div> | ||
{/key} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div /> | ||
|
||
<style> | ||
div { | ||
background-color: var(--sk-back-1); | ||
width: 100%; | ||
height: 100%; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script lang="ts"> | ||
import { onDestroy, onMount, type ComponentType, type SvelteComponent } from "svelte"; | ||
import PlaceholderComponent from "./PlaceholderComponent.svelte"; | ||
import Desktop from "./Desktop.svelte"; | ||
export let podName: string; | ||
export let projectId: string; | ||
let Console: ComponentType<SvelteComponent> = PlaceholderComponent; | ||
let clear: number; | ||
// let loadingCodeEditor = false; | ||
onMount(async () => { | ||
// loadingCodeEditor = true; | ||
Console = (await import("$lib/components/map/Console.svelte")).default; | ||
}); | ||
onDestroy(() => { | ||
// loadingCodeEditor = false; | ||
Console = PlaceholderComponent; | ||
clearInterval(clear); | ||
}); | ||
</script> | ||
|
||
<div class="p-2 rounded-lg bg-gray-800"> | ||
<Desktop {Console} {podName} {projectId} /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { writable } from "svelte/store"; | ||
|
||
export const terminal_size = writable({ height: 65 }); | ||
|
||
// get pathnames from url | ||
export const pathname = writable(window.location.pathname); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.