chore: fix chrome
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
9
src/fs/Directory.ts
Normal file
9
src/fs/Directory.ts
Normal 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
42
src/fs/File.ts
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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<string>, stdout: SimpleStream<string>, __: string[]): Promise<number> {
|
||||
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
|
||||
}
|
||||
|
||||
16
src/program/Ls.ts
Normal file
16
src/program/Ls.ts
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { SimpleStream } from "../utils/SimpleStream";
|
||||
import type { SimpleStream } from "../utils/SimpleStream"
|
||||
|
||||
export abstract class Program {
|
||||
abstract Exec(stdin: SimpleStream<string>, stdout: SimpleStream<string>, args: string[]): Promise<number>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user