Skip to content

Commit a33d721

Browse files
committed
fix phoenix WINSZ handling
1 parent 7139d29 commit a33d721

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-13
lines changed

src/phoenix/src/ansi-shell/ANSIShell.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export class ANSIShell extends EventTarget {
9191
})
9292
Object.defineProperty(this.env, 'COLS', {
9393
enumerable: true,
94-
get: () => this.variables.size?.cols ?? 0
94+
get: () => {
95+
const v = this.variables.size?.cols ?? 0
96+
return v;
97+
}
9598
})
9699

97100
this.export_('LANG', 'en_US.UTF-8');

src/phoenix/src/main_puter.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ window.main_shell = async () => {
3030
.entries()
3131
);
3232

33-
let resolveConfigured = null;
34-
const configured_ = new Promise(rslv => {
35-
resolveConfigured = rslv;
36-
});
33+
// let resolveConfigured = null;
34+
// const configured_ = new Promise(rslv => {
35+
// resolveConfigured = rslv;
36+
// });
37+
const puterSDK = globalThis.puter;
3738

3839
const terminal = puter.ui.parentApp();
3940
if (!terminal) {
@@ -45,9 +46,10 @@ window.main_shell = async () => {
4546
if (message.$ === 'config') {
4647
const configValues = { ...message };
4748
// Only copy the config that we actually need
48-
config['puter.auth.username'] = configValues['puter.auth.username'];
49+
// config['puter.auth.username'] = configValues['puter.auth.username'];
4950
config['puter.auth.token'] = configValues['puter.auth.token'];
50-
resolveConfigured();
51+
// console.log('set!');
52+
// resolveConfigured();
5153
}
5254
});
5355
terminal.on('close', () => {
@@ -59,14 +61,17 @@ window.main_shell = async () => {
5961

6062
terminal.postMessage({ $: 'ready' });
6163

62-
await configured_;
64+
const ptt = new XDocumentPTT(terminal);
6365

64-
const puterSDK = globalThis.puter;
65-
if ( config['puter.auth.token'] ) {
66-
await puterSDK.setAuthToken(config['puter.auth.token']);
67-
}
66+
// await configured_;
67+
const user = await puterSDK.auth.getUser();
68+
config['puter.auth.username'] = user.username;
69+
// await new Promise(rslv => setTimeout(rslv, 0));
70+
71+
// if ( config['puter.auth.token'] ) {
72+
// await puterSDK.setAuthToken(config['puter.auth.token']);
73+
// }
6874

69-
const ptt = new XDocumentPTT(terminal);
7075
await launchPuterShell(new Context({
7176
ptt,
7277
config, puterSDK,

src/phoenix/src/pty/XDocumentPTT.js

+19
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,26 @@ import { BetterReader } from "dev-pty";
2121
const encoder = new TextEncoder();
2222

2323
export class XDocumentPTT {
24+
static IOCTL = {
25+
TIOCGWINSZ: {
26+
id: 104,
27+
},
28+
}
2429
constructor(terminalConnection) {
30+
for ( const k in XDocumentPTT.IOCTL ) {
31+
this[k] = async () => {
32+
return await new Promise((resolve, reject) => {
33+
terminalConnection.postMessage({
34+
$: 'ioctl.request',
35+
requestCode: XDocumentPTT.IOCTL[k].id,
36+
});
37+
this.once('ioctl.set', evt => {
38+
resolve(evt);
39+
});
40+
});
41+
};
42+
}
43+
2544
this.ioctl_listeners = {};
2645

2746
this.readableStream = new ReadableStream({

src/phoenix/src/puter-shell/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ export const launchPuterShell = async (ctx) => {
136136
}));
137137
});
138138

139+
// NEXT
140+
ptt.TIOCGWINSZ();
141+
139142
const fire = (text) => {
140143
// Define fire-like colors (ANSI 256-color codes)
141144
const fireColors = [202, 208, 166];

src/terminal/src/pty/XDocumentANSIShell.js

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export class XDocumentANSIShell {
2929

3030
shell.on('message', message => {
3131
// When the shell reports it's ready, send configuration
32+
if (message.$ === 'ioctl.request') {
33+
if (message.requestCode === 104) {
34+
shell.postMessage({
35+
$: 'ioctl.set',
36+
windowSize: this.internal_.windowSize,
37+
});
38+
}
39+
}
3240
if (message.$ === 'ready') {
3341
const params = Object.fromEntries(
3442
new URLSearchParams(window.location.search)

0 commit comments

Comments
 (0)