From 83830c77179ecea2f5b3525ab2a7c17359cdf4ba Mon Sep 17 00:00:00 2001 From: binekrasik Date: Fri, 27 Mar 2026 09:20:21 +0100 Subject: [PATCH] feat: add neofetch, fix buffer backspacing --- src/program/Neofetch.ts | 29 +++++++++++++++++++++++++++++ src/shell/Wush.ts | 21 ++++++++++++++++++--- 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 src/program/Neofetch.ts diff --git a/src/program/Neofetch.ts b/src/program/Neofetch.ts new file mode 100644 index 0000000..329bc0a --- /dev/null +++ b/src/program/Neofetch.ts @@ -0,0 +1,29 @@ +import type { SimpleStream } from '../utils/SimpleStream' +import { Program } from './Program' + +export class Neofetch extends Program { + async Exec(_: SimpleStream, stdout: SimpleStream, __: string[]): Promise { + const art = `++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++ ++++++++++++++++++++++;..:+++++ +++++ ++ +++ +++++++++. +++++ +++++++++ +++++++++. +++++: ++++++++ +++++++++. ++++++; ++++ +++++++++. ++++++++++. +++ +++++++++. +++++.++++++ ;++ +++++++++. +++++ +++ +++++++++;...++++++; ;+++++ +++++++++++++++++++++++++++++++` + + art.split("\n").forEach(line => { + stdout.emit(`${line}\n`) + }) + + return 0 + } +} diff --git a/src/shell/Wush.ts b/src/shell/Wush.ts index 3d3adbb..cae38a6 100644 --- a/src/shell/Wush.ts +++ b/src/shell/Wush.ts @@ -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) {