feat: add neofetch, fix buffer backspacing
This commit is contained in:
29
src/program/Neofetch.ts
Normal file
29
src/program/Neofetch.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import { Clear } from '../program/Clear'
|
|||||||
import { Eval } from '../program/Eval'
|
import { Eval } from '../program/Eval'
|
||||||
import { Loadprg } from '../program/Loadprg'
|
import { Loadprg } from '../program/Loadprg'
|
||||||
import { Lsprg } from '../program/Lsprg'
|
import { Lsprg } from '../program/Lsprg'
|
||||||
|
import { Neofetch } from '../program/Neofetch'
|
||||||
import { Program } from '../program/Program'
|
import { Program } from '../program/Program'
|
||||||
import { Terminal } from '../terminal/Terminal'
|
import { Terminal } from '../terminal/Terminal'
|
||||||
import { EventBroadcaster } from '../utils/EventBroadcaster'
|
import { EventBroadcaster } from '../utils/EventBroadcaster'
|
||||||
@@ -46,6 +47,7 @@ export class Wush extends Shell {
|
|||||||
this.programs['eval'] = new Eval()
|
this.programs['eval'] = new Eval()
|
||||||
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['neofetch'] = new Neofetch()
|
||||||
|
|
||||||
this.stdout.on(data => this.WriteEscapedString(data))
|
this.stdout.on(data => this.WriteEscapedString(data))
|
||||||
this.Prompt()
|
this.Prompt()
|
||||||
@@ -91,8 +93,8 @@ export class Wush extends Shell {
|
|||||||
console.log(this.buffer)
|
console.log(this.buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoveLastCharsFromBuffer(amount: number) {
|
RemoveCharFromBuffer(amount: number, index: number) {
|
||||||
this.buffer.splice(this.buffer.length - amount, amount)
|
this.buffer.splice(index - amount, amount)
|
||||||
this.bufferPos -= amount
|
this.bufferPos -= amount
|
||||||
|
|
||||||
console.log(this.buffer)
|
console.log(this.buffer)
|
||||||
@@ -181,9 +183,22 @@ export class Wush extends Shell {
|
|||||||
break
|
break
|
||||||
|
|
||||||
this.terminal.RemoveCell()
|
this.terminal.RemoveCell()
|
||||||
this.RemoveLastCharsFromBuffer(1)
|
this.RemoveCharFromBuffer(1, this.bufferPos)
|
||||||
|
// this.buffer.splice(this.bufferPos, 1)
|
||||||
this.terminal.MoveCursor(-1, 0)
|
this.terminal.MoveCursor(-1, 0)
|
||||||
break
|
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':
|
case 'Enter':
|
||||||
// send the buffer to stdin if an exec is running
|
// send the buffer to stdin if an exec is running
|
||||||
if (this.execExitCode === -1) {
|
if (this.execExitCode === -1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user