diff --git a/src/terminal/Parser.zig b/src/terminal/Parser.zig index 032fa42d9..9773da63f 100644 --- a/src/terminal/Parser.zig +++ b/src/terminal/Parser.zig @@ -567,6 +567,31 @@ test "osc: change window title" { const cmd = a[0].?.osc_dispatch; try testing.expect(cmd == .change_window_title); + try testing.expectEqualStrings("abc", cmd.change_window_title); + } +} + +test "osc: change window title (end in esc)" { + var p = init(); + _ = p.next(0x1B); + _ = p.next(']'); + _ = p.next('0'); + _ = p.next(';'); + _ = p.next('a'); + _ = p.next('b'); + _ = p.next('c'); + + { + const a = p.next(0x1B); + _ = p.next('\\'); + try testing.expect(p.state == .ground); + try testing.expect(a[0].? == .osc_dispatch); + try testing.expect(a[1] == null); + try testing.expect(a[2] == null); + + const cmd = a[0].?.osc_dispatch; + try testing.expect(cmd == .change_window_title); + try testing.expectEqualStrings("abc", cmd.change_window_title); } } diff --git a/src/terminal/osc.zig b/src/terminal/osc.zig index 7f02d1631..494938d58 100644 --- a/src/terminal/osc.zig +++ b/src/terminal/osc.zig @@ -326,11 +326,7 @@ pub const Parser = struct { else => self.state = .invalid, }, - .string => { - // Complete once we receive one character since we have - // at least SOME value for the expected string value. - self.complete = true; - }, + .string => self.complete = true, } } @@ -352,6 +348,10 @@ pub const Parser = struct { } } + fn endString(self: *Parser) void { + self.temp_state.str.* = self.buf[self.buf_start..self.buf_idx]; + } + /// End the sequence and return the command, if any. If the return value /// is null, then no valid command was found. pub fn end(self: *Parser) ?Command { @@ -364,7 +364,7 @@ pub const Parser = struct { switch (self.state) { .semantic_exit_code => self.endSemanticExitCode(), .semantic_option_value => self.endSemanticOptionValue(), - .string => self.temp_state.str.* = self.buf[self.buf_start..self.buf_idx], + .string => self.endString(), else => {}, }