From 0d9216bb5a06ff33e5aadbeea27bd3c63567f732 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 23 Jan 2026 13:37:34 -0800 Subject: [PATCH] terminal/osc: semantic prompt 'N' --- src/terminal/osc/parsers/semantic_prompt2.zig | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/terminal/osc/parsers/semantic_prompt2.zig b/src/terminal/osc/parsers/semantic_prompt2.zig index b46157692..890fe714b 100644 --- a/src/terminal/osc/parsers/semantic_prompt2.zig +++ b/src/terminal/osc/parsers/semantic_prompt2.zig @@ -8,6 +8,7 @@ const log = std.log.scoped(.osc_semantic_prompt); pub const Command = union(enum) { fresh_line, fresh_line_new_prompt: Options, + new_command: Options, prompt_start: Options, }; @@ -104,6 +105,14 @@ pub fn parse(parser: *Parser, _: ?u8) ?*OSCCommand { parser.command = .{ .semantic_prompt = .fresh_line }; }, + 'N' => new_command: { + parser.command = .{ .semantic_prompt = .{ .new_command = .init } }; + if (data.len == 1) break :new_command; + if (data[1] != ';') break :valid; + var it = KVIterator.init(writer) catch break :valid; + parser.command.semantic_prompt.new_command.parse(&it); + }, + 'P' => prompt_start: { parser.command = .{ .semantic_prompt = .{ .prompt_start = .init } }; if (data.len == 1) break :prompt_start; @@ -450,3 +459,70 @@ test "OSC 133: prompt_start extra contents" { for (input) |ch| p.next(ch); try testing.expect(p.end(null) == null); } + +test "OSC 133: new_command" { + const testing = std.testing; + + var p: Parser = .init(null); + + const input = "133;N"; + for (input) |ch| p.next(ch); + + const cmd = p.end(null).?.*; + try testing.expect(cmd == .semantic_prompt); + try testing.expect(cmd.semantic_prompt == .new_command); + try testing.expect(cmd.semantic_prompt.new_command.aid == null); + try testing.expect(cmd.semantic_prompt.new_command.cl == null); +} + +test "OSC 133: new_command with aid" { + const testing = std.testing; + + var p: Parser = .init(null); + + const input = "133;N;aid=foo"; + for (input) |ch| p.next(ch); + + const cmd = p.end(null).?.*; + try testing.expect(cmd == .semantic_prompt); + try testing.expect(cmd.semantic_prompt == .new_command); + try testing.expectEqualStrings("foo", cmd.semantic_prompt.new_command.aid.?); +} + +test "OSC 133: new_command with cl=line" { + const testing = std.testing; + + var p: Parser = .init(null); + + const input = "133;N;cl=line"; + for (input) |ch| p.next(ch); + + const cmd = p.end(null).?.*; + try testing.expect(cmd == .semantic_prompt); + try testing.expect(cmd.semantic_prompt == .new_command); + try testing.expect(cmd.semantic_prompt.new_command.cl == .line); +} + +test "OSC 133: new_command with multiple options" { + const testing = std.testing; + + var p: Parser = .init(null); + + const input = "133;N;aid=foo;cl=line"; + for (input) |ch| p.next(ch); + + const cmd = p.end(null).?.*; + try testing.expect(cmd == .semantic_prompt); + try testing.expect(cmd.semantic_prompt == .new_command); + try testing.expectEqualStrings("foo", cmd.semantic_prompt.new_command.aid.?); + try testing.expect(cmd.semantic_prompt.new_command.cl == .line); +} + +test "OSC 133: new_command extra contents" { + const testing = std.testing; + + var p: Parser = .init(null); + const input = "133;Nextra"; + for (input) |ch| p.next(ch); + try testing.expect(p.end(null) == null); +}