terminal: share progress state enum

This commit is contained in:
Jack Pearkes
2026-07-27 11:20:39 -04:00
parent 47d602c422
commit 628adaf30f
3 changed files with 19 additions and 21 deletions

View File

@@ -121,7 +121,10 @@ pub fn checkGhosttyHEnum(
if (@hasDecl(c, expected_name)) {
std.testing.expectEqual(field.value, @field(c, expected_name)) catch |e| {
std.log.err(@typeName(T) ++ " key " ++ field.name ++ " does not have the same backing int as " ++ expected_name, .{});
std.log.err(
"{s} key {s} does not have the same backing int as " ++ expected_name,
.{ @typeName(T), field.name },
);
return e;
};

View File

@@ -92,16 +92,8 @@ pub const DesktopNotification = extern struct {
body: lib.String,
};
/// State of a terminal progress report.
///
/// C: GhosttyTerminalProgressState
pub const ProgressState = enum(c_int) {
remove = 0,
set = 1,
@"error" = 2,
indeterminate = 3,
pause = 4,
};
pub const ProgressState = osc.Command.ProgressReport.State;
/// A progress report emitted by the running program.
///

View File

@@ -203,19 +203,16 @@ pub const Command = union(Key) {
);
pub const ProgressReport = struct {
pub const State = enum(c_int) {
remove,
set,
@"error",
indeterminate,
pause,
test "ghostty.h Command.ProgressReport.State" {
if (comptime build_options.artifact == .lib) return error.SkipZigTest;
try lib.checkGhosttyHEnum(State, "GHOSTTY_PROGRESS_STATE_");
}
const state_keys = &.{
"remove",
"set",
"error",
"indeterminate",
"pause",
};
pub const State = LibEnum(lib.target, state_keys);
state: State,
progress: ?u8 = null,
@@ -235,6 +232,12 @@ pub const Command = union(Key) {
)) else -1,
};
}
test "ghostty.h Command.ProgressReport.State" {
if (comptime build_options.artifact == .lib) return error.SkipZigTest;
const CState = LibEnum(.c, state_keys);
try lib.checkGhosttyHEnum(CState, "GHOSTTY_PROGRESS_STATE_");
}
};
comptime {