feat: add neofetch, fix buffer backspacing

This commit is contained in:
2026-03-27 09:20:21 +01:00
parent 91eeb33d9e
commit 83830c7717
2 changed files with 47 additions and 3 deletions

29
src/program/Neofetch.ts Normal file
View File

@@ -0,0 +1,29 @@
import type { SimpleStream } from '../utils/SimpleStream'
import { Program } from './Program'
export class Neofetch extends Program {
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, __: string[]): Promise<number> {
const art = `++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
+++++++++++++++++++++;..:+++++
++++ ++ +++
++++++++. +++++ +++++++++
++++++++. +++++: ++++++++
++++++++. ++++++; ++++
++++++++. ++++++++++. +++
++++++++. +++++.++++++ ;++
++++++++. +++++ +++
++++++++;...++++++; ;+++++
++++++++++++++++++++++++++++++`
art.split("\n").forEach(line => {
stdout.emit(`${line}\n`)
})
return 0
}
}

View File

@@ -5,6 +5,7 @@ import { Clear } from '../program/Clear'
import { Eval } from '../program/Eval'
import { Loadprg } from '../program/Loadprg'
import { Lsprg } from '../program/Lsprg'
import { Neofetch } from '../program/Neofetch'
import { Program } from '../program/Program'
import { Terminal } from '../terminal/Terminal'
import { EventBroadcaster } from '../utils/EventBroadcaster'
@@ -46,6 +47,7 @@ export class Wush extends Shell {
this.programs['eval'] = new Eval()
this.programs['loadprg'] = new Loadprg(this)
this.programs['lsprg'] = new Lsprg(this)
this.programs['neofetch'] = new Neofetch()
this.stdout.on(data => this.WriteEscapedString(data))
this.Prompt()
@@ -91,8 +93,8 @@ export class Wush extends Shell {
console.log(this.buffer)
}
RemoveLastCharsFromBuffer(amount: number) {
this.buffer.splice(this.buffer.length - amount, amount)
RemoveCharFromBuffer(amount: number, index: number) {
this.buffer.splice(index - amount, amount)
this.bufferPos -= amount
console.log(this.buffer)
@@ -181,9 +183,22 @@ export class Wush extends Shell {
break
this.terminal.RemoveCell()
this.RemoveLastCharsFromBuffer(1)
this.RemoveCharFromBuffer(1, this.bufferPos)
// this.buffer.splice(this.bufferPos, 1)
this.terminal.MoveCursor(-1, 0)
break
case 'Delete':
if (this.bufferPos >= this.buffer.length || this.buffer.length <= 0)
break
this.bufferPos++
this.terminal.MoveCursor(1, 0)
this.terminal.RemoveCell()
this.RemoveCharFromBuffer(1, this.bufferPos)
this.terminal.MoveCursor(-1, 0)
console.log(this.bufferPos)
break
case 'Enter':
// send the buffer to stdin if an exec is running
if (this.execExitCode === -1) {