148 lines
3.9 KiB
Svelte
148 lines
3.9 KiB
Svelte
<script lang="ts">
|
|
import { movable } from '$lib/movable/movable_controller.svelte';
|
|
import type { MovableAPI } from '$lib/movable/util';
|
|
import Input from './terminal/Input.svelte';
|
|
|
|
let { username }: { username: string } = $props();
|
|
|
|
export async function init(username: string, password: string) {
|
|
try {
|
|
//await initTerminal({ username, password }, callbackInit, 'en_US');
|
|
updateTerminal(); //Rename this
|
|
} catch (error) {
|
|
console.error('Failed to intialize the terminal', error);
|
|
}
|
|
|
|
document.getElementById('terminal-window')?.classList.remove('hidden');
|
|
}
|
|
|
|
function updateTerminal() {
|
|
//isProcessActive = terminal.isProcessActive;
|
|
//username = terminal!.getUser().username;
|
|
//cwd = terminal!.getCwd();
|
|
}
|
|
|
|
function getWidth() {
|
|
const e = document.getElementById('cout');
|
|
if (!e) {
|
|
throw new Error('cant get width of the teminal element. Its null');
|
|
}
|
|
//gets an int from padding property value (which is a string) by cutting last 2 letters "px" and parsing to int
|
|
const padding: number = parseInt(
|
|
window.getComputedStyle(e, null).getPropertyValue('padding').slice(0, -2)
|
|
);
|
|
return e.clientWidth - padding * 2;
|
|
}
|
|
|
|
function getFontSize() {
|
|
const e = document.getElementById('cout');
|
|
if (!e) {
|
|
throw new Error('cant get font size of the terminal element. its null');
|
|
}
|
|
|
|
const canvas = document.createElement('canvas');
|
|
const ctx = canvas.getContext('2d')!;
|
|
ctx.font = `${window.getComputedStyle(e, null).getPropertyValue('font-size')} 'JetBrains Mono', monospace;`;
|
|
return ctx.measureText('M').width;
|
|
}
|
|
|
|
let cwd: string = $state('');
|
|
const hostname = 'terminal'; //TODO: Change this to pull from config on db
|
|
//let isProcessActive = $state(false);
|
|
|
|
let movableAPI: MovableAPI;
|
|
let inputValue = $state('');
|
|
</script>
|
|
|
|
<div
|
|
class="terminal-wrapper relative flex h-screen w-1/2 flex-col items-center justify-center bg-red-400"
|
|
>
|
|
<div
|
|
class="absolute flex size-full h-256 w-512 flex-col rounded-md shadow-subtle transition-discrete will-change-auto"
|
|
use:movable={{
|
|
wrapper: '.terminal-wrapper',
|
|
handle: '.terminal-bar',
|
|
baseZIndex: 10,
|
|
resizable: { threshold: 24, minWidth: 500, minHeight: 300 },
|
|
onAPI: (api) => (movableAPI = api)
|
|
}}
|
|
>
|
|
<div
|
|
class="terminal-bar flex h-9 w-full flex-row items-center rounded-t-md bg-surface-2 text-center font-terminal text-sm font-bold text-primary select-none"
|
|
>
|
|
<div class="dots-wrapper mx-3 flex h-full flex-row items-center justify-center gap-3">
|
|
<button
|
|
class="size-3 cursor-pointer rounded-full p-0"
|
|
title=""
|
|
onclick={() => movableAPI.close()}
|
|
></button>
|
|
<button
|
|
class="size-3 cursor-pointer rounded-full p-0"
|
|
title=""
|
|
onclick={() => movableAPI.maximize()}
|
|
></button>
|
|
<button
|
|
class="size-3 cursor-pointer rounded-full p-0"
|
|
title=""
|
|
onclick={() => movableAPI.minimize()}
|
|
></button>
|
|
</div>
|
|
<div class=" mr-2 flex grow text-sm">
|
|
<p>{username}@{hostname} {cwd}</p>
|
|
</div>
|
|
</div>
|
|
<div
|
|
class="inner-content scroll-hidden grow origin-top overflow-y-auto rounded-b-md bg-surface-1 p-4 text-sm text-text-primary"
|
|
id="cout"
|
|
>
|
|
<div id="outputWrapper"></div>
|
|
<Input bind:value={inputValue} blinkDelay={500} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
* {
|
|
transition: var(--transition-standard);
|
|
}
|
|
@keyframes fadeIn {
|
|
from {
|
|
opacity: 0;
|
|
display: none;
|
|
}
|
|
to {
|
|
opacity: 1;
|
|
display: block;
|
|
}
|
|
}
|
|
.dots-wrapper {
|
|
& > button {
|
|
border: none;
|
|
&:hover {
|
|
transform: translateY(-0.1rem);
|
|
}
|
|
&:active {
|
|
transform: translate(0);
|
|
}
|
|
&:nth-child(1) {
|
|
background-color: rgb(255, 0, 0);
|
|
&:active {
|
|
background-color: rgb(255, 100, 100);
|
|
}
|
|
}
|
|
&:nth-child(2) {
|
|
background-color: rgb(255, 165, 0);
|
|
&:active {
|
|
background-color: rgb(255, 215, 50);
|
|
}
|
|
}
|
|
&:nth-child(3) {
|
|
background-color: rgb(50, 205, 50);
|
|
&:active {
|
|
background-color: rgb(100, 255, 100);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</style>
|