diff --git a/src/terminal/osc.zig b/src/terminal/osc.zig index 8db4f3025..7e93b48d7 100644 --- a/src/terminal/osc.zig +++ b/src/terminal/osc.zig @@ -400,7 +400,7 @@ pub const Parser = struct { .@"0" => switch (c) { ';' => { self.command = .{ .change_window_title = undefined }; - + self.complete = true; self.state = .string; self.temp_state = .{ .str = &self.command.change_window_title }; self.buf_start = self.buf_idx; @@ -477,7 +477,7 @@ pub const Parser = struct { '2' => self.state = .@"22", ';' => { self.command = .{ .change_window_title = undefined }; - + self.complete = true; self.state = .string; self.temp_state = .{ .str = &self.command.change_window_title }; self.buf_start = self.buf_idx; @@ -1159,6 +1159,17 @@ test "OSC: change_window_title with utf8" { 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" { const testing = std.testing; diff --git a/src/termio/stream_handler.zig b/src/termio/stream_handler.zig index ab837cfd4..fa887932a 100644 --- a/src/termio/stream_handler.zig +++ b/src/termio/stream_handler.zig @@ -965,7 +965,23 @@ pub const StreamHandler = struct { @memcpy(buf[0..title.len], title); 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.surfaceMessageWriter(.{ .set_title = buf }); }