sync: wip shell and info fetch
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user