Skip to content

Commit e3d8e74

Browse files
authored
Remove all migration/compatibility code (#13)
* Remove all migration/compatibility code Phase 3: Clean up adapter layer and legacy type definitions. Changes: - Deleted lib/buffer-types.ts (28 lines) - legacy Cell/CellColor types - Removed TerminalAdapter class from terminal.ts (68 lines) - Refactored renderer.ts to work directly with GhosttyCell (WASM format) - Updated IRenderable interface: getLine() instead of getAllLines() - Removed colorToCSS() union type handler, replaced with rgbToCSS() - Updated all Cell references to GhosttyCell throughout renderer - Removed Cell/CellColor exports from public API (index.ts) - Cleaned up migration-related comments (ScreenBuffer/VTParser refs) Architecture: Renderer now consumes WASM cells directly with no conversion layer. All styling uses bitwise CellFlags instead of boolean properties.
1 parent 9626fbd commit e3d8e74

7 files changed

Lines changed: 131 additions & 181 deletions

File tree

demo/index.html

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,16 @@ <h3>📚 Available Commands</h3>
235235

236236
function connect() {
237237
updateStatus('connecting', 'Connecting to server...');
238-
console.log('Connecting to WebSocket:', WS_URL);
238+
239+
// Include terminal size in WebSocket URL
240+
console.log(`Terminal dimensions at connect time: ${term.cols}x${term.rows}`);
241+
const wsUrlWithSize = `${WS_URL}?cols=${term.cols}&rows=${term.rows}`;
242+
console.log('Connecting to WebSocket:', wsUrlWithSize);
239243

240244
// Show WebSocket URL in status bar
241245
document.getElementById('ws-url').textContent = WS_URL;
242246

243-
ws = new WebSocket(WS_URL);
247+
ws = new WebSocket(wsUrlWithSize);
244248

245249
ws.onopen = () => {
246250
updateStatus('connected', 'Connected (PTY mode)');
@@ -602,12 +606,21 @@ <h3>📚 Available Commands</h3>
602606

603607
// Fit terminal to container
604608
fitAddon.fit();
609+
console.log(`After fit(): Terminal size is ${term.cols}x${term.rows}`);
605610

606611
// Handle window resize
607612
window.addEventListener('resize', () => {
608613
fitAddon.fit();
609614
});
610615

616+
// Send resize notifications to server
617+
term.onResize(({ cols, rows }) => {
618+
if (ws && ws.readyState === WebSocket.OPEN) {
619+
ws.send(JSON.stringify({ type: 'resize', cols, rows }));
620+
console.log(`Sent resize to server: ${cols}x${rows}`);
621+
}
622+
});
623+
611624
// Handle input
612625
term.onData(handleInput);
613626

demo/server/pty-server.ts

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ const sessions = new Map<any, Session>();
3838
/**
3939
* Create a PTY shell session
4040
*/
41-
function createShell(cwd: string = process.cwd()) {
41+
function createShell(cwd: string = process.cwd(), cols: number = 80, rows: number = 24) {
4242
// Use 'script' command to create a real PTY
43+
console.log(`Creating PTY shell with size ${cols}x${rows}`);
44+
4345
// script -q -c "bash" /dev/null creates a PTY running bash
4446
const shell = spawn('script', ['-qfc', SHELL, '/dev/null'], {
4547
cwd: cwd,
@@ -51,6 +53,9 @@ function createShell(cwd: string = process.cwd()) {
5153
PS1: '\\[\\033[1;32m\\]\\w\\[\\033[0m\\] $ ',
5254
// Disable some escape sequences that cause artifacts
5355
PROMPT_COMMAND: '', // Disable dynamic prompt command
56+
// Set terminal size via environment variables (vim and other apps read these)
57+
COLUMNS: String(cols),
58+
LINES: String(rows),
5459
},
5560
stdio: ['pipe', 'pipe', 'pipe'],
5661
});
@@ -79,7 +84,14 @@ const server = Bun.serve({
7984
const url = new URL(req.url);
8085

8186
if (url.pathname === '/ws') {
82-
const success = server.upgrade(req);
87+
// Parse terminal size from query parameters before upgrade
88+
const cols = parseInt(url.searchParams.get('cols') || '80');
89+
const rows = parseInt(url.searchParams.get('rows') || '24');
90+
91+
// Pass size data to WebSocket via upgrade data
92+
const success = server.upgrade(req, {
93+
data: { cols, rows }
94+
});
8395
if (success) {
8496
return undefined;
8597
}
@@ -99,9 +111,14 @@ const server = Bun.serve({
99111

100112
websocket: {
101113
open(ws) {
114+
// Get terminal size from WebSocket data (set during upgrade)
115+
const { cols, rows } = (ws.data as any) || { cols: 80, rows: 24 };
116+
117+
console.log(`Client requested terminal size: ${cols}x${rows}`);
118+
102119
// Create new shell session for this client
103120
const sessionId = Math.random().toString(36).substring(7);
104-
const shell = createShell(homedir());
121+
const shell = createShell(homedir(), cols, rows);
105122

106123
const session: Session = {
107124
id: sessionId,
@@ -153,17 +170,25 @@ const server = Bun.serve({
153170
sessions.delete(ws);
154171
});
155172

156-
// Send initial welcome message and test WebSocket
157-
console.log(`[${session.id}] Sending welcome message to client`);
158-
ws.send('TEST: WebSocket is working!\r\n');
159-
ws.send('\x1b[1;36m╔══════════════════════════════════════════════════════════════╗\x1b[0m\r\n');
160-
ws.send('\x1b[1;36m║\x1b[0m \x1b[1;32mWelcome to Ghostty Terminal!\x1b[0m \x1b[1;36m║\x1b[0m\r\n');
161-
ws.send('\x1b[1;36m║\x1b[0m \x1b[1;36m║\x1b[0m\r\n');
162-
ws.send('\x1b[1;36m║\x1b[0m You now have a real shell session with full PTY support. \x1b[1;36m║\x1b[0m\r\n');
163-
ws.send('\x1b[1;36m║\x1b[0m Try: \x1b[1;33mls\x1b[0m, \x1b[1;33mcd\x1b[0m, \x1b[1;33mtop\x1b[0m, \x1b[1;33mvim\x1b[0m, or any command! \x1b[1;36m║\x1b[0m\r\n');
164-
ws.send('\x1b[1;36m╚══════════════════════════════════════════════════════════════╝\x1b[0m\r\n');
165-
ws.send('\r\n');
166-
console.log(`[${session.id}] Welcome message sent`);
173+
// Send stty command to resize the PTY
174+
// This runs inside the shell and sets the actual PTY size
175+
// Clear the line after to hide the command echo
176+
console.log(`[${session.id}] Setting PTY size via stty`);
177+
shell.stdin.write(`stty cols ${cols} rows ${rows}; clear\n`);
178+
179+
// Wait a bit for stty to execute, then send welcome
180+
setTimeout(() => {
181+
console.log(`[${session.id}] Sending welcome message to client`);
182+
ws.send('TEST: WebSocket is working!\r\n');
183+
ws.send('\x1b[1;36m╔══════════════════════════════════════════════════════════════╗\x1b[0m\r\n');
184+
ws.send('\x1b[1;36m║\x1b[0m \x1b[1;32mWelcome to Ghostty Terminal!\x1b[0m \x1b[1;36m║\x1b[0m\r\n');
185+
ws.send('\x1b[1;36m║\x1b[0m \x1b[1;36m║\x1b[0m\r\n');
186+
ws.send('\x1b[1;36m║\x1b[0m You now have a real shell session with full PTY support. \x1b[1;36m║\x1b[0m\r\n');
187+
ws.send('\x1b[1;36m║\x1b[0m Try: \x1b[1;33mls\x1b[0m, \x1b[1;33mcd\x1b[0m, \x1b[1;33mtop\x1b[0m, \x1b[1;33mvim\x1b[0m, or any command! \x1b[1;36m║\x1b[0m\r\n');
188+
ws.send('\x1b[1;36m╚══════════════════════════════════════════════════════════════╝\x1b[0m\r\n');
189+
ws.send('\r\n');
190+
console.log(`[${session.id}] Welcome message sent`);
191+
}, 100);
167192
},
168193

169194
message(ws, message) {
@@ -174,8 +199,24 @@ const server = Bun.serve({
174199
}
175200

176201
try {
177-
// Forward input to shell stdin
178202
const input = message.toString();
203+
204+
// Check if it's a resize message (JSON format: {"type":"resize","cols":N,"rows":N})
205+
if (input.startsWith('{')) {
206+
try {
207+
const msg = JSON.parse(input);
208+
if (msg.type === 'resize') {
209+
console.log(`[${session.id}] Resize request: ${msg.cols}x${msg.rows}`);
210+
// Note: 'script' command doesn't support dynamic resize,
211+
// but we log it for debugging. Use node-pty for full resize support.
212+
return;
213+
}
214+
} catch (e) {
215+
// Not JSON, treat as regular input
216+
}
217+
}
218+
219+
// Forward input to shell stdin
179220
console.log(`[${session.id}] Received input:`, JSON.stringify(input));
180221
session.ptyProcess.stdin.write(input);
181222
} catch (error: any) {

lib/buffer-types.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

lib/ghostty.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ export class KeyEncoder {
415415
/**
416416
* GhosttyTerminal - Wraps the WASM terminal emulator
417417
*
418-
* This replaces the TypeScript ScreenBuffer and VTParser with
419-
* Ghostty's complete terminal implementation via WASM.
418+
* Provides a TypeScript-friendly interface to Ghostty's complete
419+
* terminal implementation via WASM.
420420
*
421421
* @example
422422
* ```typescript
@@ -534,6 +534,13 @@ export class GhosttyTerminal {
534534
return this._rows;
535535
}
536536

537+
/**
538+
* Get terminal dimensions (for IRenderable compatibility)
539+
*/
540+
getDimensions(): { cols: number; rows: number } {
541+
return { cols: this._cols, rows: this._rows };
542+
}
543+
537544
/**
538545
* Get cursor position and visibility.
539546
*/

lib/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ export type {
3232
TerminalHandle
3333
} from './types';
3434

35-
// Legacy buffer types (for renderer compatibility)
36-
export type { Cell, CellColor } from './buffer-types';
37-
3835
// Low-level components (for custom integrations)
3936
export { CanvasRenderer } from './renderer';
4037
export type { RendererOptions, FontMetrics, IRenderable } from './renderer';

0 commit comments

Comments
 (0)