chore: fix chrome

This commit is contained in:
2026-04-15 11:40:45 +02:00
parent ea968b8492
commit dc706d6262
10 changed files with 112 additions and 32 deletions

View File

@@ -10,9 +10,9 @@
}, },
"devDependencies": { "devDependencies": {
"typescript": "~5.9.3", "typescript": "~5.9.3",
"vite": "^8.0.1" "vite": "^8.0.8"
}, },
"dependencies": { "dependencies": {
"sass": "^1.98.0" "sass": "^1.99.0"
} }
} }

View File

@@ -3,6 +3,12 @@ import { Wush } from './shell/Wush'
import { Terminal } from './terminal/Terminal' import { Terminal } from './terminal/Terminal'
import { EventBroadcaster } from './utils/EventBroadcaster' 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 // Initializes the app
const init = () => { const init = () => {
const localBroadcaster = new EventBroadcaster() const localBroadcaster = new EventBroadcaster()

9
src/fs/Directory.ts Normal file
View File

@@ -0,0 +1,9 @@
export class Directory {
readonly path: string
constructor(path: string) {
this.path = path
console.log(this.path.split('/'))
}
}

42
src/fs/File.ts Normal file
View File

@@ -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
}
}

View File

@@ -1,24 +1,13 @@
import { GetCurrentTerminal, WEBSHELL_VERSION } from '../app'
import { Terminal } from '../terminal/Terminal'
import type { SimpleStream } from '../utils/SimpleStream' import type { SimpleStream } from '../utils/SimpleStream'
import { Program } from './Program' import { Program } from './Program'
export class Info extends Program { export class Info extends Program {
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, __: string[]): Promise<number> { async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, __: string[]): Promise<number> {
const art = `++++++++++++++++++++++++++++++\n++++++++++++++++++++++++++++++\n++++++++++++++++++++++++++++++\n++++++++++++++++++++++++++++++\n++++++++++++++++++++++++++++++\n++++++++++++++++++++++++++++++\n+++++++++++++++++++++;..:+++++\n++++ ++ +++\n++++++++. +++++ +++++++++\n++++++++. +++++: ++++++++\n++++++++. ++++++; ++++\n++++++++. ++++++++++. +++\n++++++++. +++++.++++++ ;++\n++++++++. +++++ +++\n++++++++;...++++++; ;+++++\n++++++++++++++++++++++++++++++` stdout.emit(`Webshell v${WEBSHELL_VERSION}\n`)
stdout.emit(`Terminal v${Terminal.Version}\n`)
const modules = [ stdout.emit(`Running ${GetCurrentTerminal().GetShell()?.Name} v${GetCurrentTerminal().GetShell()?.Version}\n`)
{ 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`)
})
return 0 return 0
} }

16
src/program/Ls.ts Normal file
View File

@@ -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<string>, stdout: SimpleStream<string>, workdir: Directory, __: string[]): Promise<number> {
new Directory('/etc/system/idk')
return 0
}
}

View File

@@ -1,4 +1,4 @@
import type { SimpleStream } from "../utils/SimpleStream"; import type { SimpleStream } from "../utils/SimpleStream"
export abstract class Program { export abstract class Program {
abstract Exec(stdin: SimpleStream<string>, stdout: SimpleStream<string>, args: string[]): Promise<number> abstract Exec(stdin: SimpleStream<string>, stdout: SimpleStream<string>, args: string[]): Promise<number>

View File

@@ -2,6 +2,8 @@ import type { Terminal } from '../terminal/Terminal'
import type { EventBroadcaster } from '../utils/EventBroadcaster' import type { EventBroadcaster } from '../utils/EventBroadcaster'
export abstract class Shell { export abstract class Shell {
readonly abstract Version: string
readonly abstract Name: string
broadcaster: EventBroadcaster broadcaster: EventBroadcaster
terminal: Terminal terminal: Terminal

View File

@@ -1,5 +1,5 @@
// Web-Uno Shell // 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 { Clear } from '../program/Clear'
import { Eval } from '../program/Eval' import { Eval } from '../program/Eval'
@@ -11,8 +11,12 @@ import { Terminal } from '../terminal/Terminal'
import { EventBroadcaster } from '../utils/EventBroadcaster' import { EventBroadcaster } from '../utils/EventBroadcaster'
import { SimpleStream } from '../utils/SimpleStream' import { SimpleStream } from '../utils/SimpleStream'
import { Shell } from './Shell' import { Shell } from './Shell'
import { Ls } from '../program/Ls'
export class Wush extends Shell { export class Wush extends Shell {
public readonly Version = "0.1.0"
public readonly Name = "wush"
// buffer // buffer
private buffer: string[] = [] private buffer: string[] = []
private bufferPos: number = 0 private bufferPos: number = 0
@@ -51,6 +55,7 @@ export class Wush extends Shell {
this.programs['loadprg'] = new Loadprg(this) this.programs['loadprg'] = new Loadprg(this)
this.programs['lsprg'] = new Lsprg(this) this.programs['lsprg'] = new Lsprg(this)
this.programs['info'] = new Info() this.programs['info'] = new Info()
this.programs['ls'] = new Ls()
this.stdout.on(data => this.WriteEscapedString(data)) this.stdout.on(data => this.WriteEscapedString(data))
this.Prompt() this.Prompt()
@@ -78,12 +83,9 @@ export class Wush extends Shell {
WriteEscapedString(data: string) { WriteEscapedString(data: string) {
let buf = data.split('') let buf = data.split('')
buf.forEach((char, i) => { buf.forEach((char) => {
if (this.ProcessControlCode(char)) { if (!this.ProcessControlCode(char))
buf.splice(i, 1)
} else {
this.terminal.Write(char) this.terminal.Write(char)
}
}) })
} }
@@ -125,8 +127,9 @@ export class Wush extends Shell {
.then(code => { .then(code => {
this.execExitCode = code != -1 ? code : -2 this.execExitCode = code != -1 ? code : -2
}) })
.catch(() => { .catch((e) => {
this.WriteEscapedString("lol") this.WriteEscapedString("lol")
this.WriteEscapedString(`\n${String(e)}\n`)
}) })
.finally(() => { .finally(() => {
// check if the exec actually exited with an exit code // check if the exec actually exited with an exit code

View File

@@ -1,12 +1,17 @@
import { SetCurrentTerminal } from '../app'
import type { Shell } from '../shell/Shell' import type { Shell } from '../shell/Shell'
import sqs from '../utils/sqs' import sqs from '../utils/sqs'
import type { CursorPosition, CursorStyle } from './CursorProperties' import type { CursorPosition, CursorStyle } from './CursorProperties'
export class Terminal { export class Terminal {
public static readonly Version = "0.1.1"
private terminal: HTMLElement private terminal: HTMLElement
private cursor: HTMLElement private cursor: HTMLElement
private cellHeight = 16 private cursorStyle: CursorStyle = 'bar'
private cellWidth = 8 private cellHeight = 0
private cellWidth = 0
private cursorPosition: CursorPosition = { private cursorPosition: CursorPosition = {
col: 0, col: 0,
@@ -16,11 +21,11 @@ export class Terminal {
private shell?: Shell private shell?: Shell
constructor() { constructor() {
SetCurrentTerminal(this)
this.terminal = sqs('#terminal') this.terminal = sqs('#terminal')
this.cursor = sqs('#cursor') this.cursor = sqs('#cursor')
this.ResetCellSize()
this.SetCursorStyle('bar') this.SetCursorStyle('bar')
this.NewPage() this.NewPage()
} }
@@ -30,7 +35,13 @@ export class Terminal {
this.shell.Init() this.shell.Init()
} }
GetShell(): Shell | undefined {
return this.shell
}
NewPage() { NewPage() {
this.ResetCellSize()
this.terminal.innerHTML = '' this.terminal.innerHTML = ''
this.SetCursorPosition(0, 0) this.SetCursorPosition(0, 0)
} }
@@ -127,8 +138,8 @@ export class Terminal {
this.terminal.appendChild(cell) this.terminal.appendChild(cell)
this.cellWidth = cell.scrollWidth this.cellWidth = cell.offsetWidth
this.cellHeight = cell.scrollHeight this.cellHeight = cell.offsetHeight
cell.remove() cell.remove()
} }
@@ -142,6 +153,8 @@ export class Terminal {
} }
UpdateCursor() { UpdateCursor() {
this.SetCursorStyle(this.cursorStyle)
this.cursor.style.left = `${this.cursorPosition.col * this.cellWidth}px` this.cursor.style.left = `${this.cursorPosition.col * this.cellWidth}px`
this.cursor.style.top = `${this.cursorPosition.row * this.cellHeight}px` this.cursor.style.top = `${this.cursorPosition.row * this.cellHeight}px`
} }