Skip to content

Conversation

@sreya
Copy link
Contributor

@sreya sreya commented Nov 20, 2025

No description provided.

sreya added 21 commits November 20, 2025 20:15
- Add bin/ghostty-web.js with inline HTML, WebSocket server, and PTY support
- Implement minimal WebSocket server using only Node.js built-ins (no deps)
- Single file implementation (~624 lines, 16KB)
- Auto-opens browser to http://localhost:8080
- Usage: npx ghostty-web

All functionality inlined:
- HTML template with styling
- Minimal WebSocket protocol implementation
- PTY session handler using child_process.spawn
- HTTP file server for library and WASM
- Graceful shutdown handling

Size impact: +16KB bin script only (package stays dependency-free)
- Pass -i flag to bash/zsh for interactive mode
- Shell now displays prompt and responds to commands
- Fixes issue where terminal loaded but no shell appeared
- Send \n when WebSocket connects to trigger prompt display
- Add console logging for debugging data flow
- Shell now displays prompt immediately on connection
- Hardcode port 8080 in client-side WebSocket URL
- Fixes syntax error: Invalid or unexpected token
- Template literal was incorrectly interpolating server-side variable
- Change \\n to \\\\n in source (4 backslashes)
- Outputs \\n in HTML (valid JS string with newline char)
- Fixes: Uncaught SyntaxError: Invalid or unexpected token
- Add route for __vite-browser-external-2447137e.js
- Log actual received data for debugging
- Fixes 404 error for vite internal file
- Move newline trigger from client to server-side
- Send to ptyProcess.stdin.write() after 100ms
- Should properly trigger shell prompt display
- Use 'script -qfc' to create proper PTY instead of plain spawn
- Filter OSC sequences (window title) that were causing artifacts
- Pass COLUMNS and LINES env vars for terminal size
- Matches working implementation in demo/server/pty-server.ts
- Send stty cols/rows command after spawn to set initial size
- Handle resize messages with stty command instead of no-op
- Clear screen after initial stty to hide command echo
- Matches demo/server/pty-server.ts implementation
- Log client-side input being sent
- Log server-side input being received
- Helps debug vim keyboard issues (0, 15gg not working)
- Copy HTML/CSS/JS verbatim from working demo
- Remove debug logging from client-side
- Use exact same Terminal initialization
- Use exact same WebSocket handling
- Should fix vim keyboard issues (0, 15gg, etc)
- Wrap stderr in red escape codes like demo
- Remove debug logging that might interfere
- Server code now matches demo/server/pty-server.ts output handling
- Known issue: vim commands like 0, 15gg don't work
- Suspected cause: MinimalWebSocket implementation bug
- Working demo with Bun WebSocket works fine
- Document workaround and potential fixes
- Log raw WebSocket data received (hex)
- Log parsed frame details (opcode, payload)
- Log data written to PTY stdin
- Log data sent from PTY stdout to client
- Will help identify where vim '0' command is lost
BUG: Characters like '0' are valid JSON and would parse successfully,
then be ignored because they're not resize messages.

FIX: Check if parsed JSON is an object with type='resize' first.
Always fall through to treating data as terminal input unless it's
explicitly a control message.

This fixes vim commands like 0, gg, etc that were being dropped.
Bug is fixed, remove verbose logging to keep output clean
Complete working implementation of npx ghostty-web demo launcher
Fixes lint errors:
- Use for...of instead of forEach in emit()
- Use for...of instead of forEach in cleanup()
@sreya sreya merged commit 5e035a2 into main Nov 20, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant