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
20 changes: 20 additions & 0 deletions src/terminal/modes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ pub const ModeState = struct {
/// Return a DECRPM report for the given mode tag. If the tag does
/// not correspond to a known mode, the report state is .not_recognized.
pub fn getReport(self: *const ModeState, tag: ModeTag) Report {
// DECECM (Erase Color Mode, DEC private mode 117) controls whether erasing
// and scrolling use the default background or the active background color.
// Ghostty's behavior is fixed equivalent to DECECM reset, and DECRQM has a
// "permanently reset" response for recognized modes that cannot be changed.
// Report that instead of "not recognized" so applications can query and adapt
// to Ghostty's erase-color behavior.
//
// See VT520/VT525 Programmer Information, "Erase Color" and DECRQM/DECRPM:
// https://web.mit.edu/dosathena/doc/www/ek-vt520-rm.pdf

if (!tag.ansi and tag.value == 117) {
return .{ .tag = tag, .state = .permanently_reset };
}
const mode = modeFromInt(tag.value, tag.ansi) orelse return .{
.tag = tag,
.state = .not_recognized,
Expand Down Expand Up @@ -347,6 +360,13 @@ test "getReport known ANSI mode" {
try testing.expectEqual(true, report.tag.ansi);
}

test "getReport DECECM permanently reset" {
const state: ModeState = .{};
const report = state.getReport(.{ .value = 117, .ansi = false });
try testing.expectEqual(Report.State.permanently_reset, report.state);
try testing.expectEqual(false, report.tag.ansi);
}

test "getReport unknown mode" {
const state: ModeState = .{};
const report = state.getReport(.{ .value = 9999 });
Expand Down
4 changes: 4 additions & 0 deletions src/terminal/stream_terminal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,10 @@ test "request mode DECRQM with write_pty callback" {
// Query an unknown mode
s.nextSlice("\x1B[?9999$p");
try testing.expectEqualStrings("\x1B[?9999;0$y", S.last_response.?);

// Query DECECM, which Ghostty recognizes but does not allow changing
s.nextSlice("\x1B[?117$p");
try testing.expectEqualStrings("\x1B[?117;4$y", S.last_response.?);
}
}

Expand Down
Loading