Lots of 0.14 changes

This commit is contained in:
Mitchell Hashimoto
2025-03-12 09:55:46 -07:00
parent 86d3f18707
commit 0f4d2bb237
67 changed files with 326 additions and 316 deletions

View File

@@ -510,7 +510,7 @@ pub const Action = union(enum) {
///
crash: CrashThread,
pub const Key = @typeInfo(Action).Union.tag_type.?;
pub const Key = @typeInfo(Action).@"union".tag_type.?;
pub const CrashThread = enum {
main,
@@ -638,17 +638,22 @@ pub const Action = union(enum) {
const field_info = @typeInfo(field.type);
// Fields can provide a custom "parse" function
if (field_info == .Struct or field_info == .Union or field_info == .Enum) {
if (@hasDecl(field.type, "parse") and @typeInfo(@TypeOf(field.type.parse)) == .Fn) {
if (field_info == .@"struct" or
field_info == .@"union" or
field_info == .@"enum")
{
if (@hasDecl(field.type, "parse") and
@typeInfo(@TypeOf(field.type.parse)) == .@"fn")
{
return field.type.parse(param);
}
}
return switch (field_info) {
.Enum => try parseEnum(field.type, param),
.Int => try parseInt(field.type, param),
.Float => try parseFloat(field.type, param),
.Struct => |info| blk: {
.@"enum" => try parseEnum(field.type, param),
.int => try parseInt(field.type, param),
.float => try parseFloat(field.type, param),
.@"struct" => |info| blk: {
// Only tuples are supported to avoid ambiguity with field
// ordering
comptime assert(info.is_tuple);
@@ -658,9 +663,9 @@ pub const Action = union(enum) {
inline for (info.fields) |field_| {
const next = it.next() orelse return Error.InvalidFormat;
@field(value, field_.name) = switch (@typeInfo(field_.type)) {
.Enum => try parseEnum(field_.type, next),
.Int => try parseInt(field_.type, next),
.Float => try parseFloat(field_.type, next),
.@"enum" => try parseEnum(field_.type, next),
.int => try parseInt(field_.type, next),
.float => try parseFloat(field_.type, next),
else => unreachable,
};
}
@@ -688,7 +693,7 @@ pub const Action = union(enum) {
// An action name is always required
if (action.len == 0) return Error.InvalidFormat;
const actionInfo = @typeInfo(Action).Union;
const actionInfo = @typeInfo(Action).@"union";
inline for (actionInfo.fields) |field| {
if (std.mem.eql(u8, action, field.name)) {
// If the field type is void we expect no value
@@ -813,7 +818,9 @@ pub const Action = union(enum) {
/// Returns a union type that only contains actions that are scoped to
/// the given scope.
pub fn Scoped(comptime s: Scope) type {
const all_fields = @typeInfo(Action).Union.fields;
@setEvalBranchQuota(100_000);
const all_fields = @typeInfo(Action).@"union".fields;
// Find all fields that are app-scoped
var i: usize = 0;
@@ -829,9 +836,9 @@ pub const Action = union(enum) {
}
// Build our union
return @Type(.{ .Union = .{
return @Type(.{ .@"union" = .{
.layout = .auto,
.tag_type = @Type(.{ .Enum = .{
.tag_type = @Type(.{ .@"enum" = .{
.tag_type = std.math.IntFittingRange(0, i),
.fields = enum_fields[0..i],
.decls = &.{},
@@ -903,10 +910,10 @@ pub const Action = union(enum) {
void => {},
[]const u8 => try writer.print("{s}", .{value}),
else => switch (value_info) {
.Enum => try writer.print("{s}", .{@tagName(value)}),
.Float => try writer.print("{d}", .{value}),
.Int => try writer.print("{d}", .{value}),
.Struct => |info| if (!info.is_tuple) {
.@"enum" => try writer.print("{s}", .{@tagName(value)}),
.float => try writer.print("{d}", .{value}),
.int => try writer.print("{d}", .{value}),
.@"struct" => |info| if (!info.is_tuple) {
try writer.print("{} (not configurable)", .{value});
} else {
inline for (info.fields, 0..) |field, i| {
@@ -937,21 +944,21 @@ pub const Action = union(enum) {
value: anytype,
) Allocator.Error!@TypeOf(value) {
return switch (@typeInfo(@TypeOf(value))) {
.Void,
.Int,
.Float,
.Enum,
.void,
.int,
.float,
.@"enum",
=> value,
.Pointer => |info| slice: {
comptime assert(info.size == .Slice);
.pointer => |info| slice: {
comptime assert(info.size == .slice);
break :slice try alloc.dupe(
info.child,
value,
);
},
.Struct => |info| if (info.is_tuple)
.@"struct" => |info| if (info.is_tuple)
value
else
try value.clone(alloc),
@@ -974,7 +981,7 @@ pub const Action = union(enum) {
/// Hash the action into the given hasher.
fn hashIncremental(self: Action, hasher: anytype) void {
// Always has the active tag.
const Tag = @typeInfo(Action).Union.tag_type.?;
const Tag = @typeInfo(Action).@"union".tag_type.?;
std.hash.autoHash(hasher, @as(Tag, self));
// Hash the value of the field.
@@ -1081,7 +1088,7 @@ pub const Trigger = struct {
if (part.len == 0) return Error.InvalidFormat;
// Check if its a modifier
const modsInfo = @typeInfo(key.Mods).Struct;
const modsInfo = @typeInfo(key.Mods).@"struct";
inline for (modsInfo.fields) |field| {
if (field.type == bool) {
if (std.mem.eql(u8, part, field.name)) {
@@ -1116,7 +1123,7 @@ pub const Trigger = struct {
const key_part = if (physical) part[physical_prefix.len..] else part;
// Check if its a key
const keysInfo = @typeInfo(key.Key).Enum;
const keysInfo = @typeInfo(key.Key).@"enum";
inline for (keysInfo.fields) |field| {
if (!std.mem.eql(u8, field.name, "invalid")) {
if (std.mem.eql(u8, key_part, field.name)) {

View File

@@ -1531,7 +1531,7 @@ test "kitty: left shift with report all" {
}
test "kitty: report associated with alt text on macOS with option" {
if (comptime !builtin.target.isDarwin()) return error.SkipZigTest;
if (comptime !builtin.target.os.tag.isDarwin()) return error.SkipZigTest;
var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{
@@ -1555,7 +1555,7 @@ test "kitty: report associated with alt text on macOS with option" {
}
test "kitty: report associated with alt text on macOS with alt" {
if (comptime !builtin.target.isDarwin()) return error.SkipZigTest;
if (comptime !builtin.target.os.tag.isDarwin()) return error.SkipZigTest;
{
// With Alt modifier
@@ -1826,7 +1826,7 @@ test "legacy: alt+e only unshifted" {
}
test "legacy: alt+x macos" {
if (comptime !builtin.target.isDarwin()) return error.SkipZigTest;
if (comptime !builtin.target.os.tag.isDarwin()) return error.SkipZigTest;
var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{
@@ -1845,7 +1845,7 @@ test "legacy: alt+x macos" {
}
test "legacy: shift+alt+. macos" {
if (comptime !builtin.target.isDarwin()) return error.SkipZigTest;
if (comptime !builtin.target.os.tag.isDarwin()) return error.SkipZigTest;
var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{

View File

@@ -81,24 +81,24 @@ pub const keys = keys: {
result.set(.left, pcStyle("\x1b[1;{}D") ++ cursorKey("\x1b[D", "\x1bOD"));
result.set(.home, pcStyle("\x1b[1;{}H") ++ cursorKey("\x1b[H", "\x1bOH"));
result.set(.end, pcStyle("\x1b[1;{}F") ++ cursorKey("\x1b[F", "\x1bOF"));
result.set(.insert, pcStyle("\x1b[2;{}~") ++ .{.{ .sequence = "\x1B[2~" }});
result.set(.delete, pcStyle("\x1b[3;{}~") ++ .{.{ .sequence = "\x1B[3~" }});
result.set(.page_up, pcStyle("\x1b[5;{}~") ++ .{.{ .sequence = "\x1B[5~" }});
result.set(.page_down, pcStyle("\x1b[6;{}~") ++ .{.{ .sequence = "\x1B[6~" }});
result.set(.insert, pcStyle("\x1b[2;{}~") ++ .{Entry{ .sequence = "\x1B[2~" }});
result.set(.delete, pcStyle("\x1b[3;{}~") ++ .{Entry{ .sequence = "\x1B[3~" }});
result.set(.page_up, pcStyle("\x1b[5;{}~") ++ .{Entry{ .sequence = "\x1B[5~" }});
result.set(.page_down, pcStyle("\x1b[6;{}~") ++ .{Entry{ .sequence = "\x1B[6~" }});
// Function Keys. todo: f13-f35 but we need to add to input.Key
result.set(.f1, pcStyle("\x1b[1;{}P") ++ .{.{ .sequence = "\x1BOP" }});
result.set(.f2, pcStyle("\x1b[1;{}Q") ++ .{.{ .sequence = "\x1BOQ" }});
result.set(.f3, pcStyle("\x1b[13;{}~") ++ .{.{ .sequence = "\x1BOR" }});
result.set(.f4, pcStyle("\x1b[1;{}S") ++ .{.{ .sequence = "\x1BOS" }});
result.set(.f5, pcStyle("\x1b[15;{}~") ++ .{.{ .sequence = "\x1B[15~" }});
result.set(.f6, pcStyle("\x1b[17;{}~") ++ .{.{ .sequence = "\x1B[17~" }});
result.set(.f7, pcStyle("\x1b[18;{}~") ++ .{.{ .sequence = "\x1B[18~" }});
result.set(.f8, pcStyle("\x1b[19;{}~") ++ .{.{ .sequence = "\x1B[19~" }});
result.set(.f9, pcStyle("\x1b[20;{}~") ++ .{.{ .sequence = "\x1B[20~" }});
result.set(.f10, pcStyle("\x1b[21;{}~") ++ .{.{ .sequence = "\x1B[21~" }});
result.set(.f11, pcStyle("\x1b[23;{}~") ++ .{.{ .sequence = "\x1B[23~" }});
result.set(.f12, pcStyle("\x1b[24;{}~") ++ .{.{ .sequence = "\x1B[24~" }});
result.set(.f1, pcStyle("\x1b[1;{}P") ++ .{Entry{ .sequence = "\x1BOP" }});
result.set(.f2, pcStyle("\x1b[1;{}Q") ++ .{Entry{ .sequence = "\x1BOQ" }});
result.set(.f3, pcStyle("\x1b[13;{}~") ++ .{Entry{ .sequence = "\x1BOR" }});
result.set(.f4, pcStyle("\x1b[1;{}S") ++ .{Entry{ .sequence = "\x1BOS" }});
result.set(.f5, pcStyle("\x1b[15;{}~") ++ .{Entry{ .sequence = "\x1B[15~" }});
result.set(.f6, pcStyle("\x1b[17;{}~") ++ .{Entry{ .sequence = "\x1B[17~" }});
result.set(.f7, pcStyle("\x1b[18;{}~") ++ .{Entry{ .sequence = "\x1B[18~" }});
result.set(.f8, pcStyle("\x1b[19;{}~") ++ .{Entry{ .sequence = "\x1B[19~" }});
result.set(.f9, pcStyle("\x1b[20;{}~") ++ .{Entry{ .sequence = "\x1B[20~" }});
result.set(.f10, pcStyle("\x1b[21;{}~") ++ .{Entry{ .sequence = "\x1B[21~" }});
result.set(.f11, pcStyle("\x1b[23;{}~") ++ .{Entry{ .sequence = "\x1B[23~" }});
result.set(.f12, pcStyle("\x1b[24;{}~") ++ .{Entry{ .sequence = "\x1B[24~" }});
// Keypad keys
result.set(.kp_0, kpKeys("p"));
@@ -116,7 +116,7 @@ pub const keys = keys: {
result.set(.kp_multiply, kpKeys("j"));
result.set(.kp_subtract, kpKeys("m"));
result.set(.kp_add, kpKeys("k"));
result.set(.kp_enter, kpKeys("M") ++ .{.{ .sequence = "\r" }});
result.set(.kp_enter, kpKeys("M") ++ .{Entry{ .sequence = "\r" }});
result.set(.kp_up, pcStyle("\x1b[1;{}A") ++ cursorKey("\x1b[A", "\x1bOA"));
result.set(.kp_down, pcStyle("\x1b[1;{}B") ++ cursorKey("\x1b[B", "\x1bOB"));
result.set(.kp_right, pcStyle("\x1b[1;{}C") ++ cursorKey("\x1b[C", "\x1bOC"));
@@ -124,10 +124,10 @@ pub const keys = keys: {
result.set(.kp_begin, pcStyle("\x1b[1;{}E") ++ cursorKey("\x1b[E", "\x1bOE"));
result.set(.kp_home, pcStyle("\x1b[1;{}H") ++ cursorKey("\x1b[H", "\x1bOH"));
result.set(.kp_end, pcStyle("\x1b[1;{}F") ++ cursorKey("\x1b[F", "\x1bOF"));
result.set(.kp_insert, pcStyle("\x1b[2;{}~") ++ .{.{ .sequence = "\x1B[2~" }});
result.set(.kp_delete, pcStyle("\x1b[3;{}~") ++ .{.{ .sequence = "\x1B[3~" }});
result.set(.kp_page_up, pcStyle("\x1b[5;{}~") ++ .{.{ .sequence = "\x1B[5~" }});
result.set(.kp_page_down, pcStyle("\x1b[6;{}~") ++ .{.{ .sequence = "\x1B[6~" }});
result.set(.kp_insert, pcStyle("\x1b[2;{}~") ++ .{Entry{ .sequence = "\x1B[2~" }});
result.set(.kp_delete, pcStyle("\x1b[3;{}~") ++ .{Entry{ .sequence = "\x1B[3~" }});
result.set(.kp_page_up, pcStyle("\x1b[5;{}~") ++ .{Entry{ .sequence = "\x1B[5~" }});
result.set(.kp_page_down, pcStyle("\x1b[6;{}~") ++ .{Entry{ .sequence = "\x1B[6~" }});
result.set(.backspace, &.{
// Modify Keys Normal

View File

@@ -73,7 +73,7 @@ pub fn generate(
var buffer = std.ArrayList(u8).init(page_allocator);
defer buffer.deinit();
const fields = @typeInfo(KeybindAction).Union.fields;
const fields = @typeInfo(KeybindAction).@"union".fields;
inline for (fields) |field| {
if (field.name[0] == '_') continue;

View File

@@ -152,7 +152,7 @@ pub const Mods = packed struct(Mods.Backing) {
pub fn translation(self: Mods, option_as_alt: config.OptionAsAlt) Mods {
// We currently only process macos-option-as-alt so other
// platforms don't need to do anything.
if (comptime !builtin.target.isDarwin()) return self;
if (comptime !builtin.target.os.tag.isDarwin()) return self;
// Alt has to be set only on the correct side
switch (option_as_alt) {
@@ -170,7 +170,7 @@ pub const Mods = packed struct(Mods.Backing) {
/// Checks to see if super is on (MacOS) or ctrl.
pub fn ctrlOrSuper(self: Mods) bool {
if (comptime builtin.target.isDarwin()) {
if (comptime builtin.target.os.tag.isDarwin()) {
return self.super;
}
return self.ctrl;
@@ -187,7 +187,7 @@ pub const Mods = packed struct(Mods.Backing) {
}
test "translation macos-option-as-alt" {
if (comptime !builtin.target.isDarwin()) return error.SkipZigTest;
if (comptime !builtin.target.os.tag.isDarwin()) return error.SkipZigTest;
const testing = std.testing;
@@ -646,7 +646,7 @@ pub const Key = enum(c_int) {
/// true if this key is one of the left or right versions of super (MacOS)
/// or ctrl.
pub fn ctrlOrSuper(self: Key) bool {
if (comptime builtin.target.isDarwin()) {
if (comptime builtin.target.os.tag.isDarwin()) {
return self == .left_super or self == .right_super;
}
return self == .left_control or self == .right_control;
@@ -757,7 +757,7 @@ pub const Key = enum(c_int) {
/// non-Mac we default to ctrl (i.e. ctrl+c for copy).
pub fn ctrlOrSuper(mods: Mods) Mods {
var copy = mods;
if (comptime builtin.target.isDarwin()) {
if (comptime builtin.target.os.tag.isDarwin()) {
copy.super = true;
} else {
copy.ctrl = true;

View File

@@ -27,7 +27,7 @@ pub const Button = enum(c_int) {
/// packed array, for example.
pub const max = max: {
var cur = 0;
for (@typeInfo(Self).Enum.fields) |field| {
for (@typeInfo(Self).@"enum".fields) |field| {
if (field.value > cur) cur = field.value;
}