diff --git a/include/ghostty/vt.h b/include/ghostty/vt.h index fc5eb1812..5d80cb653 100644 --- a/include/ghostty/vt.h +++ b/include/ghostty/vt.h @@ -81,19 +81,6 @@ typedef enum { GHOSTTY_OSC_COMMAND_CONEMU_GUIMACRO = 20, } GhosttyOscCommandType; -/** - * OSC command data types. The values returned are documented - * on each type. - * */ -typedef enum { - /** - * The window title string. - * - * Type: const char* - * */ - GHOSTTY_OSC_DATA_WINDOW_TITLE, -} GhosttyOscCommandData; - //------------------------------------------------------------------- // Allocator Interface @@ -317,9 +304,17 @@ void ghostty_osc_next(GhosttyOscParser parser, uint8_t byte); */ 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); +/** + * Get the type of an OSC command. + * + * Returns the type identifier for the given OSC command. This can be used + * to determine what kind of command was parsed and what data might be + * available from it. + * + * @param command The OSC command handle to query (may be NULL) + * @return The command type, or GHOSTTY_OSC_COMMAND_INVALID if command is NULL + */ +GhosttyOscCommandType ghostty_osc_command_type(GhosttyOscCommand command); #ifdef __cplusplus } diff --git a/src/lib_vt.zig b/src/lib_vt.zig index 4de7e390e..37ab7ae68 100644 --- a/src/lib_vt.zig +++ b/src/lib_vt.zig @@ -75,6 +75,7 @@ comptime { @export(&c.osc_next, .{ .name = "ghostty_osc_next" }); @export(&c.osc_reset, .{ .name = "ghostty_osc_reset" }); @export(&c.osc_end, .{ .name = "ghostty_osc_end" }); + @export(&c.osc_command_type, .{ .name = "ghostty_osc_command_type" }); } } diff --git a/src/terminal/c/main.zig b/src/terminal/c/main.zig index 2779beebd..f32dd226f 100644 --- a/src/terminal/c/main.zig +++ b/src/terminal/c/main.zig @@ -6,6 +6,7 @@ pub const osc_free = osc.free; pub const osc_reset = osc.reset; pub const osc_next = osc.next; pub const osc_end = osc.end; +pub const osc_command_type = osc.commandType; test { _ = osc; diff --git a/src/terminal/c/osc.zig b/src/terminal/c/osc.zig index 3859b3cc3..c04626b69 100644 --- a/src/terminal/c/osc.zig +++ b/src/terminal/c/osc.zig @@ -44,7 +44,12 @@ pub fn end(parser_: Parser, terminator: u8) callconv(.c) Command { return parser_.?.end(terminator); } -test "osc" { +pub fn commandType(command_: Command) callconv(.c) osc.Command.Key { + const command = command_ orelse return .invalid; + return command.*; +} + +test "alloc" { const testing = std.testing; var p: Parser = undefined; try testing.expectEqual(Result.success, new( @@ -53,3 +58,24 @@ test "osc" { )); free(p); } + +test "command type null" { + const testing = std.testing; + try testing.expectEqual(.invalid, commandType(null)); +} + +test "command type" { + const testing = std.testing; + var p: Parser = undefined; + try testing.expectEqual(Result.success, new( + &lib_alloc.test_allocator, + &p, + )); + defer free(p); + + p.next('0'); + p.next(';'); + p.next('a'); + const cmd = p.end(0); + try testing.expectEqual(.change_window_title, commandType(cmd)); +} diff --git a/src/terminal/main.zig b/src/terminal/main.zig index 70b5742cd..7403ff309 100644 --- a/src/terminal/main.zig +++ b/src/terminal/main.zig @@ -64,7 +64,7 @@ pub const isSafePaste = sanitize.isSafePaste; /// This is set to true when we're building the C library. pub const is_c_lib = @import("build_options.zig").is_c_lib; -pub const c_api = @import("c/main.zig"); +pub const c_api = if (is_c_lib) @import("c/main.zig") else void; test { @import("std").testing.refAllDecls(@This());