xrsh-com/com/isoterminal/feat/boot.js
Leon van Kammen e00b403dfc
All checks were successful
/ mirror_to_github (push) Successful in 28s
/ test (push) Successful in 7s
promote more readable this.send() in REPLs
2025-01-28 11:30:31 +01:00

99 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

ISOTerminal.addEventListener('ready', function(e){
setTimeout( () => this.boot(), 50 ) // because of autorestore.js
})
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.send(msg)
}
ISOTerminal.addEventListener('bootmenu', function(e){ this.bootMenu() })
ISOTerminal.prototype.boot = async function(e){
// set environment
let env = [
`export LINES=${this.opts.rows}`,
`export COLUMNS=${this.opts.cols}`,
'export BROWSER=1',
]
for ( let i in document.location ){
if( typeof document.location[i] == 'string' ){
env.push( 'export '+String(i).toUpperCase()+'="'+decodeURIComponent( document.location[i]+'"') )
}
}
await this.worker.create_file("profile.browser", this.convert.toUint8Array( env.join('\n') ) )
if( this.serial_input == 0 ){
if( !this.noboot ){
this.send("source /etc/profile # \\o/ FOSS powa!\n")
}
}
}
// here REPL's can be defined
ISOTerminal.prototype.boot.menu = []
// REPL: iso
if( typeof window.PromiseWorker != 'undefined' ){ // if xrsh v86 is able to run in in worker
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: "j",
title: (opts) => "just give me an javascript-console in WebXR instantly",
init: function(){
this.prompt = "\r> "
this.emit('enable-console',{stdout:true})
this.emit('status',"javascript console")
this.console = ""
setTimeout( () => {
this.send(this.prompt)
}, 100 )
},
keyHandler: function(ch){
let erase = false
if( ch == '\x7F' ){
ch = "\b \b" // why does write() not just support \x7F ?
erase = true
}
this.send(ch)
const reset = () => {
this.console = ""
setTimeout( () => {
if( this.boot.menu.selected ) this.send(this.prompt)
},100)
}
if( (ch == "\n" || ch == "\r") ){
try{
this.send("\n\r")
if( this.console ) eval(this.console)
reset()
}catch(e){
reset()
throw e // re throw
}
}else{
if( erase ){
this.console = this.console.split('').slice(0,-1).join('')
}else{
this.console += ch
}
}
}
}
)