terminal: use LibEnum for the command keys

This commit is contained in:
Mitchell Hashimoto
2025-09-27 14:32:45 -07:00
parent a79e68ace1
commit 397e47c274
4 changed files with 38 additions and 3 deletions

View File

@@ -35,7 +35,8 @@ pub fn Enum(
fields_i += 1; fields_i += 1;
} }
return @Type(.{ .@"enum" = .{ // Assigned to var so that the type name is nicer in stack traces.
const Result = @Type(.{ .@"enum" = .{
.tag_type = switch (target) { .tag_type = switch (target) {
.c => c_int, .c => c_int,
.zig => std.math.IntFittingRange(0, fields_i - 1), .zig => std.math.IntFittingRange(0, fields_i - 1),
@@ -44,6 +45,7 @@ pub fn Enum(
.decls = &.{}, .decls = &.{},
.is_exhaustive = true, .is_exhaustive = true,
} }); } });
return Result;
} }
pub const Target = union(enum) { pub const Target = union(enum) {

View File

@@ -1,5 +1,8 @@
const std = @import("std"); const std = @import("std");
/// True if we're building the C library libghostty-vt.
pub const is_c_lib = @import("root") == @import("../lib_vt.zig");
pub const Options = struct { pub const Options = struct {
/// The target artifact to build. This will gate some functionality. /// The target artifact to build. This will gate some functionality.
artifact: Artifact, artifact: Artifact,

View File

@@ -63,7 +63,7 @@ pub const Attribute = sgr.Attribute;
pub const isSafePaste = sanitize.isSafePaste; pub const isSafePaste = sanitize.isSafePaste;
/// This is set to true when we're building the C library. /// This is set to true when we're building the C library.
pub const is_c_lib = @import("root") == @import("../lib_vt.zig"); pub const is_c_lib = @import("build_options.zig").is_c_lib;
pub const c_api = @import("c/main.zig"); pub const c_api = @import("c/main.zig");
test { test {

View File

@@ -10,6 +10,8 @@ const builtin = @import("builtin");
const mem = std.mem; const mem = std.mem;
const assert = std.debug.assert; const assert = std.debug.assert;
const Allocator = mem.Allocator; const Allocator = mem.Allocator;
const LibEnum = @import("../lib/enum.zig").Enum;
const is_c_lib = @import("build_options.zig").is_c_lib;
const RGB = @import("color.zig").RGB; const RGB = @import("color.zig").RGB;
const kitty_color = @import("kitty/color.zig"); const kitty_color = @import("kitty/color.zig");
const osc_color = @import("osc/color.zig"); const osc_color = @import("osc/color.zig");
@@ -17,7 +19,7 @@ pub const color = osc_color;
const log = std.log.scoped(.osc); const log = std.log.scoped(.osc);
pub const Command = union(enum) { pub const Command = union(Key) {
/// This generally shouldn't ever be set except as an initial zero value. /// This generally shouldn't ever be set except as an initial zero value.
/// Ignore it. /// Ignore it.
invalid, invalid,
@@ -172,6 +174,34 @@ pub const Command = union(enum) {
/// ConEmu GUI macro (OSC 9;6) /// ConEmu GUI macro (OSC 9;6)
conemu_guimacro: []const u8, conemu_guimacro: []const u8,
pub const Key = LibEnum(
if (is_c_lib) .c else .zig,
// NOTE: Order matters, see LibEnum documentation.
&.{
"invalid",
"change_window_title",
"change_window_icon",
"prompt_start",
"prompt_end",
"end_of_input",
"end_of_command",
"clipboard_contents",
"report_pwd",
"mouse_shape",
"color_operation",
"kitty_color_protocol",
"show_desktop_notification",
"hyperlink_start",
"hyperlink_end",
"conemu_sleep",
"conemu_show_message_box",
"conemu_change_tab_title",
"conemu_progress_report",
"conemu_wait_input",
"conemu_guimacro",
},
);
pub const ProgressReport = struct { pub const ProgressReport = struct {
pub const State = enum(c_int) { pub const State = enum(c_int) {
remove, remove,