promote more readable this.send() in REPLs
Some checks failed
/ mirror_to_github (push) Failing after 1m59s
/ test (push) Successful in 8s

This commit is contained in:
Leon van Kammen 2025-01-28 11:31:37 +01:00
parent 5bf33dedcd
commit fc2e42c714
8 changed files with 30 additions and 22 deletions

View file

@ -199,7 +199,7 @@ You can specify a different `.iso` file in various ways:
mainmenu()
},
keyHandler: function(ch){
this.emit('serial-output-string', "\n\ryou typed:"+ch) // write to term
this.send("\n\ryou typed:"+ch) // write to term
}
})

File diff suppressed because one or more lines are too long

View file

@ -30,6 +30,9 @@ function waitForAScene(callback) {
// Example usage
waitForAScene((aScene) => {
if( aScene.innerHTML.match(/ isoterminal/) ) return; // prevent duplicates
// Inject the external script
const xrshScript = document.createElement("script");
xrshScript.src = chrome.runtime.getURL("xrsh.js");

View file

@ -72,6 +72,7 @@
},
keyHandler: function(ch){
console.log("you typed: "+ch)
//this.send("you typed:"+ch)
}
})

@ -1 +1 @@
Subproject commit 2137af0a484ce72d6f8dc43d6cbbd40f41e18b5a
Subproject commit e00b403dfcca855957b315ba91f1dde34bc68f0c

BIN
xrsh.com

Binary file not shown.

View file

@ -1 +1 @@
7fd0c456ce260b22485f270a8202db660a8bddf22f6c2f59db75b9b29b45c27d xrsh.com
f2183b15e0a18ee93eda634fcf732832c796b86a1bdf52cd8094d1342bfd125a xrsh.com

36
xrsh.js
View file

@ -1460,18 +1460,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)
}
}
@ -3227,7 +3231,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() })
@ -3280,7 +3284,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){
@ -3289,16 +3293,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){