@@ -186,25 +186,38 @@ Bidirectional, event-driven connection to a session.
186186
187187``` typescript
188188const conn = new SessionConnection ({ name: " myserver" , rows: 24 , cols: 80 });
189- const initialScreen = await conn .connect ();
190189
190+ conn .on (" geometry" , ({ rows , cols }) => {
191+ // Resize your emulator before the following screen/data bytes are parsed.
192+ terminal .resize (cols , rows );
193+ });
191194conn .on (" data" , (data : string ) => { /* terminal output */ });
192195conn .on (" exit" , (code : number ) => { /* process exited */ });
193196conn .on (" close" , () => { /* connection closed */ });
194197conn .on (" error" , (err : Error ) => { /* connection error */ });
195198
199+ const initialScreen = await conn .connect ();
200+ // Initial GEOMETRY is stream-ordered before SCREEN. The effective getters are
201+ // therefore authoritative before applying the returned replay.
202+ terminal .resize (conn .effectiveCols , conn .effectiveRows );
203+ terminal .write (initialScreen );
204+
196205conn .write (" hello\r " ); // send raw data
197206conn .press (" ctrl+c" ); // send named key
198- conn .resize (30 , 100 ); // resize terminal
207+ conn .resize (30 , 100 ); // request a shared-grid size
199208conn .disconnect (); // close connection
200209```
201210
202211** Properties:**
203212- ` connected: boolean ` — whether the connection is active
213+ - ` effectiveRows: number ` / ` effectiveCols: number ` — current authoritative
214+ shared-grid dimensions. These can differ from the client's requested size
215+ when another writable client is smaller.
204216
205217** Events:**
206218| Event | Payload | Description |
207219| ---| ---| ---|
220+ | ` geometry ` | ` { rows, cols } ` | Effective shared geometry, ordered before affected ` screen ` /` data ` |
208221| ` data ` | ` string ` | Terminal output from the session |
209222| ` screen ` | ` string ` | Initial screen replay on connect |
210223| ` exit ` | ` number ` | Session process exited with code |
@@ -384,9 +397,15 @@ const MessageType = {
384397 SCREEN: 5 , // Screen replay
385398 PEEK: 6 , // Read-only peek request
386399 STATUS: 7 , // Stats query/response
400+ GEOMETRY: 10 , // Effective shared rows/cols (server → client)
387401};
388402```
389403
404+ Packet types are length-delimited. Clients predating ` GEOMETRY ` ignore the
405+ unknown bounded packet and continue with following ` SCREEN ` /` DATA ` , preserving
406+ their historical raw-byte behavior. Embedders that reconstruct a terminal grid
407+ must handle ` GEOMETRY ` .
408+
390409### ` TERMINAL_SANITIZE: string `
391410
392411ANSI sequence that resets all terminal modes (mouse tracking, cursor visibility, alternate screen, etc.). Useful after disconnecting from a session.
0 commit comments