Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions demo/bin/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,16 @@ const HTML_TEMPLATE = `<!doctype html>
padding: 0;
min-height: 400px;
height: 60vh;
position: relative;
}

#terminal {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
}
</style>
</head>
Expand Down Expand Up @@ -203,6 +208,7 @@ const HTML_TEMPLATE = `<!doctype html>
const container = document.getElementById('terminal');
await term.open(container);
fitAddon.fit();
fitAddon.observeResize(); // Auto-fit when container resizes

// Status elements
const statusDot = document.getElementById('status-dot');
Expand Down Expand Up @@ -249,13 +255,17 @@ const HTML_TEMPLATE = `<!doctype html>
}
});

// Handle resize
window.addEventListener('resize', () => {
fitAddon.fit();
// Handle resize - notify PTY when terminal dimensions change
term.onResize(({ cols, rows }) => {
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'resize', cols: term.cols, rows: term.rows }));
ws.send(JSON.stringify({ type: 'resize', cols, rows }));
}
});

// Also handle window resize (for browsers that don't trigger ResizeObserver on window resize)
window.addEventListener('resize', () => {
fitAddon.fit();
});
</script>
</body>
</html>`;
Expand Down
2 changes: 1 addition & 1 deletion demo/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
let ws;
let fitAddon;

function initTerminal() {
async function initTerminal() {
term = new Terminal({
cursorBlink: true,
fontSize: 14,
Expand All @@ -153,10 +153,11 @@
fitAddon = new FitAddon();
term.loadAddon(fitAddon);

term.open(document.getElementById('terminal-container'));
await term.open(document.getElementById('terminal-container'));
fitAddon.fit();
fitAddon.observeResize(); // Auto-fit when container resizes

// Handle window resize
// Handle window resize (for browsers that don't trigger ResizeObserver on window resize)
window.addEventListener('resize', () => {
fitAddon.fit();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Terminal implements ITerminalCore {
// Components (created on open())
private ghostty?: Ghostty;
public wasmTerm?: GhosttyTerminal; // Made public for link providers
private renderer?: CanvasRenderer;
public renderer?: CanvasRenderer; // Made public for FitAddon
private inputHandler?: InputHandler;
private selectionManager?: SelectionManager;
private canvas?: HTMLCanvasElement;
Expand Down