mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
dev: resize handling
This commit is contained in:
parent
db3e0b5ce8
commit
e1ec84877a
@ -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({
|
||||
|
@ -219,6 +219,7 @@ export class ANSIShell extends EventTarget {
|
||||
}
|
||||
|
||||
const executionCtx = this.ctx.sub({
|
||||
shell: this,
|
||||
vars: this.variables,
|
||||
env: this.env,
|
||||
locals: {
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user