dev: update emu load indicator

This commit is contained in:
KernelDeimos 2024-09-30 16:50:03 -04:00
parent 04c05a5bb8
commit 6e1ed7ab04
7 changed files with 35 additions and 9 deletions

9
package-lock.json generated
View File

@ -7296,6 +7296,14 @@
"@xterm/xterm": "^5.0.0" "@xterm/xterm": "^5.0.0"
} }
}, },
"node_modules/@xterm/addon-image": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/@xterm/addon-image/-/addon-image-0.8.0.tgz",
"integrity": "sha512-b/dqpFn3jUad2pUP5UpF4scPIh0WdxRQL/1qyiahGfUI85XZTCXo0py9G6AcOR2QYUw8eJ8EowGspT7BQcgw6A==",
"peerDependencies": {
"@xterm/xterm": "^5.2.0"
}
},
"node_modules/@xterm/xterm": { "node_modules/@xterm/xterm": {
"version": "5.5.0", "version": "5.5.0",
"resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-5.5.0.tgz", "resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-5.5.0.tgz",
@ -17436,6 +17444,7 @@
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"dependencies": { "dependencies": {
"@xterm/addon-fit": "^0.10.0", "@xterm/addon-fit": "^0.10.0",
"@xterm/addon-image": "^0.8.0",
"@xterm/xterm": "^5.5.0" "@xterm/xterm": "^5.5.0"
}, },
"devDependencies": { "devDependencies": {

View File

@ -115,6 +115,11 @@ const setup_pty = (ptt, pty) => {
})() })()
} }
let TUX_SIXEL; (async () => {
const resp = await fetch('./static/tux.sixel');
const text = await resp.text();
TUX_SIXEL = text;
})();
puter.ui.on('connection', event => { puter.ui.on('connection', event => {
const { conn, accept, reject } = event; const { conn, accept, reject } = event;
@ -131,6 +136,7 @@ puter.ui.on('connection', event => {
accept({ accept({
version: '1.0.0', version: '1.0.0',
status, status,
logo: TUX_SIXEL,
}); });
console.log('emulator got connection event', event); console.log('emulator got connection event', event);

1
src/emulator/tux.sixel Normal file

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,8 @@ module.exports = {
}), }),
new CopyPlugin({ new CopyPlugin({
patterns: [ patterns: [
{ from: 'benchmark', to: 'static' } { from: 'benchmark', to: 'static' },
{ from: 'tux.sixel', to: 'static' },
] ]
}) })
] ]

View File

@ -40,6 +40,7 @@ export class EmuCommandProvider {
let prev_phase = 'init'; let prev_phase = 'init';
let progress_shown = false; let progress_shown = false;
let tux_enabled = false; let tux_enabled = false;
const leftpadd = 10;
const on_message = message => { const on_message = message => {
if ( message.$ !== 'status' ) { if ( message.$ !== 'status' ) {
console.log('[!!] message from the emulator', message); console.log('[!!] message from the emulator', message);
@ -53,21 +54,22 @@ export class EmuCommandProvider {
if ( message.phase === 'ready' ) { if ( message.phase === 'ready' ) {
if ( progress_shown ) { if ( progress_shown ) {
// show complete progress so it doesn't look weird // show complete progress so it doesn't look weird
ctx.externs.out.write('\r[' + '='.repeat(ctx.env.COLS-2) + ']\n'); ctx.externs.out.write(`\r\x1B[${leftpadd}C[` +
'='.repeat(ctx.env.COLS-2-leftpadd) + ']\n');
} }
p_ready.resolve(); p_ready.resolve();
return; return;
} }
if ( message.phase !== prev_phase ) { if ( message.phase !== prev_phase ) {
progress_shown = false; progress_shown = false;
ctx.externs.out.write(`phase: ${message.phase}\n`); ctx.externs.out.write(`\r\x1B[${leftpadd}Cphase: ${message.phase}\n`);
prev_phase = message.phase; prev_phase = message.phase;
} }
if ( message.phase_progress ) { if ( message.phase_progress ) {
progress_shown = true; progress_shown = true;
let w = ctx.env.COLS; let w = ctx.env.COLS;
w -= 2; w -= 2 + leftpadd;
ctx.externs.out.write('\r['); ctx.externs.out.write(`\r\x1B[${leftpadd}C[`);
const done = Math.floor(message.phase_progress * w); const done = Math.floor(message.phase_progress * w);
for ( let i=0 ; i < done ; i++ ) { for ( let i=0 ; i < done ; i++ ) {
ctx.externs.out.write('='); ctx.externs.out.write('=');
@ -83,9 +85,12 @@ export class EmuCommandProvider {
if ( conn.response.status.ready ) { if ( conn.response.status.ready ) {
p_ready.resolve(); p_ready.resolve();
} else { } else {
tux_enabled = true;
conn.response.status.$ = 'status'; conn.response.status.$ = 'status';
ctx.externs.out.write('\x1B[36;1mWaiting for emulator to be ready...\x1B[0m\n'); ctx.externs.out.write(' Puter Linux is starting...\n');
ctx.externs.out.write(' (Alpine Linux edge i686)\n');
ctx.externs.out.write('\x1B[2A');
ctx.externs.out.write(conn.response.logo + '\n');
ctx.externs.out.write('\x1B[2A');
on_message(conn.response.status); on_message(conn.response.status);
} }
console.log('status from emu', conn.response); console.log('status from emu', conn.response);

View File

@ -19,7 +19,8 @@
"rollup-plugin-copy": "^3.4.0" "rollup-plugin-copy": "^3.4.0"
}, },
"dependencies": { "dependencies": {
"@xterm/xterm": "^5.5.0", "@xterm/addon-fit": "^0.10.0",
"@xterm/addon-fit": "^0.10.0" "@xterm/addon-image": "^0.8.0",
"@xterm/xterm": "^5.5.0"
} }
} }

View File

@ -18,6 +18,7 @@
*/ */
import { Terminal } from '@xterm/xterm'; import { Terminal } from '@xterm/xterm';
import { FitAddon } from '@xterm/addon-fit'; import { FitAddon } from '@xterm/addon-fit';
import { ImageAddon } from '@xterm/addon-image';
import { PTY } from './pty/PTY'; import { PTY } from './pty/PTY';
import { XDocumentANSIShell } from './pty/XDocumentANSIShell'; import { XDocumentANSIShell } from './pty/XDocumentANSIShell';
@ -98,6 +99,8 @@ window.main_term = async () => {
const term = new Terminal({ const term = new Terminal({
linkHandler, linkHandler,
}); });
const imageAddon = new ImageAddon();
term.loadAddon(imageAddon);
term.open(document.getElementById('terminal')); term.open(document.getElementById('terminal'));
const fitAddon = new FitAddon(); const fitAddon = new FitAddon();