- Termos library plugged in and partially working
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -73,7 +73,6 @@
|
||||
|
||||
function submit(): void {
|
||||
onsubmit?.(value);
|
||||
value = '';
|
||||
cursorPos = 0;
|
||||
anchorPos = null;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
+66
-74
@@ -1,27 +1,40 @@
|
||||
<script lang="ts">
|
||||
import { rawJson } from '#lib/assets/fs.ts';
|
||||
import Input from '#lib/modules/Input.svelte';
|
||||
import StatusBar from '#lib/modules/StatusBar.svelte';
|
||||
import Terminal from '#lib/modules/Terminal.svelte';
|
||||
import TrayIcon from '#lib/modules/TrayIcon.svelte';
|
||||
import type { MWinAPI } from '#lib/mwinlib/mwin_util.ts';
|
||||
import { ChevronDown, Shell } from '@lucide/svelte';
|
||||
import { mount, unmount } from 'svelte';
|
||||
import { mount, onMount, unmount } from 'svelte';
|
||||
import { resolvePointerToHome, Termos, type Shell } from 'termos';
|
||||
|
||||
function doSmth(e: MouseEvent): void {
|
||||
console.log(e);
|
||||
}
|
||||
const config = {
|
||||
groups: ['users'],
|
||||
users: [
|
||||
{
|
||||
username: 'gornodox',
|
||||
groups: ['users', 'sudoers'],
|
||||
home: '/home/gornodox'
|
||||
}
|
||||
],
|
||||
general: {
|
||||
user: 'gornodox'
|
||||
},
|
||||
filesystem: {
|
||||
json: rawJson
|
||||
}
|
||||
};
|
||||
|
||||
let shell: Shell | undefined = $state();
|
||||
let api: MWinAPI | undefined = $state();
|
||||
|
||||
let value = $state('');
|
||||
let input: Input | undefined = $state();
|
||||
|
||||
let date = $state(new Date());
|
||||
|
||||
let settings = $state(false);
|
||||
|
||||
let wrapper: HTMLElement;
|
||||
let terminalTray: TrayIcon | undefined = $state();
|
||||
let api: MWinAPI | undefined = $state();
|
||||
|
||||
let tray: HTMLElement | undefined = $state();
|
||||
let index: number = $state(0);
|
||||
const trayElements = new Map<number, ReturnType<typeof mount>>();
|
||||
|
||||
//const callbacks = [{ title: 'Open terminal', fn: doSmth }];
|
||||
let index: number = $state(-1);
|
||||
const instances = new Map<number, ReturnType<typeof mount>>();
|
||||
|
||||
function add() {
|
||||
index++;
|
||||
@@ -32,22 +45,23 @@
|
||||
props: {
|
||||
id,
|
||||
wrapper,
|
||||
username: 'gornodox',
|
||||
username: shell!.Session.user.username,
|
||||
hostname: 'termos',
|
||||
working_dir: '~',
|
||||
working_dir: resolvePointerToHome(shell!.State, shell!.Session.user.home),
|
||||
mwin: api,
|
||||
shell,
|
||||
close: remove
|
||||
}
|
||||
});
|
||||
|
||||
trayElements.set(id, terminal);
|
||||
instances.set(id, terminal);
|
||||
}
|
||||
|
||||
function remove(id: number): void {
|
||||
const m = trayElements.get(id);
|
||||
const m = instances.get(id);
|
||||
if (!m) return;
|
||||
unmount(m);
|
||||
trayElements.delete(id);
|
||||
instances.delete(id);
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
@@ -55,61 +69,39 @@
|
||||
date = new Date();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
onMount(async () => {
|
||||
shell = await Termos.getShell(config);
|
||||
|
||||
window.addEventListener('keydown', (e) => {
|
||||
if (e.ctrlKey && e.altKey && e.key === 't') {
|
||||
add();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
class=" fixed top-0 left-0 z-200 m-auto grid h-10 w-full grid-cols-[1fr_auto_1fr] items-center"
|
||||
>
|
||||
<div class="flex flex-row items-center gap-2 pl-3">
|
||||
<button>
|
||||
<Shell size={18} />
|
||||
</button>
|
||||
<div bind:this={tray}></div>
|
||||
</div>
|
||||
<div class=" flex flex-row items-center justify-center px-5">
|
||||
<button>
|
||||
<h2 class="font-primary text-lg">
|
||||
{date.getHours().toString().length > 1 ? date.getHours() : `0${date.getHours()}`}:{date
|
||||
.getMinutes()
|
||||
.toString().length > 1
|
||||
? date.getMinutes()
|
||||
: `0${date.getMinutes()}`}:{date.getSeconds().toString().length > 1
|
||||
? date.getSeconds()
|
||||
: `0${date.getSeconds()}`}
|
||||
</h2>
|
||||
</button>
|
||||
<!-- <div class="-translate-y- fixed top-0 bg-green-700">Calendar, Maybe...</div> -->
|
||||
</div>
|
||||
<div class="fixed right-0 m-auto pr-1">
|
||||
<div
|
||||
class="bg-surface-2 flex flex-row-reverse items-center justify-center gap-3 rounded-full p-2"
|
||||
>
|
||||
<button
|
||||
onclick={() => (settings = !settings)}
|
||||
class="{settings ? 'rotate-180' : 'rotate-0'} transition-transform"
|
||||
>
|
||||
<ChevronDown size={18} />
|
||||
</button>
|
||||
<div class="h-dvh w-full p-4">
|
||||
<div class=" bg-bg-full flex h-full flex-col rounded-md">
|
||||
<div class="absolute top-12 left-1/2 -translate-x-1/2">
|
||||
<span class="text-fg1 inline-flex items-baseline gap-2 font-mono text-sm tracking-[0.02em]">
|
||||
<span class="text-fg3">Ctrl</span>
|
||||
<span class="text-bg4 select-none" aria-hidden="true">+</span>
|
||||
<span class="text-fg3">Alt</span>
|
||||
<span class="text-bg4 select-none" aria-hidden="true">+</span>
|
||||
<span class="text-tyellow font-semibold">T</span>
|
||||
</span>
|
||||
</div>
|
||||
<div bind:this={wrapper} id="terminal-wrapper" class="relative flex flex-1"></div>
|
||||
<div class="bg-bg-soft border-bg3 w-full rounded-b-md border-t text-xs">
|
||||
<StatusBar
|
||||
username="gornodox"
|
||||
theme="gruvbox"
|
||||
windowCount={instances.size}
|
||||
windowTitle="Termos"
|
||||
version="v0.1.1_alpha"
|
||||
hash="a3d5b1c"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="absolute top-10 right-0 h-30 w-40 rounded-xl bg-green-700 transition-transform {settings
|
||||
? 'mr-4 translate-x-0'
|
||||
: 'mr-0 translate-x-full'}"
|
||||
></div>
|
||||
|
||||
<div
|
||||
id="terminal-wrapper"
|
||||
bind:this={wrapper}
|
||||
class=" relative flex h-screen w-full flex-col items-center justify-center overflow-x-hidden"
|
||||
>
|
||||
<Terminal
|
||||
id={10}
|
||||
wrapper="#terminal-wrapper"
|
||||
username="gornodox"
|
||||
hostname="termos"
|
||||
working_dir="~/Documents/Projects/gornodox.dev"
|
||||
mwin={api}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,30 @@
|
||||
<script lang="ts">
|
||||
import { rawJson } from '#lib/assets/fs.ts';
|
||||
import Input from '#lib/modules/Input.svelte';
|
||||
import StatusBar from '#lib/modules/StatusBar.svelte';
|
||||
import Terminal from '#lib/modules/Terminal.svelte';
|
||||
import type { MWinAPI } from '#lib/mwinlib/mwin_util.ts';
|
||||
import { mount, onMount, unmount } from 'svelte';
|
||||
import { resolvePointerToHome, Termos, type Shell } from 'termos';
|
||||
|
||||
const config = {
|
||||
groups: ['users'],
|
||||
users: [
|
||||
{
|
||||
username: 'gornodox',
|
||||
groups: ['users', 'sudoers'],
|
||||
home: '/home/gornodox'
|
||||
}
|
||||
],
|
||||
general: {
|
||||
user: 'gornodox'
|
||||
},
|
||||
filesystem: {
|
||||
json: rawJson
|
||||
}
|
||||
};
|
||||
|
||||
let shell: Shell | undefined = $state();
|
||||
let api: MWinAPI | undefined = $state();
|
||||
|
||||
let value = $state('');
|
||||
@@ -25,10 +45,11 @@
|
||||
props: {
|
||||
id,
|
||||
wrapper,
|
||||
username: 'gornodox',
|
||||
username: shell!.Session.user.username,
|
||||
hostname: 'termos',
|
||||
working_dir: '~/Documents/Projects/gornodox.dev',
|
||||
working_dir: resolvePointerToHome(shell!.State, shell!.Session.user.home),
|
||||
mwin: api,
|
||||
shell,
|
||||
close: remove
|
||||
}
|
||||
});
|
||||
@@ -49,9 +70,11 @@
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
onMount(async () => {
|
||||
shell = await Termos.getShell(config);
|
||||
|
||||
window.addEventListener('keydown', (e) => {
|
||||
if (e.altKey && e.key === 'n') {
|
||||
if (e.ctrlKey && e.altKey && e.key === 't') {
|
||||
add();
|
||||
}
|
||||
});
|
||||
@@ -60,14 +83,23 @@
|
||||
|
||||
<div class="h-dvh w-full p-4">
|
||||
<div class=" bg-bg-full flex h-full flex-col rounded-md">
|
||||
<div class="absolute top-12 left-1/2 -translate-x-1/2">
|
||||
<span class="text-fg1 inline-flex items-baseline gap-2 font-mono text-sm tracking-[0.02em]">
|
||||
<span class="text-fg3">Ctrl</span>
|
||||
<span class="text-bg4 select-none" aria-hidden="true">+</span>
|
||||
<span class="text-fg3">Alt</span>
|
||||
<span class="text-bg4 select-none" aria-hidden="true">+</span>
|
||||
<span class="text-tyellow font-semibold">T</span>
|
||||
</span>
|
||||
</div>
|
||||
<div bind:this={wrapper} id="terminal-wrapper" class="relative flex flex-1"></div>
|
||||
<div class="bg-bg-soft border-bg3 w-full rounded-b-md border-t text-xs">
|
||||
<StatusBar
|
||||
username="gornodox"
|
||||
theme="gruvbox"
|
||||
windowCount={0}
|
||||
windowTitle="Hello, World!"
|
||||
version="v0.0.1_alpha"
|
||||
windowCount={instances.size}
|
||||
windowTitle="Termos"
|
||||
version="v0.1.1_alpha"
|
||||
hash="a3d5b1c"
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user