WIP: Reworked input module for the terminal front-end

This commit is contained in:
2026-06-23 06:05:58 +02:00
parent 8682de7d17
commit 8cb42f07a2
6 changed files with 107 additions and 50 deletions
+2 -2
View File
@@ -73,7 +73,7 @@
> >
<input name="username" value={username} class=" hidden" /> <input name="username" value={username} class=" hidden" />
<div <div
class="ml-4 flex w-2xs flex-row class="flex w-2xs flex-row
items-center overflow-clip rounded-md border border-border bg-surface-1 pl-2 text-sm text-muted transition-colors duration-200 outline-none has-focus:border-focus-ring" items-center overflow-clip rounded-md border border-border bg-surface-1 pl-2 text-sm text-muted transition-colors duration-200 outline-none has-focus:border-focus-ring"
> >
<Lock size={16} strokeWidth={2} /> <Lock size={16} strokeWidth={2} />
@@ -83,13 +83,13 @@
placeholder="Password..." placeholder="Password..."
class=" ml-2 grow appearance-none px-3 py-2 outline-none" class=" ml-2 grow appearance-none px-3 py-2 outline-none"
/> />
</div>
<button <button
type="submit" type="submit"
class=" bg-bg-lighter-dark hover:text-primary-hover-dark active:text-primary-dark active:bg-bg-light-dark rounded p-1.5" class=" bg-bg-lighter-dark hover:text-primary-hover-dark active:text-primary-dark active:bg-bg-light-dark rounded p-1.5"
> >
<ArrowRight size={20} strokeWidth={2} /> <ArrowRight size={20} strokeWidth={2} />
</button> </button>
</div>
</form> </form>
</div> </div>
+4 -4
View File
@@ -1,6 +1,8 @@
<script lang="ts"> <script lang="ts">
import Input from './terminal/Input.svelte'; import Input from './terminal/Input.svelte';
let { username }: { username: string } = $props();
//const clearTerminal = (): void => clear(); //const clearTerminal = (): void => clear();
//const printOutput = (e: HTMLElement, d: PrintData): void => print(e, d); //const printOutput = (e: HTMLElement, d: PrintData): void => print(e, d);
@@ -18,8 +20,8 @@
function updateTerminal() { function updateTerminal() {
//isProcessActive = terminal.isProcessActive; //isProcessActive = terminal.isProcessActive;
username = terminal!.getUser().username; //username = terminal!.getUser().username;
cwd = terminal!.getCwd(); //cwd = terminal!.getCwd();
} }
function getWidth() { function getWidth() {
@@ -95,8 +97,6 @@
getWidth: getWidth, getWidth: getWidth,
getFontSize: getFontSize getFontSize: getFontSize
}; */ }; */
let username: string = $state('');
let cwd: string = $state(''); let cwd: string = $state('');
const hostname = 'terminal'; //TODO: Change this to pull from config on db const hostname = 'terminal'; //TODO: Change this to pull from config on db
//let isProcessActive = $state(false); //let isProcessActive = $state(false);
+55 -11
View File
@@ -1,36 +1,70 @@
<script lang="ts"> <script lang="ts">
import { onMount } from 'svelte';
let { let {
inputValue = $bindable(), inputValue = $bindable(),
isFocused, isFocused,
cwd cwd
}: { inputValue: string; isFocused?: boolean; cwd: string } = $props(); }: { inputValue: string; isFocused?: boolean; cwd: string } = $props();
function handleInput(event: Event) { let cursor: any;
inputValue = (event.target as HTMLInputElement).value; let input: HTMLInputElement;
let cursorPos: number = $state(0);
let locked: boolean = $state(false);
onMount(() => {
cursor = document.getElementById('cursor')!;
input = document.getElementById('input')! as HTMLInputElement;
$inspect(cursorPos);
});
function shiftCursor(direction: 0 | 1) {
if (cursorPos === 0 && direction === 1) return;
if (cursorPos === input.value.length && direction === 0) return;
if (direction === 0) {
cursorPos += 1;
} else {
cursorPos -= 1;
} }
/* function moveCursor() { cursor.style.transform = `translateX(-${8 * cursorPos + cursorPos - 1}px)`;
} }
function keyDown(event: KeyboardEvent) { function keyDown(event: KeyboardEvent) {
cursor.style.opacity = '1';
locked = true;
inputValue = (event.target as HTMLInputElement).value;
switch (event.key) { switch (event.key) {
case 'Enter': case 'Enter':
inputValue = '' inputValue = '';
cursor.style.transform = `translateX(0px)`;
break;
case 'ArrowRight': case 'ArrowRight':
document.getElementById('cursor')?.style.transform = 'translateX(8px)' shiftCursor(1);
break;
case 'ArrowLeft': case 'ArrowLeft':
shiftCursor(0);
break;
}
setTimeout(() => {
locked = false;
}, 100);
} }
} */
</script> </script>
<div class="relative">
<div id="terminal-input"></div>
</div>
<div class=" relative"> <div class=" relative">
<input <input
autofocus autofocus
bind:value={inputValue} bind:value={inputValue}
onkeydown={(e) => e.key === 'Enter' && (inputValue = '')} onkeydown={(e) => keyDown(e)}
oninput={handleInput}
onfocus={() => (isFocused = true)} onfocus={() => (isFocused = true)}
onblur={() => (isFocused = false)} onblur={() => (isFocused = false)}
type="text" type="text"
@@ -44,10 +78,20 @@
<div class="w flex-column flex flex-row flex-wrap font-terminal"> <div class="w flex-column flex flex-row flex-wrap font-terminal">
<span class="pointer pr-2">$</span> <span class="pointer pr-2">$</span>
<!-- prettier-ignore --> <!-- prettier-ignore -->
<div style="white-space: preserve;" class=" relative wrap-break-word">{inputValue}</div> <span style="white-space: preserve;" class=" relative wrap-break-word">
<span id="cursor" class={isFocused ? 'animate-cursor-blink' : ''}>_</span> {#each inputValue.split('') as char}
<span class=" w-[1ch]">{char}</span>
{/each}
</span>
<span
id="cursor"
class=" transition-transform duration-150 ease-out {isFocused && !locked
? 'animate-cursor-blink'
: ''}">_</span
>
</div> </div>
</div> </div>
<style> <style>
.char
</style> </style>
+11 -5
View File
@@ -1,6 +1,7 @@
import { db } from '$lib/server/db'; import { db } from '$lib/server/db';
import { config } from '$lib/server/db/schema'; import { config } from '$lib/server/db/schema';
import { PASSWD } from '$lib/stores/bash/etc/userData'; import { PASSWD } from '$lib/stores/bash/etc/userData';
import { error } from '@sveltejs/kit';
import { eq } from 'drizzle-orm'; import { eq } from 'drizzle-orm';
import type { Actions, PageServerLoad } from './$types'; import type { Actions, PageServerLoad } from './$types';
@@ -22,11 +23,16 @@ export const actions = {
} satisfies Actions; } satisfies Actions;
export const load: PageServerLoad = async () => { export const load: PageServerLoad = async () => {
return { try {
config: await db const rows = await db
.select({ config: config.value }) .select({ value: config.value })
.from(config) .from(config)
.where(eq(config.value, 'maintenance')) .where(eq(config.value, 'maintenance'))
.limit(1) .limit(1);
}; return { config: rows };
} catch (err) {
console.error('Full error:', err);
// Optionally, throw a user-friendly error
throw error(500, 'Database query failed');
}
}; };
+6 -1
View File
@@ -7,6 +7,7 @@
let { form, data } = $props(); let { form, data } = $props();
const MAINTENANCE = $derived(Boolean(data.config[0])); const MAINTENANCE = $derived(Boolean(data.config[0]));
let username = $state('');
function welcomeSequence() { function welcomeSequence() {
//isWelcomeSequence = true; //isWelcomeSequence = true;
@@ -16,12 +17,16 @@
function initializer(formData: FormData) { function initializer(formData: FormData) {
console.log(formData); console.log(formData);
username = formData.get('username')?.toString() ?? 'foo';
if (form?.error) return; if (form?.error) return;
/* const password = formData.get('password')?.toString(); /* const password = formData.get('password')?.toString();
const username = formData.get('username')?.toString(); const username = formData.get('username')?.toString();
if (!password || !username) throw new Error('password or username is null or undefined'); if (!password || !username) throw new Error('password or username is null or undefined');
terminalComponent.init(username, password); */ terminalComponent.init(username, password); */
} }
console.log(username);
</script> </script>
{#if MAINTENANCE} {#if MAINTENANCE}
@@ -37,7 +42,7 @@
<Login init={initializer} {form} /> <Login init={initializer} {form} />
</div> </div>
<div id="wrapper2" class=" absolute z-4 size-4/5 opacity-0 {form?.success ? 'intro' : ''}"> <div id="wrapper2" class=" absolute z-4 size-4/5 opacity-0 {form?.success ? 'intro' : ''}">
<Terminal></Terminal> <Terminal {username}></Terminal>
</div> </div>
</div> </div>
{/if} {/if}
+11 -9
View File
@@ -1,14 +1,11 @@
@theme { @theme {
--animate-loading: loading 1s ease-in-out infinite; --animate-loading: loading 1s ease-in-out infinite;
--animate-cursor-blink: blink 1s step-end infinite; --animate-cursor-blink: blink 1s step-end infinite;
--animate-error-shake: shake 0.82s cubic-bezier(.36,.07,.19,.97) both; --animate-error-shake: shake 0.82s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
@keyframes blink { @keyframes blink {
0% {
opacity: 0;
}
50% { 50% {
opacity: 1; opacity: 0;
} }
} }
@@ -26,16 +23,21 @@
} }
@keyframes shake { @keyframes shake {
10%, 90% { 10%,
90% {
transform: translate3d(-1px, 0, 0); transform: translate3d(-1px, 0, 0);
} }
20%, 80% { 20%,
80% {
transform: translate3d(2px, 0, 0); transform: translate3d(2px, 0, 0);
} }
30%, 50%, 70% { 30%,
50%,
70% {
transform: translate3d(-4px, 0, 0); transform: translate3d(-4px, 0, 0);
} }
40%, 60% { 40%,
60% {
transform: translate3d(4px, 0, 0); transform: translate3d(4px, 0, 0);
} }
} }