From 7968358234ed74c4c3e1f02ebe70eb37159d7b46 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 23 Jan 2026 13:23:30 -0800 Subject: [PATCH] terminal/osc: semantic prompt options --- src/terminal/osc/parsers/semantic_prompt2.zig | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/terminal/osc/parsers/semantic_prompt2.zig b/src/terminal/osc/parsers/semantic_prompt2.zig index 62833f31a..e3cdb815f 100644 --- a/src/terminal/osc/parsers/semantic_prompt2.zig +++ b/src/terminal/osc/parsers/semantic_prompt2.zig @@ -13,11 +13,16 @@ pub const Command = union(enum) { pub const Options = struct { aid: ?[:0]const u8, cl: ?Click, - // TODO: more + prompt_kind: ?PromptKind, + exit_code: ?i32, + err: ?[:0]const u8, pub const init: Options = .{ .aid = null, .cl = null, + .prompt_kind = null, + .exit_code = null, + .err = null, }; pub fn parse(self: *Options, it: *KVIterator) void { @@ -28,6 +33,15 @@ pub const Options = struct { } else if (std.mem.eql(u8, key, "cl")) cl: { const value = kv.value orelse break :cl; self.cl = std.meta.stringToEnum(Click, value); + } else if (std.mem.eql(u8, key, "k")) k: { + const value = kv.value orelse break :k; + if (value.len != 1) break :k; + self.prompt_kind = .init(value[0]); + } else if (std.mem.eql(u8, key, "err")) { + self.err = kv.value; + } else if (key.len == 0) exit_code: { + const value = kv.value orelse break :exit_code; + self.exit_code = std.fmt.parseInt(i32, value, 10) catch break :exit_code; } else { log.info("OSC 133: unknown semantic prompt option: {s}", .{key}); } @@ -42,6 +56,23 @@ pub const Click = enum { smart_vertical, }; +pub const PromptKind = enum { + initial, + right, + continuation, + secondary, + + pub fn init(c: u8) ?PromptKind { + return switch (c) { + 'i' => .initial, + 'r' => .right, + 'c' => .continuation, + 's' => .secondary, + else => null, + }; + } +}; + /// Parse OSC 133, semantic prompts pub fn parse(parser: *Parser, _: ?u8) ?*OSCCommand { const writer = parser.writer orelse {