mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
input: Binding.Trigger format
This commit is contained in:
@ -57,40 +57,10 @@ fn listDefaultKeybinds(alloc: Allocator) !u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn iterConfig(stdout: anytype, iter: anytype) !u8 {
|
fn iterConfig(stdout: anytype, iter: anytype) !u8 {
|
||||||
const start = @intFromEnum(inputpkg.Key.one);
|
|
||||||
var amount: u8 = 0;
|
|
||||||
|
|
||||||
while (iter.next()) |next| {
|
while (iter.next()) |next| {
|
||||||
const keys = next.key_ptr.*;
|
const keys = next.key_ptr.*;
|
||||||
const value = next.value_ptr.*;
|
const value = next.value_ptr.*;
|
||||||
try stdout.print("{}", .{value});
|
try stdout.print("{}={}\n", .{ keys, value });
|
||||||
|
|
||||||
switch (keys.key) {
|
|
||||||
.one, .two, .three, .four, .five, .six, .seven, .eight, .nine => try stdout.print(" {d} +", .{(@intFromEnum(keys.key) - start) + 1}),
|
|
||||||
inline else => try stdout.print(" {s} +", .{@tagName(keys.key)}),
|
|
||||||
}
|
|
||||||
const fields = @typeInfo(@TypeOf(keys.mods)).Struct.fields;
|
|
||||||
inline for (fields) |field| {
|
|
||||||
switch (field.type) {
|
|
||||||
bool => {
|
|
||||||
if (@field(keys.mods, field.name)) {
|
|
||||||
if (amount >= 1) {
|
|
||||||
try stdout.print(" +", .{});
|
|
||||||
}
|
|
||||||
try stdout.print(" {s}", .{field.name});
|
|
||||||
amount += 1;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
u6 => continue,
|
|
||||||
|
|
||||||
inline else => {
|
|
||||||
try stdout.print("\n", .{});
|
|
||||||
continue;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
amount = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -416,6 +416,27 @@ pub const Trigger = extern struct {
|
|||||||
std.hash.autoHash(&hasher, self.physical);
|
std.hash.autoHash(&hasher, self.physical);
|
||||||
return hasher.final();
|
return hasher.final();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Format implementation for fmt package.
|
||||||
|
pub fn format(
|
||||||
|
self: Trigger,
|
||||||
|
comptime layout: []const u8,
|
||||||
|
opts: std.fmt.FormatOptions,
|
||||||
|
writer: anytype,
|
||||||
|
) !void {
|
||||||
|
_ = layout;
|
||||||
|
_ = opts;
|
||||||
|
|
||||||
|
// Modifiers first
|
||||||
|
if (self.mods.super) try writer.writeAll("super+");
|
||||||
|
if (self.mods.ctrl) try writer.writeAll("ctrl+");
|
||||||
|
if (self.mods.alt) try writer.writeAll("alt+");
|
||||||
|
if (self.mods.shift) try writer.writeAll("shift+");
|
||||||
|
|
||||||
|
// Key
|
||||||
|
if (self.physical) try writer.writeAll("physical:");
|
||||||
|
try writer.print("{s}", .{@tagName(self.key)});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A structure that contains a set of bindings and focuses on fast lookup.
|
/// A structure that contains a set of bindings and focuses on fast lookup.
|
||||||
|
Reference in New Issue
Block a user