From dc706d6262569c838572fbf045daf2fd66d97f0b Mon Sep 17 00:00:00 2001 From: binekrasik Date: Wed, 15 Apr 2026 11:40:45 +0200 Subject: [PATCH] chore: fix chrome --- package.json | 4 ++-- src/app.ts | 6 ++++++ src/fs/Directory.ts | 9 +++++++++ src/fs/File.ts | 42 ++++++++++++++++++++++++++++++++++++++++ src/program/Info.ts | 21 +++++--------------- src/program/Ls.ts | 16 +++++++++++++++ src/program/Program.ts | 2 +- src/shell/Shell.ts | 2 ++ src/shell/Wush.ts | 17 +++++++++------- src/terminal/Terminal.ts | 25 ++++++++++++++++++------ 10 files changed, 112 insertions(+), 32 deletions(-) create mode 100644 src/fs/Directory.ts create mode 100644 src/fs/File.ts create mode 100644 src/program/Ls.ts diff --git a/package.json b/package.json index d8bb111..6e7b5e7 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,9 @@ }, "devDependencies": { "typescript": "~5.9.3", - "vite": "^8.0.1" + "vite": "^8.0.8" }, "dependencies": { - "sass": "^1.98.0" + "sass": "^1.99.0" } } diff --git a/src/app.ts b/src/app.ts index 233333e..cbf98a6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -3,6 +3,12 @@ import { Wush } from './shell/Wush' import { Terminal } from './terminal/Terminal' import { EventBroadcaster } from './utils/EventBroadcaster' +export const WEBSHELL_VERSION = "0.1.0" + +let CurrentTerminal: Terminal +export const SetCurrentTerminal = (terminal: Terminal) => CurrentTerminal = terminal +export const GetCurrentTerminal = (): Terminal => CurrentTerminal + // Initializes the app const init = () => { const localBroadcaster = new EventBroadcaster() diff --git a/src/fs/Directory.ts b/src/fs/Directory.ts new file mode 100644 index 0000000..36277b8 --- /dev/null +++ b/src/fs/Directory.ts @@ -0,0 +1,9 @@ +export class Directory { + readonly path: string + + constructor(path: string) { + this.path = path + + console.log(this.path.split('/')) + } +} diff --git a/src/fs/File.ts b/src/fs/File.ts new file mode 100644 index 0000000..b7a0bcb --- /dev/null +++ b/src/fs/File.ts @@ -0,0 +1,42 @@ +import { Directory } from "./Directory" + +export class File { + readonly location: Directory + readonly name: string + readonly path: string + private data: any + + constructor(path: string) { + this.path = path + const match = path.match(/^(\/[^\/]*)+\/?$/gm) + + if (!match) + throw new SyntaxError("Bad filepath") + + this.location = new Directory(match[0]) + this.name = match[1] + + new Directory(path) + + console.log(this.location) + console.log(this.name) + } + + Exists(): boolean { + return window.localStorage.getItem(this.path) !== null && window.localStorage.getItem(this.path) !== undefined + } + + Remove() { + window.localStorage.removeItem(this.path) + } + + Write(data: any) { + this.data = data + + window.localStorage.setItem(this.path, JSON.stringify(this)) + } + + Read(): any { + return this.data + } +} diff --git a/src/program/Info.ts b/src/program/Info.ts index 23ed7a1..ca221cc 100644 --- a/src/program/Info.ts +++ b/src/program/Info.ts @@ -1,24 +1,13 @@ +import { GetCurrentTerminal, WEBSHELL_VERSION } from '../app' +import { Terminal } from '../terminal/Terminal' import type { SimpleStream } from '../utils/SimpleStream' import { Program } from './Program' export class Info extends Program { async Exec(_: SimpleStream, stdout: SimpleStream, __: string[]): Promise { - const art = `++++++++++++++++++++++++++++++\n++++++++++++++++++++++++++++++\n++++++++++++++++++++++++++++++\n++++++++++++++++++++++++++++++\n++++++++++++++++++++++++++++++\n++++++++++++++++++++++++++++++\n+++++++++++++++++++++;..:+++++\n++++ ++ +++\n++++++++. +++++ +++++++++\n++++++++. +++++: ++++++++\n++++++++. ++++++; ++++\n++++++++. ++++++++++. +++\n++++++++. +++++.++++++ ;++\n++++++++. +++++ +++\n++++++++;...++++++; ;+++++\n++++++++++++++++++++++++++++++` - - const modules = [ - { text: "" }, - { text: "" }, - { text: "" }, - { text: "" }, - { text: "" }, - ] - - const lines = art.split("\n") - const padding = Math.floor((lines.length - modules.length) / 2) - - lines.forEach((line, i) => { - stdout.emit(`${line}${i + 1 > padding && i + 1 < ? 'hm' : ''}\n`) - }) + stdout.emit(`Webshell v${WEBSHELL_VERSION}\n`) + stdout.emit(`Terminal v${Terminal.Version}\n`) + stdout.emit(`Running ${GetCurrentTerminal().GetShell()?.Name} v${GetCurrentTerminal().GetShell()?.Version}\n`) return 0 } diff --git a/src/program/Ls.ts b/src/program/Ls.ts new file mode 100644 index 0000000..8a7fc65 --- /dev/null +++ b/src/program/Ls.ts @@ -0,0 +1,16 @@ +import type { SimpleStream } from '../utils/SimpleStream' +import { Program } from './Program' +import { File } from '../fs/File' +import { Directory } from '../fs/Directory' + +export class Ls extends Program { + constructor() { + super() + } + + async Exec(_: SimpleStream, stdout: SimpleStream, workdir: Directory, __: string[]): Promise { + new Directory('/etc/system/idk') + + return 0 + } +} diff --git a/src/program/Program.ts b/src/program/Program.ts index eecd91c..3c3f5e5 100644 --- a/src/program/Program.ts +++ b/src/program/Program.ts @@ -1,4 +1,4 @@ -import type { SimpleStream } from "../utils/SimpleStream"; +import type { SimpleStream } from "../utils/SimpleStream" export abstract class Program { abstract Exec(stdin: SimpleStream, stdout: SimpleStream, args: string[]): Promise diff --git a/src/shell/Shell.ts b/src/shell/Shell.ts index ebbd99d..f3422f5 100644 --- a/src/shell/Shell.ts +++ b/src/shell/Shell.ts @@ -2,6 +2,8 @@ import type { Terminal } from '../terminal/Terminal' import type { EventBroadcaster } from '../utils/EventBroadcaster' export abstract class Shell { + readonly abstract Version: string + readonly abstract Name: string broadcaster: EventBroadcaster terminal: Terminal diff --git a/src/shell/Wush.ts b/src/shell/Wush.ts index bf2b1ae..542d373 100644 --- a/src/shell/Wush.ts +++ b/src/shell/Wush.ts @@ -1,5 +1,5 @@ // Web-Uno Shell -// the best name I could come up with lmao +// the best name I could come up with lol import { Clear } from '../program/Clear' import { Eval } from '../program/Eval' @@ -11,8 +11,12 @@ import { Terminal } from '../terminal/Terminal' import { EventBroadcaster } from '../utils/EventBroadcaster' import { SimpleStream } from '../utils/SimpleStream' import { Shell } from './Shell' +import { Ls } from '../program/Ls' export class Wush extends Shell { + public readonly Version = "0.1.0" + public readonly Name = "wush" + // buffer private buffer: string[] = [] private bufferPos: number = 0 @@ -51,6 +55,7 @@ export class Wush extends Shell { this.programs['loadprg'] = new Loadprg(this) this.programs['lsprg'] = new Lsprg(this) this.programs['info'] = new Info() + this.programs['ls'] = new Ls() this.stdout.on(data => this.WriteEscapedString(data)) this.Prompt() @@ -78,12 +83,9 @@ export class Wush extends Shell { WriteEscapedString(data: string) { let buf = data.split('') - buf.forEach((char, i) => { - if (this.ProcessControlCode(char)) { - buf.splice(i, 1) - } else { + buf.forEach((char) => { + if (!this.ProcessControlCode(char)) this.terminal.Write(char) - } }) } @@ -125,8 +127,9 @@ export class Wush extends Shell { .then(code => { this.execExitCode = code != -1 ? code : -2 }) - .catch(() => { + .catch((e) => { this.WriteEscapedString("lol") + this.WriteEscapedString(`\n${String(e)}\n`) }) .finally(() => { // check if the exec actually exited with an exit code diff --git a/src/terminal/Terminal.ts b/src/terminal/Terminal.ts index af072d5..af81f44 100644 --- a/src/terminal/Terminal.ts +++ b/src/terminal/Terminal.ts @@ -1,12 +1,17 @@ +import { SetCurrentTerminal } from '../app' + import type { Shell } from '../shell/Shell' import sqs from '../utils/sqs' import type { CursorPosition, CursorStyle } from './CursorProperties' export class Terminal { + public static readonly Version = "0.1.1" + private terminal: HTMLElement private cursor: HTMLElement - private cellHeight = 16 - private cellWidth = 8 + private cursorStyle: CursorStyle = 'bar' + private cellHeight = 0 + private cellWidth = 0 private cursorPosition: CursorPosition = { col: 0, @@ -16,11 +21,11 @@ export class Terminal { private shell?: Shell constructor() { + SetCurrentTerminal(this) + this.terminal = sqs('#terminal') this.cursor = sqs('#cursor') - this.ResetCellSize() - this.SetCursorStyle('bar') this.NewPage() } @@ -30,7 +35,13 @@ export class Terminal { this.shell.Init() } + GetShell(): Shell | undefined { + return this.shell + } + NewPage() { + this.ResetCellSize() + this.terminal.innerHTML = '' this.SetCursorPosition(0, 0) } @@ -127,8 +138,8 @@ export class Terminal { this.terminal.appendChild(cell) - this.cellWidth = cell.scrollWidth - this.cellHeight = cell.scrollHeight + this.cellWidth = cell.offsetWidth + this.cellHeight = cell.offsetHeight cell.remove() } @@ -142,6 +153,8 @@ export class Terminal { } UpdateCursor() { + this.SetCursorStyle(this.cursorStyle) + this.cursor.style.left = `${this.cursorPosition.col * this.cellWidth}px` this.cursor.style.top = `${this.cursorPosition.row * this.cellHeight}px` }