Terminal look finished
This commit is contained in:
+3
-1
@@ -39,6 +39,8 @@
|
|||||||
"#lib/*": "./src/lib/*"
|
"#lib/*": "./src/lib/*"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lucide/svelte": "^1.66.0"
|
"@lucide/svelte": "^1.66.0",
|
||||||
|
"@wterm/dom": "^0.5.9",
|
||||||
|
"@wterm/svelte": "^0.5.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+29
@@ -11,6 +11,12 @@ importers:
|
|||||||
'@lucide/svelte':
|
'@lucide/svelte':
|
||||||
specifier: ^1.66.0
|
specifier: ^1.66.0
|
||||||
version: 1.66.0(svelte@5.57.3(@typescript-eslint/types@8.72.1))
|
version: 1.66.0(svelte@5.57.3(@typescript-eslint/types@8.72.1))
|
||||||
|
'@wterm/dom':
|
||||||
|
specifier: ^0.5.9
|
||||||
|
version: 0.5.9
|
||||||
|
'@wterm/svelte':
|
||||||
|
specifier: ^0.5.9
|
||||||
|
version: 0.5.9(@wterm/dom@0.5.9)(svelte@5.57.3(@typescript-eslint/types@8.72.1))
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@eslint/js':
|
'@eslint/js':
|
||||||
specifier: ^10.0.1
|
specifier: ^10.0.1
|
||||||
@@ -477,6 +483,18 @@ packages:
|
|||||||
resolution: {integrity: sha512-SB8xqipSzZHUePCCLNeYxqnxq83X61/qzNhjQGbTfjxGZIeOEP7tBgWYX05Tcd6CgE02WdTJnh5b8kMZJ/+bnQ==}
|
resolution: {integrity: sha512-SB8xqipSzZHUePCCLNeYxqnxq83X61/qzNhjQGbTfjxGZIeOEP7tBgWYX05Tcd6CgE02WdTJnh5b8kMZJ/+bnQ==}
|
||||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||||
|
|
||||||
|
'@wterm/core@0.5.9':
|
||||||
|
resolution: {integrity: sha512-+S5VA/CGmbU60PnN8PrE8i0hWBbzUzdrbjRYsnaioMum7alubzgRQ7IJ+SWCeymX6lKA6SfzfdkdYsNffTLA1Q==}
|
||||||
|
|
||||||
|
'@wterm/dom@0.5.9':
|
||||||
|
resolution: {integrity: sha512-0Ghz0FVbtr6g4Frk8F3I92H9UjCsIbhjQ1X8U+tly9oF172qDq685mrRPBeI8XZ5OIXK2bLr+/XAEYPUmxzwBA==}
|
||||||
|
|
||||||
|
'@wterm/svelte@0.5.9':
|
||||||
|
resolution: {integrity: sha512-keIpy5jH2bDh/p+F5sAjf0OSQEVnufCHfEXL/VqdbmqyB21+Dw+wr+y2S1WBZVTxaGgEp2F6GRWF0bvt3XM1wA==}
|
||||||
|
peerDependencies:
|
||||||
|
'@wterm/dom': 0.5.9
|
||||||
|
svelte: ^5.57.0
|
||||||
|
|
||||||
acorn-jsx@5.3.2:
|
acorn-jsx@5.3.2:
|
||||||
resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}
|
resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -1603,6 +1621,17 @@ snapshots:
|
|||||||
'@typescript-eslint/types': 8.72.1
|
'@typescript-eslint/types': 8.72.1
|
||||||
eslint-visitor-keys: 5.0.1
|
eslint-visitor-keys: 5.0.1
|
||||||
|
|
||||||
|
'@wterm/core@0.5.9': {}
|
||||||
|
|
||||||
|
'@wterm/dom@0.5.9':
|
||||||
|
dependencies:
|
||||||
|
'@wterm/core': 0.5.9
|
||||||
|
|
||||||
|
'@wterm/svelte@0.5.9(@wterm/dom@0.5.9)(svelte@5.57.3(@typescript-eslint/types@8.72.1))':
|
||||||
|
dependencies:
|
||||||
|
'@wterm/dom': 0.5.9
|
||||||
|
svelte: 5.57.3(@typescript-eslint/types@8.72.1)
|
||||||
|
|
||||||
acorn-jsx@5.3.2(acorn@8.19.0):
|
acorn-jsx@5.3.2(acorn@8.19.0):
|
||||||
dependencies:
|
dependencies:
|
||||||
acorn: 8.19.0
|
acorn: 8.19.0
|
||||||
|
|||||||
@@ -2,13 +2,17 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
|
children,
|
||||||
value = $bindable(''),
|
value = $bindable(''),
|
||||||
|
cursorPrompt = '$',
|
||||||
blinkDelay = 250,
|
blinkDelay = 250,
|
||||||
autofocus = true,
|
autofocus = true,
|
||||||
oninput = () => {},
|
oninput = () => {},
|
||||||
onsubmit = () => {}
|
onsubmit = () => {}
|
||||||
}: {
|
}: {
|
||||||
|
children: any;
|
||||||
value?: string;
|
value?: string;
|
||||||
|
cursorPrompt?: string;
|
||||||
blinkDelay?: number;
|
blinkDelay?: number;
|
||||||
autofocus?: boolean;
|
autofocus?: boolean;
|
||||||
oninput?: (value: string) => void;
|
oninput?: (value: string) => void;
|
||||||
@@ -16,6 +20,8 @@
|
|||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let container: HTMLElement;
|
let container: HTMLElement;
|
||||||
|
let textField: HTMLElement;
|
||||||
|
let cursor: HTMLElement;
|
||||||
let cursorPos: number = $state(value.length);
|
let cursorPos: number = $state(value.length);
|
||||||
let anchorPos: number | null = $state(null);
|
let anchorPos: number | null = $state(null);
|
||||||
let isDragging: boolean = $state(false);
|
let isDragging: boolean = $state(false);
|
||||||
@@ -80,6 +86,62 @@
|
|||||||
anchorPos = null;
|
anchorPos = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- cursor alignment ---------------------------------------------------
|
||||||
|
|
||||||
|
/** Move the caret to the exact pixel where the character at cursorPos lives. */
|
||||||
|
function syncCursor() {
|
||||||
|
if (!textField || !cursor) return;
|
||||||
|
|
||||||
|
/* const containerRect = container.getBoundingClientRect();
|
||||||
|
if (containerRect.width === 0) return;
|
||||||
|
|
||||||
|
const chars = container.querySelectorAll<HTMLElement>('.char');
|
||||||
|
// With the placeholder, chars is never empty — but guard anyway.
|
||||||
|
if (chars.length === 0) return; */
|
||||||
|
|
||||||
|
const containerRect = textField.getBoundingClientRect();
|
||||||
|
const chars = textField.querySelectorAll<HTMLElement>('.char');
|
||||||
|
|
||||||
|
if (chars.length === 0) {
|
||||||
|
cursor.style.transform = `translateX(0px)`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let refRect: DOMRect;
|
||||||
|
let x: number;
|
||||||
|
|
||||||
|
if (cursorPos >= chars.length) {
|
||||||
|
refRect = chars[chars.length - 1].getBoundingClientRect();
|
||||||
|
x = refRect.right - containerRect.left;
|
||||||
|
} else {
|
||||||
|
refRect = chars[cursorPos].getBoundingClientRect();
|
||||||
|
x = refRect.left - containerRect.left;
|
||||||
|
if (chars[cursorPos].classList.contains('selected')) {
|
||||||
|
cursor.style.backgroundColor = 'var(--color-bg-hard)';
|
||||||
|
} else {
|
||||||
|
cursor.style.backgroundColor = 'var(--color-fg1)';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.style.transform = `translateX(${x}px)`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-sync after every value / cursor movement (runs after DOM update).
|
||||||
|
$effect(() => {
|
||||||
|
void value;
|
||||||
|
void cursorPos;
|
||||||
|
syncCursor();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Re-sync on webfont load and on resize (font metrics can change).
|
||||||
|
$effect(() => {
|
||||||
|
if (!container) return;
|
||||||
|
const ro = new ResizeObserver(() => syncCursor());
|
||||||
|
ro.observe(container);
|
||||||
|
document.fonts?.ready.then(() => syncCursor());
|
||||||
|
return () => ro.disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (autofocus && container) {
|
if (autofocus && container) {
|
||||||
container.focus();
|
container.focus();
|
||||||
@@ -303,7 +365,7 @@
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
id="terminal-input"
|
id="terminal-input"
|
||||||
class="relative inline-block font-mono whitespace-nowrap outline-none select-none"
|
class="relative inline-block font-mono leading-relaxed whitespace-nowrap outline-none select-none"
|
||||||
bind:this={container}
|
bind:this={container}
|
||||||
tabindex="1"
|
tabindex="1"
|
||||||
role="textbox"
|
role="textbox"
|
||||||
@@ -313,38 +375,40 @@
|
|||||||
onkeydown={handleKeydown}
|
onkeydown={handleKeydown}
|
||||||
onpaste={handlePaste}
|
onpaste={handlePaste}
|
||||||
onmousedown={handleMouseDown}
|
onmousedown={handleMouseDown}
|
||||||
style="--cursor-index: {cursorPos};"
|
|
||||||
>
|
>
|
||||||
<!-- <span class="text-fg-dim inline-block">~/Downloads</span> -->
|
{@render children()}<span
|
||||||
<span class="prompt text-fg inline-block w-[1ch] text-center">$</span>
|
bind:this={textField}
|
||||||
<span class="inline cursor-text" aria-hidden="true">
|
class="text-fg0 relative inline cursor-text"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
{#each value.split('') as char, i}
|
{#each value.split('') as char, i}
|
||||||
<span
|
<span
|
||||||
class="char text-glow inline-block w-[1ch] text-center leading-relaxed whitespace-pre-wrap"
|
class="char h-3 w-[1ch] py-0.5 leading-relaxed whitespace-pre-wrap"
|
||||||
class:selected={isSelected(i)}
|
class:selected={isSelected(i)}
|
||||||
|
class:text-bg={isSelected(i)}
|
||||||
data-char-index={i}>{char}</span
|
data-char-index={i}>{char}</span
|
||||||
>
|
>
|
||||||
{/each}
|
{/each}
|
||||||
|
<div
|
||||||
|
id="curs"
|
||||||
|
bind:this={cursor}
|
||||||
|
class="cursor bg-fg1 absolute bottom-0 left-0 h-px w-[1ch]"
|
||||||
|
class:animate-cursor-blink={!blinkPaused && !selection.active}
|
||||||
|
></div>
|
||||||
</span>
|
</span>
|
||||||
<div
|
|
||||||
id="curs"
|
|
||||||
class="cursor bg-fg1 absolute bottom-1 h-px w-[1ch]"
|
|
||||||
class:animate-cursor-blink={!blinkPaused && !selection.active}
|
|
||||||
></div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.cursor {
|
.cursor {
|
||||||
left: calc(var(--cursor-index) * 1ch + 8.5px + 1ch);
|
transition: all 80ms ease;
|
||||||
transition: all 0.1s ease;
|
|
||||||
}
|
}
|
||||||
.char {
|
.char {
|
||||||
transition: all linear 0.1s;
|
transition: all 80ms ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.char.selected {
|
.char.selected {
|
||||||
transition: none;
|
transition: none;
|
||||||
background-color: var(--);
|
background-color: var(--fg1);
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
let inputValue = $state('');
|
let inputValue = $state('');
|
||||||
let inputComponent: any;
|
let inputComponent: any;
|
||||||
|
let outputWrapper: HTMLElement;
|
||||||
|
let count: [string, string][] = $state([]);
|
||||||
|
|
||||||
const mwinoptions: Partial<MWinParams> = {
|
const mwinoptions: Partial<MWinParams> = {
|
||||||
handle: '#terminal-bar',
|
handle: '#terminal-bar',
|
||||||
@@ -36,8 +38,27 @@
|
|||||||
mwin = api;
|
mwin = api;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function onsubmit(value: string) {
|
||||||
|
if (value === 'clear') {
|
||||||
|
count = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(value);
|
||||||
|
count.push([value, working_dir]);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#snippet Out(value: string, path: string)}
|
||||||
|
<span
|
||||||
|
><span class=" scroll-line text-tyellow">{username}</span><span>@</span><span class=" text-fg1"
|
||||||
|
>{hostname}</span
|
||||||
|
>
|
||||||
|
<span class="text-bg4">{path}</span><br /></span
|
||||||
|
>
|
||||||
|
<span class=" scroll-line mr-[1ch]">$</span><span>{value}</span>
|
||||||
|
{/snippet}
|
||||||
|
|
||||||
<Movable
|
<Movable
|
||||||
{wrapper}
|
{wrapper}
|
||||||
{mwinoptions}
|
{mwinoptions}
|
||||||
@@ -45,46 +66,64 @@
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
id="terminal-bar"
|
id="terminal-bar"
|
||||||
class=" bg-bg-soft grid grid-cols-[1fr_auto_1fr] rounded-t-md py-3 select-none"
|
class=" bg-bg-soft grid grid-cols-[1fr_auto_1fr] rounded-t-md py-1 select-none"
|
||||||
>
|
>
|
||||||
<div class="dots-wrapper m-auto mx-3 flex size-max flex-row items-center justify-center gap-3">
|
<div class="dots-wrapper m-auto mx-3 flex size-max flex-row items-center justify-center gap-2">
|
||||||
<button
|
<button
|
||||||
data-close-btn
|
data-close-btn
|
||||||
class="bg-term-close size-3 cursor-pointer rounded-full active:brightness-85"
|
class="bg-term-close h-2.5 w-2.5 cursor-pointer rounded-full active:brightness-85"
|
||||||
type="button"
|
type="button"
|
||||||
aria-label="Close terminal"
|
aria-label="Close terminal"
|
||||||
onclick={() => close?.(id)}
|
onclick={() => close?.(id)}
|
||||||
></button>
|
></button>
|
||||||
<button
|
<button
|
||||||
class="bg-term-maximize size-3 cursor-pointer rounded-full active:brightness-85"
|
class="bg-term-maximize h-2.5 w-2.5 cursor-pointer rounded-full active:brightness-85"
|
||||||
type="button"
|
type="button"
|
||||||
aria-label="Maximize terminal"
|
aria-label="Maximize terminal"
|
||||||
onclick={() => mwin?.maximize()}
|
onclick={() => mwin?.maximize()}
|
||||||
></button>
|
></button>
|
||||||
<button
|
<button
|
||||||
class="bg-term-minimize size-3 cursor-pointer rounded-2xl active:brightness-85"
|
class="bg-term-minimize h-2.5 w-2.5 cursor-pointer rounded-2xl active:brightness-85"
|
||||||
type="button"
|
type="button"
|
||||||
aria-label="Minimize terminal"
|
aria-label="Minimize terminal"
|
||||||
onclick={() => mwin?.minimize()}
|
onclick={() => mwin?.minimize()}
|
||||||
></button>
|
></button>
|
||||||
</div>
|
</div>
|
||||||
<span class=" text-primary mx-auto text-sm font-bold"
|
<span class=" text-fg2 mx-auto text-sm font-medium">{username} — tsh</span>
|
||||||
>{username}@{hostname} — {working_dir} {mwin?.state.width}x{mwin?.state.height}</span
|
|
||||||
>
|
|
||||||
<span></span>
|
<span></span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="inner-content scroll-hidden text-text-primary grow origin-top overflow-y-auto p-4 text-sm"
|
class="inner-content scroll-hidden text-fg4 font-ibm grow origin-top overflow-y-auto p-4 text-sm"
|
||||||
id="cout"
|
id="cout"
|
||||||
onclick={() => inputComponent?.focusInput()}
|
onclick={() => inputComponent?.focusInput()}
|
||||||
onkeydown={() => inputComponent?.focusInput()}
|
onkeydown={() => inputComponent?.focusInput()}
|
||||||
role="textbox"
|
role="textbox"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<div id="outputWrapper"></div>
|
<div bind:this={outputWrapper} class="">
|
||||||
<span>{username}@{hostname}: {working_dir}<br /></span>
|
{#each count as c}
|
||||||
<Input bind:value={inputValue} blinkDelay={500} bind:this={inputComponent} />
|
{@render Out(c[0], c[1])}
|
||||||
|
<div class="mb-3"></div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
><span class=" text-tyellow">{username}</span><span>@</span><span class=" text-fg1"
|
||||||
|
>{hostname}</span
|
||||||
|
>
|
||||||
|
<span class="text-bg4">{working_dir}</span><br /></span
|
||||||
|
>
|
||||||
|
<Input bind:value={inputValue} blinkDelay={500} {onsubmit} bind:this={inputComponent}
|
||||||
|
><span class="font-ibm mr-[1ch]">$</span></Input
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class=" bg-bg-soft">[TABS]</div> -->
|
|
||||||
<div class=" bg-bg-soft rounded-b-md">1</div>
|
|
||||||
</Movable>
|
</Movable>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.inner-content {
|
||||||
|
scroll-snap-type: y mandatory;
|
||||||
|
scroll-behavior: auto;
|
||||||
|
}
|
||||||
|
.scroll-line {
|
||||||
|
scroll-snap-align: start;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -102,14 +102,14 @@
|
|||||||
<div
|
<div
|
||||||
id="terminal-wrapper"
|
id="terminal-wrapper"
|
||||||
bind:this={wrapper}
|
bind:this={wrapper}
|
||||||
class=" relative flex h-screen w-full flex-col items-center justify-center"
|
class=" relative flex h-screen w-full flex-col items-center justify-center overflow-x-hidden"
|
||||||
>
|
>
|
||||||
<Terminal
|
<Terminal
|
||||||
id={10}
|
id={10}
|
||||||
wrapper="#terminal-wrapper"
|
wrapper="#terminal-wrapper"
|
||||||
username="gornodox"
|
username="gornodox"
|
||||||
hostname="termos"
|
hostname="termos"
|
||||||
working_dir="~"
|
working_dir="~/Documents/Projects/gornodox.dev"
|
||||||
mwin={api}
|
mwin={api}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
wrapper,
|
wrapper,
|
||||||
username: 'gornodox',
|
username: 'gornodox',
|
||||||
hostname: 'termos',
|
hostname: 'termos',
|
||||||
working_dir: '~',
|
working_dir: '~/Documents/Projects/gornodox.dev',
|
||||||
mwin: api,
|
mwin: api,
|
||||||
close: remove
|
close: remove
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Terminal } from '@wterm/svelte';
|
||||||
|
import '@wterm/svelte/css';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
|
let term: Terminal;
|
||||||
|
|
||||||
|
function print() {
|
||||||
|
term.write('Hello, World!');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
globalThis.__debug = { print };
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Terminal bind:this={term} theme="monokai" />
|
||||||
@@ -135,10 +135,6 @@
|
|||||||
--font-ibm: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
--font-ibm: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@utility glow {
|
|
||||||
text-shadow: 0 0 6px var(--glow-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@utility bg-pattern-dots {
|
@utility bg-pattern-dots {
|
||||||
background-image: var(--background-image-pattern-dots);
|
background-image: var(--background-image-pattern-dots);
|
||||||
background-size: 20px 20px;
|
background-size: 20px 20px;
|
||||||
|
|||||||
Reference in New Issue
Block a user