xrsh-com/com/isoterminal.js

219 lines
7.8 KiB
JavaScript
Raw Normal View History

2024-06-14 15:52:44 +02:00
AFRAME.registerComponent('isoterminal', {
schema: {
2024-07-04 23:00:44 +02:00
iso: { type:"string", "default":"com/isoterminal/xrsh.iso" },
cols: { type: 'number',"default": 120 },
rows: { type: 'number',"default": 30 },
padding:{ type: 'number',"default": 15 },
transparent: { type:'boolean', "default":false } // need good gpu
2024-06-14 15:52:44 +02:00
},
init: function(){
this.el.object3D.visible = false
},
requires:{
'window': "com/window.js",
2024-06-14 15:52:44 +02:00
winboxjs: "https://unpkg.com/winbox@0.2.82/dist/winbox.bundle.min.js", // deadsimple windows: https://nextapps-de.github.io/winbox
winboxcss: "https://unpkg.com/winbox@0.2.82/dist/css/winbox.min.css", //
xtermcss: "https://unpkg.com/xterm@3.12.0/dist/xterm.css",
xtermjs: "https://unpkg.com/xterm@3.12.0/dist/xterm.js",
2024-06-28 09:23:02 +02:00
v86: "com/isoterminal/libv86.js"
//axterm: "https://unpkg.com/aframe-xterm-component/aframe-xterm-component.js"
2024-06-14 15:52:44 +02:00
},
dom: {
scale: 0.7,
2024-06-14 15:52:44 +02:00
events: ['click','keydown'],
2024-06-28 16:59:27 +02:00
html: (me) => `<div class="isoterminal">
<div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
<canvas></canvas>
2024-06-28 16:59:27 +02:00
</div>`,
2024-06-14 15:52:44 +02:00
css: (me) => `.isoterminal{
2024-06-28 16:59:27 +02:00
background:#000;
2024-07-04 23:00:44 +02:00
padding: ${me.com.data.padding}px;
2024-06-28 16:59:27 +02:00
/*overflow:hidden; */
}
.isoterminal *{
white-space: pre;
font-size: 14px;
font-family: Liberation Mono,DejaVu Sans Mono,Courier New,monospace;
2024-07-03 11:34:29 +02:00
font-weight:700;
2024-07-04 23:00:44 +02:00
display:inline;
overflow: hidden;
2024-06-28 16:59:27 +02:00
}
2024-07-04 23:00:44 +02:00
.wb-body:has(> .isoterminal){ background: #000; }
.isoterminal div{ display:block; }
.isoterminal span{ display: inline }
2024-07-23 15:05:59 +02:00
@keyframes fade {
from { opacity: 1.0; }
50% { opacity: 0.5; }
to { opacity: 1.0; }
}
@-webkit-keyframes fade {
from { opacity: 1.0; }
50% { opacity: 0.5; }
to { opacity: 1.0; }
}
.blink {
animation:fade 1000ms infinite;
-webkit-animation:fade 1000ms infinite;
}
2024-07-04 23:00:44 +02:00
`
2024-06-14 15:52:44 +02:00
},
2024-06-28 16:59:27 +02:00
runISO: function(dom){
2024-07-04 23:00:44 +02:00
var emulator = window.emulator = dom.emulator = new V86({
2024-06-28 16:59:27 +02:00
wasm_path: "com/isoterminal/v86.wasm",
memory_size: 32 * 1024 * 1024,
vga_memory_size: 2 * 1024 * 1024,
screen_container: dom, //this.canvas.parentElement,
2024-06-28 09:23:02 +02:00
bios: {
url: "com/isoterminal/bios/seabios.bin",
},
vga_bios: {
url: "com/isoterminal/bios/vgabios.bin",
},
2024-06-28 16:59:27 +02:00
network_relay_url: "wss://relay.widgetry.org/",
2024-06-28 09:23:02 +02:00
cdrom: {
2024-06-28 16:59:27 +02:00
url: this.data.iso,
2024-06-28 09:23:02 +02:00
},
network_relay_url: "<UNUSED>",
2024-07-23 15:05:59 +02:00
cmdline: "rw root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose modules=virtio_pci tsc=reliable init_on_free=on init=/bin/date",
2024-06-28 16:59:27 +02:00
//bzimage:{
// url: "com/isoterminal/images/buildroot-bzimage.bin"
//},
//bzimage_initrd_from_filesystem: true,
//filesystem: {
// baseurl: "com/isoterminal/v86/images/alpine-rootfs-flat",
// basefs: "com/isoterminal/v86/images/alpine-fs.json",
// },
2024-07-23 15:05:59 +02:00
//screen_dummy: true,
2024-06-28 09:23:02 +02:00
autostart: true,
});
2024-07-04 23:00:44 +02:00
//setTimeout( () => {
// window.requestAnimationFrame = requestAnimationFrame
//},1000)
2024-06-14 15:52:44 +02:00
},
events:{
// combined AFRAME+DOM reactive events
click: function(e){ }, //
2024-07-04 23:00:44 +02:00
keydown: function(e){ },
2024-06-14 15:52:44 +02:00
// reactive events for this.data updates
myvalue: function(e){ this.el.dom.querySelector('b').innerText = this.data.myvalue },
ready: function( ){
this.el.dom.style.display = 'none'
},
launcher: async function(){
2024-07-23 15:05:59 +02:00
if( this.instance ){
const el = document.querySelector('.isoterminal')
el.classList.add('blink')
setTimeout( () => el.classList.remove('blink'), 2000 )
return console.warn('TODO: allow multiple terminals (see v86 examples)')
}
2024-06-14 15:52:44 +02:00
let s = await AFRAME.utils.require(this.requires)
// instance this component
2024-07-23 15:05:59 +02:00
const instance = this.instance = this.el.cloneNode(false)
2024-06-14 15:52:44 +02:00
this.el.sceneEl.appendChild( instance )
instance.addEventListener('DOMready', () => {
2024-06-28 16:59:27 +02:00
this.runISO(instance.dom)
2024-07-04 23:00:44 +02:00
instance.setAttribute("window", `title: ${this.data.iso}; uid: ${instance.uid}; attach: #overlay; dom: #${instance.dom.id}`)
})
instance.addEventListener('window.oncreate', (e) => {
2024-07-23 15:05:59 +02:00
instance.dom.classList.add('blink')
2024-07-04 23:00:44 +02:00
// resize after the dom content has been rendered & updated
setTimeout( () => {
let spans = [...instance.dom.querySelectorAll('span')]
instance.winbox.resize(
(spans[0].offsetWidth + (2*this.data.padding))+'px',
((spans.length * spans[0].offsetHeight) ) +'px'
)
},1200)
2024-07-23 15:05:59 +02:00
setTimeout( () => instance.dom.classList.remove('blink'), 5000 )
})
2024-06-14 15:52:44 +02:00
instance.addEventListener('window.onclose', (e) => {
if( !confirm('do you want to kill this virtual machine and all its processes?') ) e.halt = true
})
2024-06-14 15:52:44 +02:00
instance.setAttribute("dom", "")
instance.setAttribute("xd", "") // allows flipping between DOM/WebGL when toggling XD-button
instance.setAttribute("visible", AFRAME.utils.XD() == '3D' ? 'true' : 'false' )
instance.setAttribute("position", AFRAME.utils.XD.getPositionInFrontOfCamera(0.5) )
instance.setAttribute("grabbable","")
2024-06-14 15:52:44 +02:00
2024-07-04 23:00:44 +02:00
const focus = () => document.querySelector('canvas.a-canvas').focus()
instance.addEventListener('obbcollisionstarted', focus )
this.el.sceneEl.addEventListener('enter-vr', focus )
2024-07-03 11:34:29 +02:00
instance.object3D.quaternion.copy( AFRAME.scenes[0].camera.quaternion ) // face towards camera
2024-07-04 23:00:44 +02:00
}
2024-06-14 15:52:44 +02:00
},
manifest: { // HTML5 manifest to identify app to xrsh
"iso": "linux-x64-4.15.iso",
"short_name": "ISOTerm",
"name": "terminal",
"icons": [
{
"src": "https://css.gg/terminal.svg",
"type": "image/svg+xml",
"sizes": "512x512"
}
],
"id": "/?source=pwa",
"start_url": "/?source=pwa",
"background_color": "#3367D6",
"display": "standalone",
"scope": "/",
"theme_color": "#3367D6",
"shortcuts": [
{
"name": "What is the latest news?",
"cli":{
"usage": "helloworld <type> [options]",
"example": "helloworld news",
"args":{
"--latest": {type:"string"}
}
},
"short_name": "Today",
"description": "View weather information for today",
"url": "/today?source=pwa",
"icons": [{ "src": "/images/today.png", "sizes": "192x192" }]
}
],
"description": "Hello world information",
"screenshots": [
{
"src": "/images/screenshot1.png",
"type": "image/png",
"sizes": "540x720",
"form_factor": "narrow"
}
],
"help":`
Helloworld application
This is a help file which describes the application.
It will be rendered thru troika text, and will contain
headers based on non-punctualized lines separated by linebreaks,
in above's case "\nHelloworld application\n" will qualify as header.
`
}
});