Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions src/cli/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { configDir, loadConfig } from '../config';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/** Active server port, resolved from `PORT` env or config default. */
export const PORT = Number(process.env.PORT) || 2346;
/** Active server port, resolved from config (env PORT is intentionally ignored). */
export const PORT = loadConfig().port;

/** Base URL for internal CLI↔server API calls (always 127.0.0.1, avoids IPv6 lookup). */
export const BASE_URL = `http://127.0.0.1:${PORT}`;
Comment thread
jesse23 marked this conversation as resolved.
Outdated
Expand Down
31 changes: 31 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ function fit(): void {

fit();
new ResizeObserver(() => fit()).observe(container, { box: 'border-box' });
// ResizeObserver misses monitor hot-plug and DPI changes because those resize
// the viewport without changing the container's layout box. window resize fires
// reliably for both, so use both observers together.
window.addEventListener('resize', fit);
Comment thread
jesse23 marked this conversation as resolved.
Outdated

const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
let ws: WebSocket;
Expand Down Expand Up @@ -139,6 +143,33 @@ function connect(): void {

connect();

// When dragging inside the terminal (e.g. vim split resize), the pointer can
// leave the canvas boundary and the browser stops delivering mousemove to it.
// Setting pointer capture on the canvas on pointerdown redirects all subsequent
// pointer and synthesized mouse events to that element for the duration of the
// press, so drags never lose tracking mid-gesture.
container.addEventListener(
'pointerdown',
(e: PointerEvent) => {
const canvas = container.querySelector('canvas');
canvas?.setPointerCapture(e.pointerId);
},
);

// ghostty-web reports hover mousemove events (e.buttons === 0) as button-32
// SGR drags to the PTY. Vim with `set mouse=a` interprets button-32 as
// "extend selection" and enters visual mode. Block no-button mousemove events
// before ghostty-web sees them so hover never triggers a drag report.
container.addEventListener(
'mousemove',
(e: MouseEvent) => {
if (term.hasMouseTracking() && e.buttons === 0) {
e.stopPropagation();
}
},
{ capture: true },
);

// ghostty-web's Terminal.handleWheel sends \x1b[A/\x1b[B (arrow keys) on the
// alternate screen regardless of mouse tracking state, moving the cursor instead
// of scrolling. When the PTY application has enabled mouse tracking (e.g. vim
Expand Down
3 changes: 2 additions & 1 deletion src/pty/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type { PtyProcess } from './types';

const isBun = !!process.versions.bun;
// Bun.Terminal does not support the `terminal` option on Windows; fall back to node-pty.
const isBun = !!process.versions.bun && process.platform !== 'win32';
console.log(`pty: ${isBun ? 'Bun.Terminal' : 'node-pty'}`);

const { spawn: _spawn } = await (isBun ? import('./bun') : import('./node'));
Comment thread
jesse23 marked this conversation as resolved.
Outdated
Expand Down
2 changes: 1 addition & 1 deletion src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const config = loadConfig();
const HTTP_PORT = Number(process.env.PORT) || config.port;
const HTTP_PORT = config.port;
// 'localhost' resolves to ::1 (IPv6) on modern macOS/Node; bind to 127.0.0.1 instead
// but keep 'localhost' as the display host so browser URLs use it as intended.
const HTTP_HOST_DISPLAY = config.host;
Expand Down
Loading