sync: wip shell and info fetch
This commit is contained in:
@@ -5,9 +5,9 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
|
||||||
<!-- google fonts -->
|
<!-- 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 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 -->
|
<!-- import main stylesheet -->
|
||||||
<link rel="stylesheet" href="/src/styles/app.scss" />
|
<link rel="stylesheet" href="/src/styles/app.scss" />
|
||||||
|
|||||||
25
src/program/Info.ts
Normal file
25
src/program/Info.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +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 { Info } from '../program/Info'
|
||||||
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'
|
||||||
@@ -17,6 +17,9 @@ export class Wush extends Shell {
|
|||||||
private buffer: string[] = []
|
private buffer: string[] = []
|
||||||
private bufferPos: number = 0
|
private bufferPos: number = 0
|
||||||
|
|
||||||
|
private history: string[] = []
|
||||||
|
private historyPos: number = 0
|
||||||
|
|
||||||
// exec stuff
|
// exec stuff
|
||||||
/**
|
/**
|
||||||
* -1 if the exec is currently running and anything else when it's not
|
* -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['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.programs['info'] = new Info()
|
||||||
|
|
||||||
this.stdout.on(data => this.WriteEscapedString(data))
|
this.stdout.on(data => this.WriteEscapedString(data))
|
||||||
this.Prompt()
|
this.Prompt()
|
||||||
@@ -90,14 +93,14 @@ export class Wush extends Shell {
|
|||||||
this.bufferPos++
|
this.bufferPos++
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(this.buffer)
|
// console.log(this.buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoveCharFromBuffer(amount: number, index: number) {
|
RemoveCharFromBuffer(amount: number, index: number) {
|
||||||
this.buffer.splice(index - amount, amount)
|
this.buffer.splice(index - amount, amount)
|
||||||
this.bufferPos -= amount
|
this.bufferPos -= amount
|
||||||
|
|
||||||
console.log(this.buffer)
|
// console.log(this.buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
MoveBufferPos(index: number, absolute: boolean = false) {
|
MoveBufferPos(index: number, absolute: boolean = false) {
|
||||||
@@ -177,6 +180,27 @@ export class Wush extends Shell {
|
|||||||
this.MoveBufferPos(1)
|
this.MoveBufferPos(1)
|
||||||
}
|
}
|
||||||
break
|
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':
|
case 'Backspace':
|
||||||
// don't erase anything if there's nothing left in the buffer
|
// don't erase anything if there's nothing left in the buffer
|
||||||
if (this.bufferPos === 0)
|
if (this.bufferPos === 0)
|
||||||
@@ -196,8 +220,6 @@ export class Wush extends Shell {
|
|||||||
this.terminal.RemoveCell()
|
this.terminal.RemoveCell()
|
||||||
this.RemoveCharFromBuffer(1, this.bufferPos)
|
this.RemoveCharFromBuffer(1, this.bufferPos)
|
||||||
this.terminal.MoveCursor(-1, 0)
|
this.terminal.MoveCursor(-1, 0)
|
||||||
|
|
||||||
console.log(this.bufferPos)
|
|
||||||
break
|
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
|
||||||
@@ -207,6 +229,7 @@ export class Wush extends Shell {
|
|||||||
} else {
|
} else {
|
||||||
// "execute" the buffer
|
// "execute" the buffer
|
||||||
this.terminal.MoveCursor(0, 1, { x: true, y: false })
|
this.terminal.MoveCursor(0, 1, { x: true, y: false })
|
||||||
|
this.history.splice(0, 0, this.buffer.join(''))
|
||||||
this.ExecuteBuffer()
|
this.ExecuteBuffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,6 +239,8 @@ export class Wush extends Shell {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
this.historyPos = 0
|
||||||
|
|
||||||
// push the character into the buffer
|
// push the character into the buffer
|
||||||
this.terminal.InsertCell(key)
|
this.terminal.InsertCell(key)
|
||||||
this.PushToBuffer(key)
|
this.PushToBuffer(key)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
height: fit-content;
|
height: fit-content;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
text-wrap: nowrap;
|
text-wrap: nowrap;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
span {
|
span {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ export class Terminal {
|
|||||||
AppendLine() {
|
AppendLine() {
|
||||||
const paragraph = document.createElement('p')
|
const paragraph = document.createElement('p')
|
||||||
paragraph.style.height = `${this.cellHeight}px`
|
paragraph.style.height = `${this.cellHeight}px`
|
||||||
paragraph.style.lineHeight = `${this.cellHeight}px`
|
|
||||||
paragraph.id = `line-${this.cursorPosition.row}`
|
paragraph.id = `line-${this.cursorPosition.row}`
|
||||||
paragraph.className = 'line'
|
paragraph.className = 'line'
|
||||||
|
|
||||||
@@ -85,7 +84,6 @@ export class Terminal {
|
|||||||
cell.className = `cell-${i}`
|
cell.className = `cell-${i}`
|
||||||
cell.style.width = `${this.cellWidth}px`
|
cell.style.width = `${this.cellWidth}px`
|
||||||
cell.style.height = `${this.cellHeight}px`
|
cell.style.height = `${this.cellHeight}px`
|
||||||
cell.style.lineHeight = `${this.cellHeight}px`
|
|
||||||
|
|
||||||
line.appendChild(cell)
|
line.appendChild(cell)
|
||||||
}
|
}
|
||||||
@@ -104,7 +102,6 @@ export class Terminal {
|
|||||||
cell.className = `cell-${this.cursorPosition.col}`
|
cell.className = `cell-${this.cursorPosition.col}`
|
||||||
cell.style.width = `${this.cellWidth}px`
|
cell.style.width = `${this.cellWidth}px`
|
||||||
cell.style.height = `${this.cellHeight}px`
|
cell.style.height = `${this.cellHeight}px`
|
||||||
cell.style.lineHeight = `${this.cellHeight}px`
|
|
||||||
|
|
||||||
cell.innerText = char[0]
|
cell.innerText = char[0]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user