mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
Merge pull request #2658 from ghostty-org/push-sstnrxoppstv
termio: handle empty titles (OSC 0/2)
This commit is contained in:
@ -400,7 +400,7 @@ pub const Parser = struct {
|
|||||||
.@"0" => switch (c) {
|
.@"0" => switch (c) {
|
||||||
';' => {
|
';' => {
|
||||||
self.command = .{ .change_window_title = undefined };
|
self.command = .{ .change_window_title = undefined };
|
||||||
|
self.complete = true;
|
||||||
self.state = .string;
|
self.state = .string;
|
||||||
self.temp_state = .{ .str = &self.command.change_window_title };
|
self.temp_state = .{ .str = &self.command.change_window_title };
|
||||||
self.buf_start = self.buf_idx;
|
self.buf_start = self.buf_idx;
|
||||||
@ -477,7 +477,7 @@ pub const Parser = struct {
|
|||||||
'2' => self.state = .@"22",
|
'2' => self.state = .@"22",
|
||||||
';' => {
|
';' => {
|
||||||
self.command = .{ .change_window_title = undefined };
|
self.command = .{ .change_window_title = undefined };
|
||||||
|
self.complete = true;
|
||||||
self.state = .string;
|
self.state = .string;
|
||||||
self.temp_state = .{ .str = &self.command.change_window_title };
|
self.temp_state = .{ .str = &self.command.change_window_title };
|
||||||
self.buf_start = self.buf_idx;
|
self.buf_start = self.buf_idx;
|
||||||
@ -1159,6 +1159,17 @@ test "OSC: change_window_title with utf8" {
|
|||||||
try testing.expectEqualStrings("— ‐", cmd.change_window_title);
|
try testing.expectEqualStrings("— ‐", cmd.change_window_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "OSC: change_window_title empty" {
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
|
var p: Parser = .{};
|
||||||
|
p.next('2');
|
||||||
|
p.next(';');
|
||||||
|
const cmd = p.end(null).?;
|
||||||
|
try testing.expect(cmd == .change_window_title);
|
||||||
|
try testing.expectEqualStrings("", cmd.change_window_title);
|
||||||
|
}
|
||||||
|
|
||||||
test "OSC: change_window_icon" {
|
test "OSC: change_window_icon" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
|
|
||||||
|
@ -965,7 +965,23 @@ pub const StreamHandler = struct {
|
|||||||
@memcpy(buf[0..title.len], title);
|
@memcpy(buf[0..title.len], title);
|
||||||
buf[title.len] = 0;
|
buf[title.len] = 0;
|
||||||
|
|
||||||
// Mark that we've seen a title
|
// Special handling for the empty title. We treat the empty title
|
||||||
|
// as resetting to as if we never saw a title. Other terminals
|
||||||
|
// behave this way too (e.g. iTerm2).
|
||||||
|
if (title.len == 0) {
|
||||||
|
// If we have a pwd then we set the title as the pwd else
|
||||||
|
// we just set it to blank.
|
||||||
|
if (self.terminal.getPwd()) |pwd| pwd: {
|
||||||
|
if (pwd.len >= buf.len) break :pwd;
|
||||||
|
@memcpy(buf[0..pwd.len], pwd);
|
||||||
|
buf[pwd.len] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.surfaceMessageWriter(.{ .set_title = buf });
|
||||||
|
self.seen_title = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.seen_title = true;
|
self.seen_title = true;
|
||||||
self.surfaceMessageWriter(.{ .set_title = buf });
|
self.surfaceMessageWriter(.{ .set_title = buf });
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user