diff --git a/index.html b/index.html index d0a9fcd..774f101 100644 --- a/index.html +++ b/index.html @@ -5,9 +5,9 @@ - + diff --git a/src/program/Info.ts b/src/program/Info.ts new file mode 100644 index 0000000..23ed7a1 --- /dev/null +++ b/src/program/Info.ts @@ -0,0 +1,25 @@ +import type { SimpleStream } from '../utils/SimpleStream' +import { Program } from './Program' + +export class Info extends Program { + async Exec(_: SimpleStream, stdout: SimpleStream, __: string[]): Promise { + 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 + } +} diff --git a/src/program/Neofetch.ts b/src/program/Neofetch.ts deleted file mode 100644 index 329bc0a..0000000 --- a/src/program/Neofetch.ts +++ /dev/null @@ -1,29 +0,0 @@ -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 cae38a6..bf2b1ae 100644 --- a/src/shell/Wush.ts +++ b/src/shell/Wush.ts @@ -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) diff --git a/src/styles/terminal.scss b/src/styles/terminal.scss index f269f9f..77c4ad3 100644 --- a/src/styles/terminal.scss +++ b/src/styles/terminal.scss @@ -17,6 +17,7 @@ height: fit-content; word-wrap: break-word; text-wrap: nowrap; + display: flex; span { display: inline-block; diff --git a/src/terminal/Terminal.ts b/src/terminal/Terminal.ts index 5c94a4f..af072d5 100644 --- a/src/terminal/Terminal.ts +++ b/src/terminal/Terminal.ts @@ -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]