sync: wip changes
This commit is contained in:
15
src/shell/Shell.ts
Normal file
15
src/shell/Shell.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { Terminal } from '../terminal/Terminal'
|
||||
import type { EventBroadcaster } from '../utils/EventBroadcaster'
|
||||
|
||||
export abstract class Shell {
|
||||
broadcaster: EventBroadcaster
|
||||
terminal: Terminal
|
||||
|
||||
constructor(broadcaster: EventBroadcaster, terminal: Terminal) {
|
||||
this.broadcaster = broadcaster
|
||||
this.terminal = terminal
|
||||
}
|
||||
|
||||
abstract Init(): void
|
||||
abstract HandleKeyInput(key: string, isCharacter: boolean): void
|
||||
}
|
||||
42
src/shell/Wush.ts
Normal file
42
src/shell/Wush.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
// Web-Uno Shell
|
||||
// the best name I could come up with lmao
|
||||
|
||||
import { Terminal } from '../terminal/Terminal'
|
||||
import type { EventBroadcaster } from '../utils/EventBroadcaster'
|
||||
import { Shell } from './Shell'
|
||||
|
||||
export class Wush extends Shell {
|
||||
constructor(broadcaster: EventBroadcaster, terminal: Terminal) {
|
||||
super(broadcaster, terminal)
|
||||
}
|
||||
|
||||
Init() {
|
||||
this.broadcaster.on('keydown', (key: string, isCharacter: boolean) =>
|
||||
this.HandleKeyInput(key, isCharacter),
|
||||
)
|
||||
this.Prompt()
|
||||
}
|
||||
|
||||
Prompt() {
|
||||
this.terminal.Write('hi -> ')
|
||||
}
|
||||
|
||||
HandleKeyInput(key: string, isCharacter: boolean) {
|
||||
console.log(key)
|
||||
console.log(isCharacter)
|
||||
|
||||
if (!isCharacter)
|
||||
switch (key) {
|
||||
case 'Backspace':
|
||||
this.terminal.RemoveCells(1)
|
||||
break
|
||||
case 'Enter':
|
||||
this.Prompt()
|
||||
break
|
||||
}
|
||||
else {
|
||||
this.terminal.Write(key)
|
||||
this.terminal.AdjustCursorPosition(1, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user