Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
## [Unreleased]

### Fixed
- A resized terminal sends an in-band size report while the program has
mode 2048 on, as Ghostty does. Neovim enables the mode and then ignores
SIGWINCH, so it kept drawing at the size it started with.
- evil-ghostel: the editing operators and insert-state Ctrl keys drive the
shell in a bridged terminal, such as a rexel or ghostel-tmux buffer.
- A `file://` link without a host, or with `localhost`, opens on the remote
Expand Down
14 changes: 12 additions & 2 deletions src/GhostelTerm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const Allocator = std.mem.Allocator;

const emacs = @import("emacs.zig");
const gt = @import("ghostty-vt");
const GhostelHandler = @import("handler.zig").GhostelHandler;
const handler = @import("handler.zig");
const GhostelHandler = handler.GhostelHandler;
const Renderer = @import("Renderer.zig");
const RecursiveMutex = @import("RecursiveMutex.zig");
const input = @import("input.zig");
Expand Down Expand Up @@ -102,20 +103,29 @@ pub fn redraw(self: *Self, force_full: bool, force_sync: bool) !bool {
const env = emacs.current_env orelse return false;
const pre_size = .{ self.terminal.cols, self.terminal.rows };
if (!try self.renderer.redraw(env, force_full, force_sync)) return false;
const resized = !std.meta.eql(pre_size, .{ self.terminal.cols, self.terminal.rows });

if (self.process) |proc| {
const size = self.winSize();
if (!std.meta.eql(size, self.pty_size)) {
try proc.resizePty(size);
self.pty_size = size;
}
} else if (!std.meta.eql(pre_size, .{ self.terminal.cols, self.terminal.rows })) {
} else if (resized) {
// Emacs-owned PTYs carry no pixel geometry.
const process = env.symbolValue("ghostel--process");
if (env.isNotNil(process)) {
_ = env.f("set-process-window-size", .{ process, self.terminal.rows, self.terminal.cols });
}
}

// Programs with mode 2048 on, such as Neovim, ignore SIGWINCH.
if (resized and self.terminal.modes.get(.in_band_size_reports)) {
var buf: [64]u8 = undefined;
var writer = std.Io.Writer.fixed(&buf);
try gt.size_report.encode(&writer, .mode_2048, handler.reportedSize(&self.terminal));
try self.ptyWrite(writer.buffered());
}
return true;
}

Expand Down
16 changes: 10 additions & 6 deletions src/handler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const log = std.log.scoped(.GhostelHandler);
// xterm limits the title stack to 10 entries.
const title_stack_max = 10;

pub fn reportedSize(terminal: *const gt.Terminal) gt.size_report.Size {
return .{
.rows = terminal.rows,
.columns = terminal.cols,
.cell_width = terminal.width_px / terminal.cols,
.cell_height = terminal.height_px / terminal.rows,
};
}

pub fn GhostelHandler(Effects: type) type {
return struct {
const Self = @This();
Expand Down Expand Up @@ -189,12 +198,7 @@ pub fn GhostelHandler(Effects: type) type {

/// Called for XTWINOPS size queries (CSI 14/16/18 t).
fn sizeCallback(handler: *gt.TerminalStream.Handler) ?gt.size_report.Size {
return .{
.rows = handler.terminal.rows,
.columns = handler.terminal.cols,
.cell_width = handler.terminal.width_px / handler.terminal.cols,
.cell_height = handler.terminal.height_px / handler.terminal.rows,
};
return reportedSize(handler.terminal);
}

/// Called when the terminal title changes. A cleared title (empty
Expand Down
35 changes: 35 additions & 0 deletions test/ghostel-terminal-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,41 @@ has been rendered."
(should (equal "\e[6;23;9t\e[4;575;720t\e[8;25;80t"
(apply #'concat (nreverse replies)))))))

(ert-deftest ghostel-test-in-band-size-report-on-resize ()
"A committed resize sends an in-band size report while mode 2048 is on.
Neovim enables the mode and then ignores SIGWINCH."
:tags '(native)
(let ((buf (generate-new-buffer " *ghostel-test-in-band-resize*")))
(unwind-protect
(with-current-buffer buf
(set-window-buffer (selected-window) buf)
(ghostel-mode)
(setq ghostel--term (ghostel--new 6 80 100))
(let ((ghostel--process 'fake-process)
(replies nil))
(cl-letf (((symbol-function 'process-send-string)
(lambda (_process string) (push string replies)))
((symbol-function 'set-process-window-size) #'ignore))
(ghostel--set-size ghostel--term 6 80 9 23)
(ghostel-test--redraw ghostel--term t)
(ghostel--write-vt ghostel--term "\e[?2048h")
(should (equal "\e[48;6;80;138;720t"
(apply #'concat (nreverse replies))))
(setq replies nil)
(ghostel--set-size ghostel--term 4 40 9 23)
(should-not replies)
(ghostel-test--redraw ghostel--term t)
(should (equal "\e[48;4;40;92;360t"
(apply #'concat (nreverse replies))))
(setq replies nil)
(ghostel-test--redraw ghostel--term t)
(should-not replies)
(ghostel--write-vt ghostel--term "\e[?2048l")
(ghostel--set-size ghostel--term 6 80 9 23)
(ghostel-test--redraw ghostel--term t)
(should-not replies))))
(kill-buffer buf))))

(defun ghostel-test--mouse-presses (modes cells &optional cell-size)
"Return the concatenated reports for left presses at CELLS.
CELLS is a list of (COL . ROW). MODES is written first to an 80x25
Expand Down
Loading