diff --git a/src/phoenix/src/ansi-shell/ANSIShell.js b/src/phoenix/src/ansi-shell/ANSIShell.js index 93df6c31..580ba2b7 100644 --- a/src/phoenix/src/ansi-shell/ANSIShell.js +++ b/src/phoenix/src/ansi-shell/ANSIShell.js @@ -91,7 +91,10 @@ export class ANSIShell extends EventTarget { }) Object.defineProperty(this.env, 'COLS', { enumerable: true, - get: () => this.variables.size?.cols ?? 0 + get: () => { + const v = this.variables.size?.cols ?? 0 + return v; + } }) this.export_('LANG', 'en_US.UTF-8'); diff --git a/src/phoenix/src/main_puter.js b/src/phoenix/src/main_puter.js index 85dc0af0..01e03391 100644 --- a/src/phoenix/src/main_puter.js +++ b/src/phoenix/src/main_puter.js @@ -30,10 +30,11 @@ window.main_shell = async () => { .entries() ); - let resolveConfigured = null; - const configured_ = new Promise(rslv => { - resolveConfigured = rslv; - }); + // let resolveConfigured = null; + // const configured_ = new Promise(rslv => { + // resolveConfigured = rslv; + // }); + const puterSDK = globalThis.puter; const terminal = puter.ui.parentApp(); if (!terminal) { @@ -45,9 +46,10 @@ window.main_shell = async () => { if (message.$ === 'config') { const configValues = { ...message }; // Only copy the config that we actually need - config['puter.auth.username'] = configValues['puter.auth.username']; + // config['puter.auth.username'] = configValues['puter.auth.username']; config['puter.auth.token'] = configValues['puter.auth.token']; - resolveConfigured(); + // console.log('set!'); + // resolveConfigured(); } }); terminal.on('close', () => { @@ -59,14 +61,17 @@ window.main_shell = async () => { terminal.postMessage({ $: 'ready' }); - await configured_; - - const puterSDK = globalThis.puter; - if ( config['puter.auth.token'] ) { - await puterSDK.setAuthToken(config['puter.auth.token']); - } - const ptt = new XDocumentPTT(terminal); + + // await configured_; + const user = await puterSDK.auth.getUser(); + config['puter.auth.username'] = user.username; + // await new Promise(rslv => setTimeout(rslv, 0)); + + // if ( config['puter.auth.token'] ) { + // await puterSDK.setAuthToken(config['puter.auth.token']); + // } + await launchPuterShell(new Context({ ptt, config, puterSDK, diff --git a/src/phoenix/src/pty/XDocumentPTT.js b/src/phoenix/src/pty/XDocumentPTT.js index e9afbb6f..3ea15e56 100644 --- a/src/phoenix/src/pty/XDocumentPTT.js +++ b/src/phoenix/src/pty/XDocumentPTT.js @@ -21,7 +21,26 @@ import { BetterReader } from "dev-pty"; const encoder = new TextEncoder(); export class XDocumentPTT { + static IOCTL = { + TIOCGWINSZ: { + id: 104, + }, + } constructor(terminalConnection) { + for ( const k in XDocumentPTT.IOCTL ) { + this[k] = async () => { + return await new Promise((resolve, reject) => { + terminalConnection.postMessage({ + $: 'ioctl.request', + requestCode: XDocumentPTT.IOCTL[k].id, + }); + this.once('ioctl.set', evt => { + resolve(evt); + }); + }); + }; + } + this.ioctl_listeners = {}; this.readableStream = new ReadableStream({ diff --git a/src/phoenix/src/puter-shell/main.js b/src/phoenix/src/puter-shell/main.js index 8c200a92..7ba7f882 100644 --- a/src/phoenix/src/puter-shell/main.js +++ b/src/phoenix/src/puter-shell/main.js @@ -136,6 +136,9 @@ export const launchPuterShell = async (ctx) => { })); }); + // NEXT + ptt.TIOCGWINSZ(); + const fire = (text) => { // Define fire-like colors (ANSI 256-color codes) const fireColors = [202, 208, 166]; diff --git a/src/terminal/src/pty/XDocumentANSIShell.js b/src/terminal/src/pty/XDocumentANSIShell.js index 953659ec..e7930146 100644 --- a/src/terminal/src/pty/XDocumentANSIShell.js +++ b/src/terminal/src/pty/XDocumentANSIShell.js @@ -29,6 +29,14 @@ export class XDocumentANSIShell { shell.on('message', message => { // When the shell reports it's ready, send configuration + if (message.$ === 'ioctl.request') { + if (message.requestCode === 104) { + shell.postMessage({ + $: 'ioctl.set', + windowSize: this.internal_.windowSize, + }); + } + } if (message.$ === 'ready') { const params = Object.fromEntries( new URLSearchParams(window.location.search)