Skip to content

Commit

Permalink
promote more readable this.send() in REPLs
Browse files Browse the repository at this point in the history
  • Loading branch information
coderofsalvation committed Jan 28, 2025
1 parent 2137af0 commit e00b403
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
26 changes: 15 additions & 11 deletions com/isoterminal/ISOTerminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ ISOTerminal.prototype.serial_input = 0; // can be set to 0,1,2,3 to define stdin

ISOTerminal.prototype.send = function(str, ttyNr){
if( ttyNr == undefined) ttyNr = this.serial_input
if( ttyNr == undefined ){
if( this.emulator.serial_adapter ){
this.emulator.serial_adapter.term.paste(str)
}else this.emulator.keyboard_send_text(str) // vga screen
if( (this.emulator || this.worker) && this.ready ){
if( ttyNr == undefined ){
if( this.emulator.serial_adapter ){
this.emulator.serial_adapter.term.paste(str)
}else this.emulator.keyboard_send_text(str) // vga screen
}else{
this.convert.toUint8Array( str ).map( (c) => {
this.preventFrameDrop(
() => {
this.worker.postMessage({event:`serial${ttyNr}-input`,data:c})
}
)
})
}
}else{
this.convert.toUint8Array( str ).map( (c) => {
this.preventFrameDrop(
() => {
this.worker.postMessage({event:`serial${ttyNr}-input`,data:c})
}
)
})
this.emit('serial-output-string', str)
}
}

Expand Down
10 changes: 5 additions & 5 deletions com/isoterminal/feat/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ISOTerminal.prototype.bootMenu = function(e){
msg += `\r ${m.key}) ${m.title(this.opts)}\n`
})
msg += `\n\r enter choice> `
this.emit('serial-output-string', msg)
this.send(msg)
}

ISOTerminal.addEventListener('bootmenu', function(e){ this.bootMenu() })
Expand Down Expand Up @@ -62,7 +62,7 @@ ISOTerminal.prototype.boot.menu.push(
this.emit('status',"javascript console")
this.console = ""
setTimeout( () => {
this.emit('serial-output-string', this.prompt)
this.send(this.prompt)
}, 100 )
},
keyHandler: function(ch){
Expand All @@ -71,16 +71,16 @@ ISOTerminal.prototype.boot.menu.push(
ch = "\b \b" // why does write() not just support \x7F ?
erase = true
}
this.emit('serial-output-string', ch)
this.send(ch)
const reset = () => {
this.console = ""
setTimeout( () => {
if( this.boot.menu.selected ) this.emit('serial-output-string', this.prompt)
if( this.boot.menu.selected ) this.send(this.prompt)
},100)
}
if( (ch == "\n" || ch == "\r") ){
try{
this.emit('serial-output-string', "\n\r")
this.send("\n\r")
if( this.console ) eval(this.console)
reset()
}catch(e){
Expand Down

0 comments on commit e00b403

Please sign in to comment.