Files
ghostty/src/config/key.zig
Chris Marchesi e8525c0fd9 Update to Zig 0.16.0
This commit represents the majority of the work necessary to upgrade
Ghostty to use Zig 0.16.0.

Key parts:

* In addition to its previous responsibilities, the global state now
  houses state for global I/O implementations and the process
  environment. It is now also utilized in the main application along
  with the C library. Where necessary, global state is isolated from key
  parts of the implementation (e.g., in libghostty subsystems), and it's
  expected that this list will grow.

* We currently manage our own C translation layer where necessary. In
  these cases, cImport has been removed in favor of the new external
  translate-c package. Due to fixes that have needed be made to properly
  translate the dependencies that were swapped out, as mentioned, we
  have had to backport fixes from the current translate-c package (and
  the upstream Arocc dependency). We will host this ourselves until Zig
  0.17.0 is released with these fixes.

* Where necessary (only a small number of cases), some stdlib code from
  0.15.2 (and even from 0.17.0) has been taken, adopted, and vendored in
  lib/compat.

Co-authored-by: Leah Amelia Chen <hi@pluie.me>
2026-07-21 12:35:05 -07:00

55 lines
1.5 KiB
Zig

const std = @import("std");
const Config = @import("Config.zig");
/// Key is an enum of all the available configuration keys. This is used
/// when paired with diff to determine what fields have changed in a config,
/// amongst other things.
pub const Key = key: {
const field_infos = std.meta.fields(Config);
var names: [field_infos.len][]const u8 = undefined;
var raw_values: [field_infos.len]comptime_int = undefined;
var i: usize = 0;
for (field_infos, &names, &raw_values) |field, *name, *raw| {
// Ignore fields starting with "_" since they're internal and
// not copied ever.
if (field.name[0] == '_') continue;
name.* = field.name;
raw.* = i;
i += 1;
}
const TagInt = std.math.IntFittingRange(0, field_infos.len - 1);
var values: [i]TagInt = undefined;
for (raw_values[0..i], &values) |raw, *val| {
val.* = raw;
}
break :key @Enum(TagInt, .exhaustive, names[0..i], &values);
};
/// Returns the value type for a key
pub fn Value(comptime key: Key) type {
const field = comptime field: {
@setEvalBranchQuota(100_000);
const fields = std.meta.fields(Config);
for (fields) |field| {
if (@field(Key, field.name) == key) {
break :field field;
}
}
unreachable;
};
return field.type;
}
test "Value" {
const testing = std.testing;
try testing.expectEqual(Config.RepeatableString, Value(.@"font-family"));
try testing.expectEqual(?bool, Value(.@"cursor-style-blink"));
}