diff --git a/include/ghostty/vt.h b/include/ghostty/vt.h index c784dcb0e..fc5eb1812 100644 --- a/include/ghostty/vt.h +++ b/include/ghostty/vt.h @@ -289,9 +289,37 @@ void ghostty_osc_reset(GhosttyOscParser parser); */ void ghostty_osc_next(GhosttyOscParser parser, uint8_t byte); -GhosttyOscCommand ghostty_osc_end(GhosttyOscParser parser); -GhosttyOscCommandType ghostty_osc_command_type(GhosttyOscCommand command); -bool ghostty_osc_command_data(GhosttyOscCommand command, GhosttyOscCommandData, void *result); +/** + * Finalize OSC parsing and retrieve the parsed command. + * + * Call this function after feeding all bytes of an OSC sequence to the parser + * using ghostty_osc_next() with the exception of the terminating character + * (ESC or ST). This function finalizes the parsing process and returns the + * parsed OSC command. + * + * The return value is never NULL. Invalid commands will return a command + * with type GHOSTTY_OSC_COMMAND_INVALID. + * + * The terminator parameter specifies the byte that terminated the OSC sequence + * (typically 0x07 for BEL or 0x5C for ST after ESC). This information is + * preserved in the parsed command so that responses can use the same terminator + * format for better compatibility with the calling program. For commands that + * do not require a response, this parameter is ignored and the resulting + * command will not retain the terminator information. + * + * The returned command handle is valid until the next call to any + * `ghostty_osc_*` function with the same parser instance with the exception + * of command introspection functions such as `ghostty_osc_command_type`. + * + * @param parser The parser handle, must not be null. + * @param terminator The terminating byte of the OSC sequence (0x07 for BEL, 0x5C for ST) + * @return Handle to the parsed OSC command + */ +GhosttyOscCommand ghostty_osc_end(GhosttyOscParser parser, uint8_t terminator); + +// TODO +// GhosttyOscCommandType ghostty_osc_command_type(GhosttyOscCommand command); +// bool ghostty_osc_command_data(GhosttyOscCommand command, GhosttyOscCommandData, void *result); #ifdef __cplusplus } diff --git a/src/lib_vt.zig b/src/lib_vt.zig index 6d9c042d8..4de7e390e 100644 --- a/src/lib_vt.zig +++ b/src/lib_vt.zig @@ -74,6 +74,7 @@ comptime { @export(&c.osc_free, .{ .name = "ghostty_osc_free" }); @export(&c.osc_next, .{ .name = "ghostty_osc_next" }); @export(&c.osc_reset, .{ .name = "ghostty_osc_reset" }); + @export(&c.osc_end, .{ .name = "ghostty_osc_end" }); } } diff --git a/src/terminal/c/main.zig b/src/terminal/c/main.zig index 1a25685ba..2779beebd 100644 --- a/src/terminal/c/main.zig +++ b/src/terminal/c/main.zig @@ -5,6 +5,7 @@ pub const osc_new = osc.new; pub const osc_free = osc.free; pub const osc_reset = osc.reset; pub const osc_next = osc.next; +pub const osc_end = osc.end; test { _ = osc; diff --git a/src/terminal/c/osc.zig b/src/terminal/c/osc.zig index 59761cfba..3859b3cc3 100644 --- a/src/terminal/c/osc.zig +++ b/src/terminal/c/osc.zig @@ -9,6 +9,9 @@ const Result = @import("result.zig").Result; /// C: GhosttyOscParser pub const Parser = ?*osc.Parser; +/// C: GhosttyOscCommand +pub const Command = ?*osc.Command; + pub fn new( alloc_: ?*const CAllocator, result: *Parser, @@ -37,6 +40,10 @@ pub fn next(parser_: Parser, byte: u8) callconv(.c) void { parser_.?.next(byte); } +pub fn end(parser_: Parser, terminator: u8) callconv(.c) Command { + return parser_.?.end(terminator); +} + test "osc" { const testing = std.testing; var p: Parser = undefined;