- Termos library plugged in and partially working

This commit is contained in:
2026-11-20 13:24:06 +01:00
parent baa0d34cf4
commit cae28de874
7 changed files with 975 additions and 123 deletions
File diff suppressed because one or more lines are too long
-1
View File
@@ -73,7 +73,6 @@
function submit(): void {
onsubmit?.(value);
value = '';
cursorPos = 0;
anchorPos = null;
}
+31 -22
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import { type MWinAPI, type MWinParams } from '#lib/mwinlib/mwin_util.ts';
import { resolvePointerToHome, type Shell } from 'termos';
import Input from './Input.svelte';
import Movable from './Movable.svelte';
@@ -10,6 +11,7 @@
hostname = $bindable(),
working_dir = $bindable(),
mwin = $bindable(),
shell = $bindable(),
close
}: {
@@ -19,37 +21,53 @@
hostname: string;
working_dir: string;
mwin: MWinAPI | undefined;
shell: Shell | undefined;
close?: (id: number) => void;
} = $props();
//let isProcessActive = $state(false);
const d = new TextDecoder('utf-8');
let inputValue = $state('');
let inputComponent: any;
let outputWrapper: HTMLElement;
let count: [string, string][] = $state([]);
let scrollDiv: HTMLElement;
let stdout: string = '';
let count: [string, string, string][] = $state([]);
const mwinoptions: Partial<MWinParams> = {
handle: '#terminal-bar',
resizable: { threshold: 10, minWidth: 300, minHeight: 200 },
baseZIndex: 300,
resizeHandle: '#terminal',
onAPI: (api: MWinAPI) => {
mwin = api;
}
};
function onsubmit(value: string) {
if (value === 'clear') {
count = [];
return;
}
console.log(value);
count.push([value, working_dir]);
async function onsubmit(value: string) {
const input = value.trim();
await shell!.execute(input);
scrollDiv.scrollTop = scrollDiv.scrollHeight;
}
$effect(() => {
shell!.on('stdout', (payload) => {
const decoded = d.decode(payload.data);
stdout = stdout + decoded;
});
shell!.on('result', (payload) => {
if (payload.result.type === 'error') {
stdout = stdout + payload.result.error.message + '\n';
}
count.push([inputValue, resolvePointerToHome(shell!.State, shell!.Session.cwd), stdout]);
stdout = '';
inputValue = '';
});
});
</script>
{#snippet Out(value: string, path: string)}
{#snippet Out(value: string, path: string, stdout: string)}
<span
><span class=" scroll-line text-tyellow">{username}</span><span>@</span><span class=" text-fg1"
>{hostname}</span
@@ -57,6 +75,7 @@
<span class="text-bg4">{path}</span><br /></span
>
<span class=" scroll-line mr-[1ch]">$</span><span>{value}</span>
<div class=" whitespace-pre-wrap">{stdout}</div>
{/snippet}
<Movable
@@ -86,7 +105,6 @@
class="bg-term-minimize h-2.5 w-2.5 cursor-pointer rounded-2xl active:brightness-85"
type="button"
aria-label="Minimize terminal"
onclick={() => mwin?.minimize()}
></button>
</div>
<span class=" text-fg2 mx-auto text-sm font-medium">{username} — tsh</span>
@@ -94,6 +112,7 @@
</div>
<div
class="inner-content scroll-hidden text-fg4 font-ibm grow origin-top overflow-y-auto p-4 text-sm"
bind:this={scrollDiv}
id="cout"
onclick={() => inputComponent?.focusInput()}
onkeydown={() => inputComponent?.focusInput()}
@@ -102,7 +121,7 @@
>
<div bind:this={outputWrapper} class="">
{#each count as c}
{@render Out(c[0], c[1])}
{@render Out(c[0], c[1], c[2])}
<div class="mb-3"></div>
{/each}
</div>
@@ -117,13 +136,3 @@
>
</div>
</Movable>
<style>
.inner-content {
scroll-snap-type: y mandatory;
scroll-behavior: auto;
}
.scroll-line {
scroll-snap-align: start;
}
</style>