sync: wip shell and info fetch

This commit is contained in:
2026-03-27 17:52:58 +01:00
parent 83830c7717
commit ea968b8492
6 changed files with 59 additions and 40 deletions

View File

@@ -5,9 +5,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- google fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<!--<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap" rel="stylesheet" />-->
<!-- import main stylesheet -->
<link rel="stylesheet" href="/src/styles/app.scss" />

25
src/program/Info.ts Normal file
View File

@@ -0,0 +1,25 @@
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`)
})
return 0
}
}

View File

@@ -1,29 +0,0 @@
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,7 +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 { Info } from '../program/Info'
import { Program } from '../program/Program'
import { Terminal } from '../terminal/Terminal'
import { EventBroadcaster } from '../utils/EventBroadcaster'
@@ -17,6 +17,9 @@ export class Wush extends Shell {
private buffer: string[] = []
private bufferPos: number = 0
private history: string[] = []
private historyPos: number = 0
// exec stuff
/**
* -1 if the exec is currently running and anything else when it's not
@@ -47,7 +50,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.programs['info'] = new Info()
this.stdout.on(data => this.WriteEscapedString(data))
this.Prompt()
@@ -90,14 +93,14 @@ export class Wush extends Shell {
this.bufferPos++
})
console.log(this.buffer)
// console.log(this.buffer)
}
RemoveCharFromBuffer(amount: number, index: number) {
this.buffer.splice(index - amount, amount)
this.bufferPos -= amount
console.log(this.buffer)
// console.log(this.buffer)
}
MoveBufferPos(index: number, absolute: boolean = false) {
@@ -177,6 +180,27 @@ export class Wush extends Shell {
this.MoveBufferPos(1)
}
break
case 'ArrowUp':
if (this.historyPos < this.history.length) {
if (this.historyPos === 0)
this.history.splice(0, 0, this.buffer.join(''))
this.historyPos++
console.log(this.historyPos)
console.log(this.history[this.historyPos])
}
break
case 'ArrowDown':
if (this.historyPos > 0) {
this.historyPos--
if (this.historyPos === 0)
this.history.splice(0, 1)
console.log(this.historyPos)
console.log(this.history[this.historyPos])
}
break
case 'Backspace':
// don't erase anything if there's nothing left in the buffer
if (this.bufferPos === 0)
@@ -196,8 +220,6 @@ export class Wush extends Shell {
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
@@ -207,6 +229,7 @@ export class Wush extends Shell {
} else {
// "execute" the buffer
this.terminal.MoveCursor(0, 1, { x: true, y: false })
this.history.splice(0, 0, this.buffer.join(''))
this.ExecuteBuffer()
}
@@ -216,6 +239,8 @@ export class Wush extends Shell {
break
}
} else {
this.historyPos = 0
// push the character into the buffer
this.terminal.InsertCell(key)
this.PushToBuffer(key)

View File

@@ -17,6 +17,7 @@
height: fit-content;
word-wrap: break-word;
text-wrap: nowrap;
display: flex;
span {
display: inline-block;

View File

@@ -38,7 +38,6 @@ export class Terminal {
AppendLine() {
const paragraph = document.createElement('p')
paragraph.style.height = `${this.cellHeight}px`
paragraph.style.lineHeight = `${this.cellHeight}px`
paragraph.id = `line-${this.cursorPosition.row}`
paragraph.className = 'line'
@@ -85,7 +84,6 @@ export class Terminal {
cell.className = `cell-${i}`
cell.style.width = `${this.cellWidth}px`
cell.style.height = `${this.cellHeight}px`
cell.style.lineHeight = `${this.cellHeight}px`
line.appendChild(cell)
}
@@ -104,7 +102,6 @@ export class Terminal {
cell.className = `cell-${this.cursorPosition.col}`
cell.style.width = `${this.cellWidth}px`
cell.style.height = `${this.cellHeight}px`
cell.style.lineHeight = `${this.cellHeight}px`
cell.innerText = char[0]