Skip to content

Commit

Permalink
dev: resize handling
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Sep 18, 2024
1 parent db3e0b5 commit e1ec848
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/emulator/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/phoenix/src/ansi-shell/ANSIShell.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export class ANSIShell extends EventTarget {
}

const executionCtx = this.ctx.sub({
shell: this,
vars: this.variables,
env: this.env,
locals: {
Expand Down
15 changes: 14 additions & 1 deletion src/phoenix/src/puter-shell/providers/PuterAppCommandProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
}
};
}
Expand Down
14 changes: 14 additions & 0 deletions src/puter-wisp/src/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e1ec848

Please sign in to comment.