Bash and IO working, basic error setup. Changelog:
Commands:
- ls (only with -l)
- cd (basic, probably unfinished)
This commit is contained in:
41
src/lib/stores/terminal/stdio.ts
Normal file
41
src/lib/stores/terminal/stdio.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { mount, unmount } from 'svelte';
|
||||
import Output from '../../../modules/terminal/Output.svelte';
|
||||
import { isInitializing } from './init.svelte';
|
||||
import type { PrintData } from './terminal';
|
||||
|
||||
interface OutputProps {
|
||||
path: string;
|
||||
output: any;
|
||||
cmd: string;
|
||||
}
|
||||
|
||||
const outputInstances = new Set<Output>();
|
||||
|
||||
function appendOutput(container: HTMLElement, props: OutputProps): Output | undefined {
|
||||
if (!container) return;
|
||||
const instance = mount(Output, {
|
||||
target: container,
|
||||
props
|
||||
});
|
||||
|
||||
outputInstances.add(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
export function print(e: HTMLElement, data: PrintData): void {
|
||||
if (isInitializing()) {
|
||||
console.error('Terminal is initializing! Skipping Print');
|
||||
return;
|
||||
}
|
||||
appendOutput(e, {
|
||||
path: data.path,
|
||||
output: data.output,
|
||||
cmd: data.cmd
|
||||
});
|
||||
}
|
||||
|
||||
export function clear(): void {
|
||||
for (const n of outputInstances) {
|
||||
unmount(n);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user