WIP: Reworked input module for the terminal front-end
This commit is contained in:
@@ -73,7 +73,7 @@
|
||||
>
|
||||
<input name="username" value={username} class=" hidden" />
|
||||
<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"
|
||||
>
|
||||
<Lock size={16} strokeWidth={2} />
|
||||
@@ -83,13 +83,13 @@
|
||||
placeholder="Password..."
|
||||
class=" ml-2 grow appearance-none px-3 py-2 outline-none"
|
||||
/>
|
||||
<button
|
||||
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"
|
||||
>
|
||||
<ArrowRight size={20} strokeWidth={2} />
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
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"
|
||||
>
|
||||
<ArrowRight size={20} strokeWidth={2} />
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import Input from './terminal/Input.svelte';
|
||||
|
||||
let { username }: { username: string } = $props();
|
||||
|
||||
//const clearTerminal = (): void => clear();
|
||||
|
||||
//const printOutput = (e: HTMLElement, d: PrintData): void => print(e, d);
|
||||
@@ -18,8 +20,8 @@
|
||||
|
||||
function updateTerminal() {
|
||||
//isProcessActive = terminal.isProcessActive;
|
||||
username = terminal!.getUser().username;
|
||||
cwd = terminal!.getCwd();
|
||||
//username = terminal!.getUser().username;
|
||||
//cwd = terminal!.getCwd();
|
||||
}
|
||||
|
||||
function getWidth() {
|
||||
@@ -95,8 +97,6 @@
|
||||
getWidth: getWidth,
|
||||
getFontSize: getFontSize
|
||||
}; */
|
||||
|
||||
let username: string = $state('');
|
||||
let cwd: string = $state('');
|
||||
const hostname = 'terminal'; //TODO: Change this to pull from config on db
|
||||
//let isProcessActive = $state(false);
|
||||
|
||||
@@ -1,36 +1,70 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let {
|
||||
inputValue = $bindable(),
|
||||
isFocused,
|
||||
cwd
|
||||
}: { inputValue: string; isFocused?: boolean; cwd: string } = $props();
|
||||
|
||||
function handleInput(event: Event) {
|
||||
inputValue = (event.target as HTMLInputElement).value;
|
||||
}
|
||||
let cursor: any;
|
||||
let input: HTMLInputElement;
|
||||
let cursorPos: number = $state(0);
|
||||
let locked: boolean = $state(false);
|
||||
|
||||
/* function moveCursor() {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
cursor.style.transform = `translateX(-${8 * cursorPos + cursorPos - 1}px)`;
|
||||
}
|
||||
|
||||
function keyDown(event: KeyboardEvent) {
|
||||
switch(event.key) {
|
||||
case 'Enter':
|
||||
inputValue = ''
|
||||
case 'ArrowRight':
|
||||
document.getElementById('cursor')?.style.transform = 'translateX(8px)'
|
||||
case 'ArrowLeft':
|
||||
cursor.style.opacity = '1';
|
||||
locked = true;
|
||||
inputValue = (event.target as HTMLInputElement).value;
|
||||
|
||||
switch (event.key) {
|
||||
case 'Enter':
|
||||
inputValue = '';
|
||||
cursor.style.transform = `translateX(0px)`;
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
shiftCursor(1);
|
||||
break;
|
||||
case 'ArrowLeft':
|
||||
shiftCursor(0);
|
||||
break;
|
||||
}
|
||||
} */
|
||||
|
||||
setTimeout(() => {
|
||||
locked = false;
|
||||
}, 100);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="relative">
|
||||
<div id="terminal-input"></div>
|
||||
</div>
|
||||
|
||||
<div class=" relative">
|
||||
<input
|
||||
autofocus
|
||||
bind:value={inputValue}
|
||||
onkeydown={(e) => e.key === 'Enter' && (inputValue = '')}
|
||||
oninput={handleInput}
|
||||
onkeydown={(e) => keyDown(e)}
|
||||
onfocus={() => (isFocused = true)}
|
||||
onblur={() => (isFocused = false)}
|
||||
type="text"
|
||||
@@ -44,10 +78,20 @@
|
||||
<div class="w flex-column flex flex-row flex-wrap font-terminal">
|
||||
<span class="pointer pr-2">$</span>
|
||||
<!-- prettier-ignore -->
|
||||
<div style="white-space: preserve;" class=" relative wrap-break-word">{inputValue}</div>
|
||||
<span id="cursor" class={isFocused ? 'animate-cursor-blink' : ''}>_</span>
|
||||
<span style="white-space: preserve;" class=" relative wrap-break-word">
|
||||
{#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>
|
||||
|
||||
<style>
|
||||
.char
|
||||
</style>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { db } from '$lib/server/db';
|
||||
import { config } from '$lib/server/db/schema';
|
||||
import { PASSWD } from '$lib/stores/bash/etc/userData';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import type { Actions, PageServerLoad } from './$types';
|
||||
|
||||
@@ -22,11 +23,16 @@ export const actions = {
|
||||
} satisfies Actions;
|
||||
|
||||
export const load: PageServerLoad = async () => {
|
||||
return {
|
||||
config: await db
|
||||
.select({ config: config.value })
|
||||
try {
|
||||
const rows = await db
|
||||
.select({ value: config.value })
|
||||
.from(config)
|
||||
.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');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
let { form, data } = $props();
|
||||
|
||||
const MAINTENANCE = $derived(Boolean(data.config[0]));
|
||||
let username = $state('');
|
||||
|
||||
function welcomeSequence() {
|
||||
//isWelcomeSequence = true;
|
||||
@@ -16,12 +17,16 @@
|
||||
function initializer(formData: FormData) {
|
||||
console.log(formData);
|
||||
|
||||
username = formData.get('username')?.toString() ?? 'foo';
|
||||
|
||||
if (form?.error) return;
|
||||
/* const password = formData.get('password')?.toString();
|
||||
const username = formData.get('username')?.toString();
|
||||
if (!password || !username) throw new Error('password or username is null or undefined');
|
||||
terminalComponent.init(username, password); */
|
||||
}
|
||||
|
||||
console.log(username);
|
||||
</script>
|
||||
|
||||
{#if MAINTENANCE}
|
||||
@@ -37,7 +42,7 @@
|
||||
<Login init={initializer} {form} />
|
||||
</div>
|
||||
<div id="wrapper2" class=" absolute z-4 size-4/5 opacity-0 {form?.success ? 'intro' : ''}">
|
||||
<Terminal></Terminal>
|
||||
<Terminal {username}></Terminal>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
+19
-17
@@ -1,14 +1,11 @@
|
||||
@theme {
|
||||
--animate-loading: loading 1s ease-in-out 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 {
|
||||
0% {
|
||||
opacity: 0;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,17 +23,22 @@
|
||||
}
|
||||
|
||||
@keyframes shake {
|
||||
10%, 90% {
|
||||
transform: translate3d(-1px, 0, 0);
|
||||
}
|
||||
20%, 80% {
|
||||
transform: translate3d(2px, 0, 0);
|
||||
}
|
||||
30%, 50%, 70% {
|
||||
transform: translate3d(-4px, 0, 0);
|
||||
}
|
||||
40%, 60% {
|
||||
transform: translate3d(4px, 0, 0);
|
||||
}
|
||||
10%,
|
||||
90% {
|
||||
transform: translate3d(-1px, 0, 0);
|
||||
}
|
||||
20%,
|
||||
80% {
|
||||
transform: translate3d(2px, 0, 0);
|
||||
}
|
||||
30%,
|
||||
50%,
|
||||
70% {
|
||||
transform: translate3d(-4px, 0, 0);
|
||||
}
|
||||
40%,
|
||||
60% {
|
||||
transform: translate3d(4px, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user