Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
feat: add transparent terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
doinkythederp committed Dec 10, 2023
1 parent dcb3f69 commit 232d271
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</Modal>
<Card title="Get Started" titleCentered>
<div class="grid grid-cols-2 gap-4 self-stretch">
<Button onClick={pickWorkspace} class="flex-1"
<Button on:click={pickWorkspace} class="flex-1"
>Open workspace</Button
>
<p class="secondary flex-1 text-center">
Expand Down
10 changes: 6 additions & 4 deletions src/lib/Button.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script context="module" lang="ts">
export type ButtonContext =
| {
large: boolean;
plain: boolean;
}
| undefined;
export const buttonStyle = Symbol("button-style");
Expand All @@ -11,10 +11,10 @@
import { twMerge } from "tailwind-merge";
import { getContext, onMount } from "svelte";
const context = getContext<ButtonContext | undefined>(buttonStyle);
export let onClick: () => void;
export let large = context?.large ?? false;
export let large = false;
export let primary = false;
export let disabled = false;
export let plain = context?.plain ?? false;
let className = "";
export { className as class };
Expand Down Expand Up @@ -46,11 +46,13 @@
primary && "font-semibold",
disabled &&
"pointer-events-none bg-neutral-100 text-black/50 shadow-neutral-500/10 transition-colors dark:bg-neutral-800 dark:text-white/50",
plain &&
"self-baseline bg-transparent shadow-none dark:border-solid dark:border-white/20 dark:bg-transparent dark:active:bg-neutral-500/50",
className,
)}
type="button"
{disabled}
on:click={onClick}
on:click
>
<slot />
</button>
11 changes: 8 additions & 3 deletions src/lib/Card.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<script lang="ts">
import { setContext } from "svelte";
import { twMerge } from "tailwind-merge";
import Button, { buttonStyle, type ButtonContext } from "./Button.svelte";
import WithContext from "./WithContext.svelte";
export let title: string | undefined = undefined;
export let titleCentered = false;
let className = "";
Expand All @@ -16,15 +19,17 @@
{#if title}
<h2
class={twMerge(
"mb-1 text-xl font-bold",
"mb-1 flex-1 text-xl font-bold",
titleCentered && "self-center",
)}
>
{title}
</h2>
{/if}
<div class="flex-1">
<slot name="actions" />
<div class="flex flex-1 justify-end">
<WithContext ctx={buttonStyle} value={{ plain: true }}>
<slot name="actions" />
</WithContext>
</div>
</div>
<slot />
Expand Down
15 changes: 14 additions & 1 deletion src/lib/Console.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
export const terminal = new Terminal({
convertEol: true,
fontFamily: "ui-monospace, monospace",
allowTransparency: true,
theme: {
background: "#00000000",
},
});
const fitAddon = new FitAddon();
const webgl = new WebglAddon();
Expand Down Expand Up @@ -50,9 +54,18 @@
terminal.open(term!);
fitAddon.fit();
resize.observe(term!);
terminal.focus();
const focused = document.activeElement;
terminal.focus();
if (focused instanceof HTMLElement) {
focused.focus();
}
});
</script>

<div class="relative h-full w-full">
<div class="absolute inset-0 bg-black" bind:this={term} />
<div
class="absolute inset-0 overflow-hidden rounded-md bg-black bg-transparent p-2"
bind:this={term}
/>
</div>
24 changes: 13 additions & 11 deletions src/lib/FirstTimeSetup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import TransitionHeight from "./TransitionHeight.svelte";
import type { Action } from "svelte/action";
import type { TransitionConfig } from "svelte/transition";
import { downloadServer } from '../sidecar.ts';
import { downloadServer } from "../sidecar.ts";
const dismiss = getContext<ctx.DismissContext>(ctx.dismiss);
enum Page {
Expand Down Expand Up @@ -79,14 +79,14 @@
<Divider />
<div class="sticky bottom-0 flex justify-between gap-3 self-stretch px-6 py-3">
<Button
onClick={() => {
on:click={() => {
exit(0);
}}
large>Quit</Button
>
<div class="flex-1" />
<Button
onClick={() => {
on:click={() => {
page -= 1;
}}
large
Expand All @@ -95,19 +95,21 @@
Back
</Button>
<Button
onClick={() => {
on:click={() => {
if (page === Page.Welcome) {
page += 1;
if (!download) {
download = downloadServer((progress) => {
downloadProgress = progress;
}).then(() => {
downloadFinished = true;
downloadProgress = 100;
}).catch((err) => {
error = err;
downloadProgress = 0;
});
})
.then(() => {
downloadFinished = true;
downloadProgress = 100;
})
.catch((err) => {
error = err;
downloadProgress = 0;
});
}
} else {
dismiss?.();
Expand Down
10 changes: 10 additions & 0 deletions src/lib/WithContext.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script lang="ts">
import { setContext } from "svelte";
export let ctx: unknown;
export let value: unknown;
setContext(ctx, value);
</script>

<slot />
15 changes: 12 additions & 3 deletions src/lib/WorkspaceView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@
<div class="grid grid-cols-2 grid-rows-2 gap-4 self-stretch">
<Button
large
onClick={() => {
on:click={() => {
Workspace.close();
}}
>
Close workspace
</Button>
<Button large onClick={start}>Start simulator</Button>
<Button large on:click={start}>Start simulator</Button>
</div>
</Card>
<Card title="LCD Display" class="">
Expand All @@ -119,7 +119,16 @@
</div>
</Pane>
<Pane minSize={25}>
<Card title="Console" class="flex-1">
<Card title="Console" class="flex-1 gap-2">
<svelte:fragment slot="actions">
<Button
on:click={() => {
terminal.clear();
}}
>
Clear
</Button>
</svelte:fragment>
<Console bind:terminal />
</Card>
</Pane>
Expand Down

0 comments on commit 232d271

Please sign in to comment.