lib_vt: osc_next/reset

pull/8941/head
Mitchell Hashimoto 2025-09-27 13:22:56 -07:00
parent 8a1dc5bd97
commit b3d1802c89
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
5 changed files with 39 additions and 1 deletions

View File

@ -214,6 +214,32 @@ GhosttyResult ghostty_osc_new(const GhosttyAllocator *allocator, GhosttyOscParse
*/
void ghostty_osc_free(GhosttyOscParser parser);
/**
* Reset an OSC parser instance to its initial state.
*
* Resets the parser state, clearing any partially parsed OSC sequences
* and returning the parser to its initial state. This is useful for
* reusing a parser instance or recovering from parse errors.
*
* @param parser The parser handle to reset, must not be null.
*/
void ghostty_osc_reset(GhosttyOscParser parser);
/**
* Parse the next byte in an OSC sequence.
*
* Processes a single byte as part of an OSC sequence. The parser maintains
* internal state to track the progress through the sequence. Call this
* function for each byte in the sequence data.
*
* When finished pumping the parser with bytes, call ghostty_osc_end
* to get the final result.
*
* @param parser The parser handle, must not be null.
* @param byte The next byte to parse
*/
void ghostty_osc_next(GhosttyOscParser parser, uint8_t byte);
#ifdef __cplusplus
}
#endif

View File

@ -72,6 +72,8 @@ comptime {
const c = terminal.c_api;
@export(&c.osc_new, .{ .name = "ghostty_osc_new" });
@export(&c.osc_free, .{ .name = "ghostty_osc_free" });
@export(&c.osc_next, .{ .name = "ghostty_osc_next" });
@export(&c.osc_reset, .{ .name = "ghostty_osc_reset" });
}
}

View File

@ -3,6 +3,8 @@ pub const osc = @import("osc.zig");
// The full C API, unexported.
pub const osc_new = osc.new;
pub const osc_free = osc.free;
pub const osc_reset = osc.reset;
pub const osc_next = osc.next;
test {
_ = osc;

View File

@ -29,6 +29,14 @@ pub fn free(parser_: Parser) callconv(.c) void {
alloc.destroy(parser);
}
pub fn reset(parser_: Parser) callconv(.c) void {
parser_.?.reset();
}
pub fn next(parser_: Parser, byte: u8) callconv(.c) void {
parser_.?.next(byte);
}
test "osc" {
const testing = std.testing;
var p: Parser = undefined;

View File

@ -431,7 +431,7 @@ pub const Parser = struct {
self.reset();
}
/// Reset the parser start.
/// Reset the parser state.
pub fn reset(self: *Parser) void {
// If the state is already empty then we do nothing because
// we may touch uninitialized memory.