Prechádzať zdrojové kódy

dev: resize handling

KernelDeimos 8 mesiacov pred
rodič
commit
e1ec84877a

+ 24 - 0
src/emulator/src/main.js

@@ -108,9 +108,20 @@ window.onload = async function()
             on: function () {
                 const pty = this.getPTY();
                 console.log('PTY created', pty);
+
+                // resize
+                ptt.on('ioctl.set', evt => {
+                    console.log('event?', evt);
+                    pty.resize(evt.windowSize);
+                });
+                ptt.TIOCGWINSZ();
+
+                // data from PTY
                 pty.on_payload = data => {
                     ptt.out.write(data);
                 }
+
+                // data to PTY
                 (async () => {
                     // for (;;) {
                     //     const buff = await ptt.in.read();
@@ -205,6 +216,19 @@ window.onload = async function()
                 { data, direction: WispPacket.SEND });
             this.client.send(packet);
         }
+
+        resize ({ rows, cols }) {
+            console.log('resize called!');
+            const data = new DataBuilder({ leb: true })
+                .uint8(0xf0)
+                .uint32(this.streamId)
+                .uint16(rows)
+                .uint16(cols)
+                .build();
+            const packet = new WispPacket(
+                { data, direction: WispPacket.SEND });
+            this.client.send(packet);
+        }
     }
     
     const ptyMgr = new PTYManager({

+ 1 - 0
src/phoenix/src/ansi-shell/ANSIShell.js

@@ -219,6 +219,7 @@ export class ANSIShell extends EventTarget {
         }
 
         const executionCtx = this.ctx.sub({
+            shell: this,
             vars: this.variables,
             env: this.env,
             locals: {

+ 14 - 1
src/phoenix/src/puter-shell/providers/PuterAppCommandProvider.js

@@ -60,6 +60,17 @@ export class PuterAppCommandProvider {
                 };
                 const child = await puter.ui.launchApp(id, args);
 
+                const resize_listener = evt => {
+                    child.postMessage({
+                        $: 'ioctl.set',
+                        windowSize: {
+                            rows: evt.detail.rows,
+                            cols: evt.detail.cols,
+                        }
+                    });
+                };
+                ctx.shell.addEventListener('signal.window-resize', resize_listener);
+
                 // Wait for app to close.
                 const app_close_promise = new Promise((resolve, reject) => {
                     child.on('close', (data) => {
@@ -118,7 +129,9 @@ export class PuterAppCommandProvider {
                 }
 
                 // TODO: propagate sigint to the app
-                return Promise.race([ app_close_promise, sigint_promise ]);
+                const exit = await Promise.race([ app_close_promise, sigint_promise ]);
+                ctx.shell.removeEventListener('signal.window-resize', resize_listener);
+                return exit;
             }
         };
     }

+ 14 - 0
src/puter-wisp/src/exports.js

@@ -223,6 +223,20 @@ const wisp_types = [
             }
         }
     },
+    {
+        // TODO: extension types should not be hardcoded here
+        id: 0xf0,
+        label: 'RESIZE',
+        describe: ({ attributes }) => {
+            return `${attributes.cols}x${attributes.rows}`;
+        },
+        getAttributes ({ payload }) {
+            return {
+                rows: lib.get_int(2, payload),
+                cols: lib.get_int(2, payload.slice(2)),
+            }
+        }
+    },
 ];
 
 class WispPacket {