a lot of "drunk code", processes need rethinking, terminal initializes but commands dont go through to IO
This commit is contained in:
Generated
+10
-10
@@ -1723,9 +1723,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@sveltejs/kit": {
|
"node_modules/@sveltejs/kit": {
|
||||||
"version": "2.53.4",
|
"version": "2.55.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.53.4.tgz",
|
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.55.0.tgz",
|
||||||
"integrity": "sha512-iAIPEahFgDJJyvz8g0jP08KvqnM6JvdW8YfsygZ+pMeMvyM2zssWMltcsotETvjSZ82G3VlitgDtBIvpQSZrTA==",
|
"integrity": "sha512-MdFRjevVxmAknf2NbaUkDF16jSIzXMWd4Nfah0Qp8TtQVoSp3bV4jKt8mX7z7qTUTWvgSaxtR0EG5WJf53gcuA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1734,7 +1734,7 @@
|
|||||||
"@types/cookie": "^0.6.0",
|
"@types/cookie": "^0.6.0",
|
||||||
"acorn": "^8.14.1",
|
"acorn": "^8.14.1",
|
||||||
"cookie": "^0.6.0",
|
"cookie": "^0.6.0",
|
||||||
"devalue": "^5.6.3",
|
"devalue": "^5.6.4",
|
||||||
"esm-env": "^1.2.2",
|
"esm-env": "^1.2.2",
|
||||||
"kleur": "^4.1.5",
|
"kleur": "^4.1.5",
|
||||||
"magic-string": "^0.30.5",
|
"magic-string": "^0.30.5",
|
||||||
@@ -2971,9 +2971,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/devalue": {
|
"node_modules/devalue": {
|
||||||
"version": "5.6.3",
|
"version": "5.6.4",
|
||||||
"resolved": "https://registry.npmjs.org/devalue/-/devalue-5.6.3.tgz",
|
"resolved": "https://registry.npmjs.org/devalue/-/devalue-5.6.4.tgz",
|
||||||
"integrity": "sha512-nc7XjUU/2Lb+SvEFVGcWLiKkzfw8+qHI7zn8WYXKkLMgfGSHbgCEaR6bJpev8Cm6Rmrb19Gfd/tZvGqx9is3wg==",
|
"integrity": "sha512-Gp6rDldRsFh/7XuouDbxMH3Mx8GMCcgzIb1pDTvNyn8pZGQ22u+Wa+lGV9dQCltFQ7uVw0MhRyb8XDskNFOReA==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/dom-accessibility-api": {
|
"node_modules/dom-accessibility-api": {
|
||||||
@@ -3590,9 +3590,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/flatted": {
|
"node_modules/flatted": {
|
||||||
"version": "3.3.3",
|
"version": "3.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.1.tgz",
|
||||||
"integrity": "sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg==",
|
"integrity": "sha512-IxfVbRFVlV8V/yRaGzk0UVIcsKKHMSfYw66T/u4nTwlWteQePsxe//LjudR1AMX4tZW3WFCh3Zqa/sjlqpbURQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
|||||||
+63
-10
@@ -5,6 +5,13 @@ import { PASSWD, type User } from './etc/userData';
|
|||||||
import { ExitCode } from './metadata';
|
import { ExitCode } from './metadata';
|
||||||
import { COMMANDS, type CommandArgs, type CommandResultData, type ICommand } from './commandRegistry';
|
import { COMMANDS, type CommandArgs, type CommandResultData, type ICommand } from './commandRegistry';
|
||||||
import { GROUP, type Group } from './etc/groupData';
|
import { GROUP, type Group } from './etc/groupData';
|
||||||
|
import { Process } from './process';
|
||||||
|
import type { KeybindInhibitor } from './keybindInhibitor';
|
||||||
|
|
||||||
|
export enum Signal {
|
||||||
|
SIGINT,
|
||||||
|
SIGKILL
|
||||||
|
}
|
||||||
|
|
||||||
export type BashInitArgs = {
|
export type BashInitArgs = {
|
||||||
io?: Terminal;
|
io?: Terminal;
|
||||||
@@ -19,14 +26,18 @@ export type Result = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class Bash {
|
export class Bash {
|
||||||
private vfs: VirtualFS;
|
private readonly vfs: VirtualFS;
|
||||||
private _passwd: User[];
|
private readonly _passwd: User[];
|
||||||
private _userInstances: Stack<User>;
|
private readonly _group: Group[];
|
||||||
private _group: Group[];
|
private readonly _terminal!: Terminal;
|
||||||
private _terminal!: Terminal;
|
|
||||||
private user: User;
|
|
||||||
private readonly _commands: Record<string, ICommand>;
|
private readonly _commands: Record<string, ICommand>;
|
||||||
|
|
||||||
|
private _userInstances: Stack<User>;
|
||||||
|
|
||||||
|
private user: User;
|
||||||
|
private _process?: Process;
|
||||||
|
|
||||||
|
|
||||||
constructor(args: BashInitArgs) {
|
constructor(args: BashInitArgs) {
|
||||||
this._commands = COMMANDS;
|
this._commands = COMMANDS;
|
||||||
this._passwd = PASSWD;
|
this._passwd = PASSWD;
|
||||||
@@ -54,6 +65,16 @@ export class Bash {
|
|||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _initNewProcess(command: ICommand, args: CommandArgs) {
|
||||||
|
this._process = new Process(
|
||||||
|
this,
|
||||||
|
this.user.uid,
|
||||||
|
'TEMP PROCESS NAME',
|
||||||
|
command,
|
||||||
|
args
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private _appendNewResult(inode: number, output: any, cmd: string) {
|
private _appendNewResult(inode: number, output: any, cmd: string) {
|
||||||
const data: PrintData = {
|
const data: PrintData = {
|
||||||
path: this.vfs.formatPath(this.vfs.getPathByInode(inode)),
|
path: this.vfs.formatPath(this.vfs.getPathByInode(inode)),
|
||||||
@@ -94,6 +115,20 @@ export class Bash {
|
|||||||
return this.vfs;
|
return this.vfs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getProcess(): Process | ExitCode.ERROR {
|
||||||
|
if(this._process) {
|
||||||
|
return this._process;
|
||||||
|
}
|
||||||
|
return ExitCode.ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
getProcessKeybindInhibitor(): KeybindInhibitor | null {
|
||||||
|
if(this._process) {
|
||||||
|
return this._process.getKeybindInhibitor();
|
||||||
|
}
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
getTerminalWidth(): number {
|
getTerminalWidth(): number {
|
||||||
return this._terminal.getTerminalWidth();
|
return this._terminal.getTerminalWidth();
|
||||||
}
|
}
|
||||||
@@ -106,22 +141,40 @@ export class Bash {
|
|||||||
return this._group[1].members.includes(uid);
|
return this._group[1].members.includes(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
async executeCommand(commandName: string, args: CommandArgs) {
|
async executeCommand(commandName: string, args: CommandArgs): Promise<Result> {
|
||||||
let result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd() };
|
let result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd() };
|
||||||
const command = this._commands[commandName];
|
const command: ICommand = this._commands[commandName];
|
||||||
|
|
||||||
if (!command) this.throwError(result);
|
if (!command) this.throwError(result);
|
||||||
|
|
||||||
if (command.root) {
|
if (command.root) {
|
||||||
if (this.hasSudoPerms(this.user.uid)) {
|
if (this.hasSudoPerms(this.user.uid)) {
|
||||||
let out: Result = command.method.call(this, args);
|
await this._initNewProcess(command, args);
|
||||||
|
if(!this._process) throw new Error('failed to init new process');
|
||||||
|
|
||||||
|
const out: Result = await this._process.getResult();
|
||||||
this._appendNewResult(this.getCwd(), out, this.user.history[0]);
|
this._appendNewResult(this.getCwd(), out, this.user.history[0]);
|
||||||
}
|
}
|
||||||
this.throwError(result);
|
this.throwError(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
let out: Result = command.method.call(this, args);
|
await this._initNewProcess(command, args);
|
||||||
|
if(!this._process) throw new Error('failed to init new process');
|
||||||
|
|
||||||
|
const out: Result = await this._process.getResult();
|
||||||
console.log(out);
|
console.log(out);
|
||||||
this._appendNewResult(out.path, out.resultData?.data, this.user.history[0]);
|
this._appendNewResult(out.path, out.resultData?.data, this.user.history[0]);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
processKill(): ExitCode {
|
||||||
|
if(this._process) {
|
||||||
|
return this._process.sigKill(() => {console.log("process Kill successfull")});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return ExitCode.SUCCESS; //Temp need to make custom enum value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throwError(result: Result): void {
|
throwError(result: Result): void {
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
|
import type { KeyBind } from "../terminal/keybindRegistry";
|
||||||
import type { Bash, Result } from "./bash";
|
import type { Bash, Result } from "./bash";
|
||||||
import { cd } from "./commands/cd";
|
import { cd } from "./commands/cd";
|
||||||
import { clear } from "./commands/clear";
|
import { clear } from "./commands/clear";
|
||||||
import { ls } from "./commands/ls";
|
import { ls } from "./commands/ls";
|
||||||
|
import { aSync } from "./commands/testAsync";
|
||||||
|
|
||||||
export type ICommand = {
|
export type ICommand = {
|
||||||
method: (this: Bash, args: CommandArgs) => Result;
|
method: (this: Bash, args: CommandArgs) => Promise<Result>;
|
||||||
|
keybinds?: Map<KeyBind, () => any>;
|
||||||
flags: string[];
|
flags: string[];
|
||||||
help: string;
|
help: string;
|
||||||
root: boolean;
|
root: boolean;
|
||||||
@@ -24,7 +27,8 @@ export type CommandResultData = {
|
|||||||
export const COMMANDS = {
|
export const COMMANDS = {
|
||||||
cd,
|
cd,
|
||||||
ls,
|
ls,
|
||||||
clear
|
clear,
|
||||||
|
aSync
|
||||||
} as const satisfies Record<string, ICommand>;
|
} as const satisfies Record<string, ICommand>;
|
||||||
|
|
||||||
/* //export const commands {
|
/* //export const commands {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const months: readonly string[] = [
|
|||||||
'Dec'
|
'Dec'
|
||||||
];
|
];
|
||||||
|
|
||||||
export const cmd_ls = function (this: Bash, args: CommandArgs): Result {
|
export const cmd_ls = async function (this: Bash, args: CommandArgs): Promise<Result> {
|
||||||
const Fs = this.getFs();
|
const Fs = this.getFs();
|
||||||
const resultData: CommandResultData = { cmd: 'ls', data: null, args: args };
|
const resultData: CommandResultData = { cmd: 'ls', data: null, args: args };
|
||||||
const result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd(), resultData: resultData };
|
const result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd(), resultData: resultData };
|
||||||
@@ -72,10 +72,8 @@ export const cmd_ls = function (this: Bash, args: CommandArgs): Result {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement {
|
function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement {
|
||||||
const dummysonoerror: HTMLElement = document.createElement('div');
|
|
||||||
const Fs: VirtualFS = this.getFs();
|
const Fs: VirtualFS = this.getFs();
|
||||||
|
|
||||||
|
|
||||||
const flagInfo = checkFlags(args.flags);
|
const flagInfo = checkFlags(args.flags);
|
||||||
const nodes: TreeNode[] = data;
|
const nodes: TreeNode[] = data;
|
||||||
let nodeIndex: number = 0;
|
let nodeIndex: number = 0;
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import type { KeyBind } from "$lib/stores/terminal/keybindRegistry";
|
||||||
|
import { type Bash, type Result } from "../bash";
|
||||||
|
import type { CommandArgs, ICommand } from "../commandRegistry";
|
||||||
|
import { ExitCode } from "../metadata";
|
||||||
|
|
||||||
|
export const cmd_async = async function(this: Bash, args: CommandArgs): Promise<Result> {
|
||||||
|
let result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd() };
|
||||||
|
|
||||||
|
|
||||||
|
result.exitCode = ExitCode.SUCCESS;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const test_keybind: KeyBind = [
|
||||||
|
{
|
||||||
|
key: 'a',
|
||||||
|
modifiers: [
|
||||||
|
'Shift'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
function test(): void {
|
||||||
|
console.log("Keybind works");
|
||||||
|
}
|
||||||
|
|
||||||
|
const keybinds: Map<KeyBind, () => any> = new Map([
|
||||||
|
[test_keybind,test]
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const aSync: ICommand = {
|
||||||
|
method: cmd_async,
|
||||||
|
keybinds: keybinds,
|
||||||
|
flags: [] as string[],
|
||||||
|
help: 'PATH TO HELP.md',
|
||||||
|
root: false
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import type { KeyBind, Modifier } from "../terminal/keybindRegistry";
|
||||||
|
|
||||||
|
|
||||||
|
export class KeybindInhibitor{
|
||||||
|
private _keybinds: Map<KeyBind, () => any>;
|
||||||
|
|
||||||
|
constructor(keybinds: Map<KeyBind, () => any>) {
|
||||||
|
this._keybinds = keybinds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private parseModifierStates(event: KeyboardEvent): Modifier[] | undefined {
|
||||||
|
const mods: Modifier[] = [];
|
||||||
|
|
||||||
|
if(event.altKey) mods.push('Alt');
|
||||||
|
if(event.ctrlKey) mods.push('Ctrl');
|
||||||
|
if(event.shiftKey) mods.push('Shift');
|
||||||
|
|
||||||
|
if(mods.length == 0) return undefined;
|
||||||
|
|
||||||
|
return mods;
|
||||||
|
}
|
||||||
|
|
||||||
|
processKeystroke(event: KeyboardEvent) {
|
||||||
|
const keybind: KeyBind = [
|
||||||
|
{
|
||||||
|
key: event.key,
|
||||||
|
modifiers: this.parseModifierStates(event)
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const out = this._keybinds.get(keybind);
|
||||||
|
if(out) out();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import type { Bash, Result } from "./bash";
|
||||||
|
import type { CommandArgs, ICommand } from "./commandRegistry";
|
||||||
|
import { KeybindInhibitor } from "./keybindInhibitor";
|
||||||
|
import { ExitCode } from "./metadata";
|
||||||
|
|
||||||
|
export class Process {
|
||||||
|
|
||||||
|
private _bash: Bash;
|
||||||
|
private _result: Result;
|
||||||
|
private _uid: number;
|
||||||
|
private _name: string;
|
||||||
|
private _initTimestamp: Date;
|
||||||
|
private _keybindInhibitor?: KeybindInhibitor;
|
||||||
|
private _abortController: AbortController;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
_bashInstance: Bash,
|
||||||
|
uid: number,
|
||||||
|
name: string,
|
||||||
|
command: ICommand,
|
||||||
|
args: CommandArgs
|
||||||
|
) {
|
||||||
|
this._bash = _bashInstance;
|
||||||
|
this._result = { exitCode: ExitCode.ERROR, path: this._bash.getCwd() }
|
||||||
|
this._uid = uid;
|
||||||
|
this._name = name;
|
||||||
|
this._initTimestamp = new Date();
|
||||||
|
this._abortController = new AbortController();
|
||||||
|
|
||||||
|
if(command.keybinds) {
|
||||||
|
this._keybindInhibitor = new KeybindInhibitor(command.keybinds);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._Run(command, _bashInstance, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getKeybindInhibitor(): KeybindInhibitor | null {
|
||||||
|
if(this._keybindInhibitor) {
|
||||||
|
return this._keybindInhibitor;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sigKill(callback: () => void): ExitCode {
|
||||||
|
this._abortController.abort();
|
||||||
|
callback();
|
||||||
|
|
||||||
|
return ExitCode.SUCCESS //Only temp, need to add ExitCode.INT
|
||||||
|
}
|
||||||
|
|
||||||
|
public getUid(): number {
|
||||||
|
return this._uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getInitTime(): Date {
|
||||||
|
return this._initTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getName(): string {
|
||||||
|
return this._name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getResult(): Promise<Result> {
|
||||||
|
return this._result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _Run(command: ICommand, bashInstance: Bash, args: CommandArgs) {
|
||||||
|
this._result = await command.method.call(
|
||||||
|
bashInstance, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
export type Modifier = 'Ctrl' | 'Alt' | 'Shift';
|
||||||
|
|
||||||
|
type KeyStroke = {
|
||||||
|
key: string;
|
||||||
|
modifiers?: Modifier[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type KeyBind = [KeyStroke] | [KeyStroke, KeyStroke];
|
||||||
|
|
||||||
|
const sigint: KeyBind = [{
|
||||||
|
key: 'c',
|
||||||
|
modifiers: ['Ctrl']
|
||||||
|
}];
|
||||||
|
|
||||||
|
export const TERMINAL_KEYBINDS = {
|
||||||
|
sigint
|
||||||
|
} as const satisfies Record<string, KeyBind>;
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
export interface KeyStroke {
|
|
||||||
keys: KeyboardEvent[];
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
import { Bash, type BashInitArgs } from '../bash/bash';
|
import { Bash, Signal, type BashInitArgs, type Result } from '../bash/bash';
|
||||||
import type { CommandArgs } from '../bash/commandRegistry';
|
import type { CommandArgs } from '../bash/commandRegistry';
|
||||||
import type { User } from '../bash/etc/userData';
|
import type { User } from '../bash/etc/userData';
|
||||||
import { VirtualFS, type TreeNode } from '../bash/fs';
|
import { VirtualFS, type TreeNode } from '../bash/fs';
|
||||||
import type { ExitCode } from '../bash/metadata';
|
import { KeybindInhibitor } from '../bash/keybindInhibitor';
|
||||||
|
import { ExitCode } from '../bash/metadata';
|
||||||
|
import type { Process } from '../bash/process';
|
||||||
|
import { TERMINAL_KEYBINDS, type KeyStroke } from './keybindRegistry';
|
||||||
//import type { ILocale } from './localeRegistry';
|
//import type { ILocale } from './localeRegistry';
|
||||||
|
|
||||||
export type TerminalMode = {};
|
export type TerminalMode = {};
|
||||||
@@ -33,16 +36,35 @@ export type PageCallbacks = {
|
|||||||
export class Terminal {
|
export class Terminal {
|
||||||
private _bash: Bash;
|
private _bash: Bash;
|
||||||
private _callbacks: Partial<PageCallbacks> = {};
|
private _callbacks: Partial<PageCallbacks> = {};
|
||||||
|
private _keybindInhibitor: KeybindInhibitor;
|
||||||
//public locale: ILocale;
|
//public locale: ILocale;
|
||||||
|
|
||||||
constructor(args: TermInitArgs) {
|
constructor(args: TermInitArgs) {
|
||||||
args.bash.io = this;
|
args.bash.io = this;
|
||||||
this._bash = new Bash(args.bash);
|
this._bash = new Bash(args.bash);
|
||||||
|
|
||||||
|
const keybinds: Map<KeyStroke, () => any> = new Map([
|
||||||
|
[TERMINAL_KEYBINDS.sigint,this._processKill]
|
||||||
|
]);
|
||||||
|
|
||||||
|
this._keybindInhibitor = new KeybindInhibitor(keybinds);
|
||||||
|
|
||||||
//this.locale = args.locale;
|
//this.locale = args.locale;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _processKill(): ExitCode {
|
||||||
|
const get: Process | ExitCode = this._bash.getProcess();
|
||||||
|
if(get == ExitCode.ERROR) return ExitCode.ERROR;
|
||||||
|
|
||||||
|
const process: Process = get;
|
||||||
|
const result = process.sigKill(() => {
|
||||||
|
console.log("process kill successful");
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private _parseInput(input: string): ParsedInput {
|
private _parseInput(input: string): ParsedInput {
|
||||||
let args: string[] = [];
|
let args: string[] = [];
|
||||||
const result: ParsedInput = { command: '', args: { flags: [], args: [] } };
|
const result: ParsedInput = { command: '', args: { flags: [], args: [] } };
|
||||||
@@ -100,11 +122,12 @@ export class Terminal {
|
|||||||
console.error(message, exitCode);
|
console.error(message, exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
executeCommand(input: string): void {
|
executeCommand(input: string): Promise<Result> {
|
||||||
this._bash.updateHistory(input);
|
this._bash.updateHistory(input);
|
||||||
const parsed: ParsedInput = this._parseInput(input);
|
const parsed: ParsedInput = this._parseInput(input);
|
||||||
console.log(parsed, 'executeCommand output');
|
//console.log(parsed, 'executeCommand output');
|
||||||
this._bash.executeCommand(parsed.command, parsed.args);
|
|
||||||
|
return this._bash.executeCommand(parsed.command, parsed.args);
|
||||||
}
|
}
|
||||||
|
|
||||||
registerCallbacks(callbacks: PageCallbacks): void {
|
registerCallbacks(callbacks: PageCallbacks): void {
|
||||||
@@ -115,6 +138,27 @@ export class Terminal {
|
|||||||
this._callbacks.clear?.();
|
this._callbacks.clear?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPrimaryKeybindInhibitor(): KeybindInhibitor {
|
||||||
|
const processKeybinds: KeybindInhibitor | null =
|
||||||
|
this._bash.getProcessKeybindInhibitor();
|
||||||
|
if(processKeybinds) {
|
||||||
|
return processKeybinds;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return this._keybindInhibitor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getProcessKeyInhibitor(): KeybindInhibitor | ExitCode.ERROR {
|
||||||
|
const out = this._bash.getProcessKeybindInhibitor();
|
||||||
|
if(out) return out;
|
||||||
|
else return ExitCode.ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
getKeybindInhibitor(): KeybindInhibitor {
|
||||||
|
return this._keybindInhibitor;
|
||||||
|
}
|
||||||
|
|
||||||
getUser(): User {
|
getUser(): User {
|
||||||
return this._bash.getUser();
|
return this._bash.getUser();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
let {init, form}: { init: (formData: FormData) => void, form: any} = $props();
|
let {init, form}: { init: (formData: FormData) => void, form: any} = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="wrapper" class=" opacity-0 flex flex-col items-center" class:outro={form?.success}>
|
<div id="wrapper" class=" flex flex-col items-center" class:outro={form?.success}>
|
||||||
<img class="rounded-full mb-4 border-primary-dark border-2" src="/src/lib/assets/login-avatar.png" alt="" width="80" height="80" />
|
<img class="rounded-full mb-4 border-primary-dark border-2" src="/src/lib/assets/login-avatar.png" alt="" width="80" height="80" />
|
||||||
<div id="name" class="flex flex-row items-center text-text-muted-dark justify-center gap-4">
|
<div id="name" class="flex flex-row items-center text-text-muted-dark justify-center gap-4">
|
||||||
<strong>gornodox</strong>
|
<strong>gornodox</strong>
|
||||||
@@ -35,10 +35,6 @@
|
|||||||
animation: fadeIn 0.2s forwards cubic-bezier(.4,.7,0,.99);
|
animation: fadeIn 0.2s forwards cubic-bezier(.4,.7,0,.99);
|
||||||
}
|
}
|
||||||
|
|
||||||
#wrapper {
|
|
||||||
animation: fadeIn 0.5s forwards cubic-bezier(.4,.7,0,.99) 1s;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes fadeIn {
|
@keyframes fadeIn {
|
||||||
to {
|
to {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import { initTerminal, isInitializing } from '$lib/stores/terminal/init.svelte';
|
import { initTerminal, isInitializing } from '$lib/stores/terminal/init.svelte';
|
||||||
import { clear, print } from '$lib/stores/terminal/stdio/io';
|
import { clear, print } from '$lib/stores/terminal/stdio/io';
|
||||||
import type { User } from '$lib/stores/bash/etc/userData';
|
import type { User } from '$lib/stores/bash/etc/userData';
|
||||||
|
import { ExitCode } from '$lib/stores/bash/metadata';
|
||||||
|
|
||||||
const clearTerminal = (): void => clear();
|
const clearTerminal = (): void => clear();
|
||||||
|
|
||||||
@@ -49,6 +50,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function inputHandler(event: KeyboardEvent) {
|
function inputHandler(event: KeyboardEvent) {
|
||||||
|
const terminalKeyInhibitor = terminal.getKeybindInhibitor();
|
||||||
|
terminalKeyInhibitor.processKeystroke(event);
|
||||||
|
|
||||||
|
const processKeyInhibitor = terminal.getProcessKeyInhibitor();
|
||||||
|
if(processKeyInhibitor != ExitCode.ERROR) {
|
||||||
|
processKeyInhibitor.processKeystroke(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(processKeyInhibitor, terminalKeyInhibitor);
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case 'Enter': {
|
case 'Enter': {
|
||||||
terminal.executeCommand(inputValue);
|
terminal.executeCommand(inputValue);
|
||||||
|
|||||||
+12
-1
@@ -39,17 +39,28 @@
|
|||||||
<div id="wrapper1" class=" absolute z-5 flex flex-col items-center {form?.success ? 'outro' : ''}">
|
<div id="wrapper1" class=" absolute z-5 flex flex-col items-center {form?.success ? 'outro' : ''}">
|
||||||
<Login init={initializer} form={form}/>
|
<Login init={initializer} form={form}/>
|
||||||
</div>
|
</div>
|
||||||
<div id="wrapper2" class=" size-4/5 absolute z-4 {form?.success ? 'intro' : ''}">
|
<div id="wrapper2" class=" opacity-0 size-4/5 absolute z-4 {form?.success ? 'intro' : ''}">
|
||||||
<Terminal bind:this={terminalComponent} />
|
<Terminal bind:this={terminalComponent} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
.intro {
|
||||||
|
animation: fadeIn 0.5s forwards cubic-bezier(.4,.7,0,.99) 1s;
|
||||||
|
}
|
||||||
|
|
||||||
.outro {
|
.outro {
|
||||||
animation: fadeOut 0.5s forwards cubic-bezier(.4,.7,0,.99) 1s;
|
animation: fadeOut 0.5s forwards cubic-bezier(.4,.7,0,.99) 1s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes fadeIn {
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes fadeOut {
|
@keyframes fadeOut {
|
||||||
to {
|
to {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user