REPL update
All checks were successful
/ mirror_to_github (push) Successful in 23s
/ test (push) Successful in 4s

This commit is contained in:
Leon van Kammen 2025-01-27 12:00:16 +01:00
parent e2fd89e691
commit ef890c8c34
3 changed files with 25 additions and 7 deletions

View file

@ -2,14 +2,17 @@ ISOTerminal.addEventListener('ready', function(e){
setTimeout( () => this.boot(), 50 ) // because of autorestore.js
})
ISOTerminal.addEventListener('bootmenu', function(e){
ISOTerminal.prototype.bootMenu = function(e){
this.boot.menu.selected = false // reset
let msg = '\n\r'
this.boot.menu.map( (m) => {
msg += `\r ${m.key}) ${m.title(this.opts)}\n`
})
msg += `\n\r enter choice> `
this.emit('serial-output-string', msg)
})
}
ISOTerminal.addEventListener('bootmenu', function(e){ this.bootMenu() })
ISOTerminal.prototype.boot = async function(e){
// set environment
@ -32,15 +35,22 @@ ISOTerminal.prototype.boot = async function(e){
}
}
ISOTerminal.prototype.boot.menu = [
// here REPL's can be defined
ISOTerminal.prototype.boot.menu = []
// REPL: iso
ISOTerminal.prototype.boot.menu.push(
{
key: "1",
title: (opts) => `boot ${String(opts.iso || "").replace(/.*\//,'')} Linux ❤️ `,
init: function(){ this.bootISO() },
keyHandler: function(ch){ this.send(ch) } // send to v86 webworker
},
}
)
// REPL: jsconsole
ISOTerminal.prototype.boot.menu.push(
{
key: "2",
title: (opts) => "just give me an javascript-console in WebXR instantly",
@ -49,7 +59,9 @@ ISOTerminal.prototype.boot.menu = [
this.emit('enable-console',{stdout:true})
this.emit('status',"javascript console")
this.console = ""
setTimeout( () => this.emit('serial-output-string', this.prompt), 100 )
setTimeout( () => {
if( this.boot.menu.selected ) this.emit('serial-output-string', this.prompt)
}, 100 )
},
keyHandler: function(ch){
let erase = false
@ -80,4 +92,4 @@ ISOTerminal.prototype.boot.menu = [
}
}
}
]
)

View file

@ -58,6 +58,7 @@ ISOTerminal.prototype.enableConsole = function(opts){
});
if( opts.stdout ){
window.menu = () => this.bootMenu()
this.emit('serial-output-string', "\n\n\r☑ initialized javascript console\n");
this.emit('serial-output-string', "\r☑ please use these functions to print:\n");
this.emit('serial-output-string', "\r└☑ console.log(\"foo\")\n");
@ -65,6 +66,8 @@ ISOTerminal.prototype.enableConsole = function(opts){
this.emit('serial-output-string', "\r└☑ console.dir({foo:12})\n");
this.emit('serial-output-string', "\r└☑ console.error(\"foo\")\n");
this.emit('serial-output-string', "\r\n");
this.emit('serial-output-string', "\rtype 'menu()' to return to mainmenu");
this.emit('serial-output-string', "\r\n");
}
}

View file

@ -87,7 +87,10 @@ ISOTerminal.prototype.TermInit = function(){
let menuitem = this.boot.menu.find( (m) => m.key == this.lastChar )
if( menuitem ){
this.boot.menu.selected = menuitem
menuitem.init.call(this)
menuitem.init.call(this, () => {
this.term.write("\n\r")
this.bootMenu()
})
}
}else{
this.term.write(ch)