Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 54 additions & 14 deletions src/lib/components/Terminal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
let terminalElement: HTMLDivElement;
let inputElement: HTMLInputElement;
let isVisible = false;
let isFullscreen = false;

function toggleFullscreen() {
isFullscreen = !isFullscreen;
if (window.matchMedia("(pointer: fine)").matches) focusInput();
else panelElement?.focus();
}
let toggleElement: HTMLButtonElement;
let panelElement: HTMLDivElement;

Expand Down Expand Up @@ -121,21 +128,24 @@ about background & experience`,
if (window.matchMedia("(pointer: fine)").matches) focusInput();
else panelElement?.focus();
} else {
isFullscreen = false;
toggleElement?.focus();
}
}

function handleWindowKeydown(event: KeyboardEvent) {
if (isVisible && event.key === "Escape") {
event.preventDefault();
toggleTerminal();
}
if (!isVisible || event.key !== "Escape") return;
event.preventDefault();
if (isFullscreen) isFullscreen = false;
else toggleTerminal();
}

onMount(() => {
const closeOtherPanel = (event: Event) => {
if ((event as CustomEvent<string>).detail !== "terminal")
if ((event as CustomEvent<string>).detail !== "terminal") {
isVisible = false;
isFullscreen = false;
}
};
window.addEventListener("portfolio-panel", closeOtherPanel);
return () => window.removeEventListener("portfolio-panel", closeOtherPanel);
Expand Down Expand Up @@ -184,6 +194,7 @@ about background & experience`,
{#if isVisible}
<div
class="terminal-container"
class:fullscreen={isFullscreen}
id="portfolio-terminal"
role="dialog"
aria-labelledby="terminal-title"
Expand All @@ -194,13 +205,25 @@ about background & experience`,
<div class="terminal-title" id="terminal-title">
terminal <span>/ divit</span>
</div>
<button
class="terminal-close"
on:click={toggleTerminal}
aria-label="Close Terminal"
>
✕
</button>
<div class="terminal-actions">
<button
class="terminal-action"
on:click={toggleFullscreen}
aria-pressed={isFullscreen}
aria-label={isFullscreen
? "Exit fullscreen terminal"
: "Fullscreen terminal"}
>
{isFullscreen ? "⊟" : "⊞"}
</button>
<button
class="terminal-close"
on:click={toggleTerminal}
aria-label="Close Terminal"
>
✕
</button>
</div>
</div>

<div
Expand Down Expand Up @@ -311,9 +334,19 @@ about background & experience`,
max-height: calc(
100dvh - 96px - env(safe-area-inset-bottom) - env(safe-area-inset-top)
);

&.fullscreen {
inset: 12px;
width: auto;
height: auto;
max-width: none;
max-height: none;
z-index: 1100;
}

border: 1px solid #777;
border-radius: 0;
background: #090909;
background: #131313eb;
color: #eee;
}

Expand All @@ -325,6 +358,7 @@ about background & experience`,
min-height: 52px;
padding-left: 16px;
border-bottom: 1px solid #444;
background: #131313cc;
}

.terminal-title {
Expand All @@ -334,6 +368,11 @@ about background & experience`,
.terminal-title span {
color: #a3a3a3;
}
.terminal-actions {
display: flex;
align-items: center;
}
.terminal-action,
.terminal-close {
min-width: 48px;
min-height: 48px;
Expand All @@ -343,6 +382,7 @@ about background & experience`,
font-size: 18px;
cursor: pointer;
}
.terminal-action:hover,
.terminal-close:hover {
background: #222;
}
Expand Down Expand Up @@ -410,7 +450,7 @@ about background & experience`,
padding: 0 10px;
gap: 8px;
}
.terminal-container {
.terminal-container:not(.fullscreen) {
right: calc(12px + env(safe-area-inset-right));
bottom: calc(68px + env(safe-area-inset-bottom));
max-width: calc(
Expand Down