mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-27 17:41:40 +00:00
Zig 0.15: zig build test
This commit is contained in:
@@ -7,6 +7,7 @@ const Allocator = std.mem.Allocator;
|
||||
const assert = std.debug.assert;
|
||||
const build_config = @import("../build_config.zig");
|
||||
const uucode = @import("uucode");
|
||||
const EntryFormatter = @import("../config/formatter.zig").EntryFormatter;
|
||||
const key = @import("key.zig");
|
||||
const KeyEvent = key.KeyEvent;
|
||||
|
||||
@@ -1184,13 +1185,8 @@ pub const Action = union(enum) {
|
||||
/// action back into the format used by parse.
|
||||
pub fn format(
|
||||
self: Action,
|
||||
comptime layout: []const u8,
|
||||
opts: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
writer: *std.Io.Writer,
|
||||
) !void {
|
||||
_ = layout;
|
||||
_ = opts;
|
||||
|
||||
switch (self) {
|
||||
inline else => |value| {
|
||||
// All actions start with the tag.
|
||||
@@ -1206,16 +1202,16 @@ pub const Action = union(enum) {
|
||||
}
|
||||
|
||||
fn formatValue(
|
||||
writer: anytype,
|
||||
writer: *std.Io.Writer,
|
||||
value: anytype,
|
||||
) !void {
|
||||
const Value = @TypeOf(value);
|
||||
const value_info = @typeInfo(Value);
|
||||
switch (Value) {
|
||||
void => {},
|
||||
[]const u8 => try std.zig.stringEscape(value, "", .{}, writer),
|
||||
[]const u8 => try std.zig.stringEscape(value, writer),
|
||||
else => switch (value_info) {
|
||||
.@"enum" => try writer.print("{s}", .{@tagName(value)}),
|
||||
.@"enum" => try writer.print("{t}", .{value}),
|
||||
.float => try writer.print("{d}", .{value}),
|
||||
.int => try writer.print("{d}", .{value}),
|
||||
.@"struct" => |info| if (!info.is_tuple) {
|
||||
@@ -1648,13 +1644,8 @@ pub const Trigger = struct {
|
||||
/// Format implementation for fmt package.
|
||||
pub fn format(
|
||||
self: Trigger,
|
||||
comptime layout: []const u8,
|
||||
opts: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
writer: *std.Io.Writer,
|
||||
) !void {
|
||||
_ = layout;
|
||||
_ = opts;
|
||||
|
||||
// Modifiers first
|
||||
if (self.mods.super) try writer.writeAll("super+");
|
||||
if (self.mods.ctrl) try writer.writeAll("ctrl+");
|
||||
@@ -1663,7 +1654,7 @@ pub const Trigger = struct {
|
||||
|
||||
// Key
|
||||
switch (self.key) {
|
||||
.physical => |k| try writer.print("{s}", .{@tagName(k)}),
|
||||
.physical => |k| try writer.print("{t}", .{k}),
|
||||
.unicode => |c| try writer.print("{u}", .{c}),
|
||||
}
|
||||
}
|
||||
@@ -1721,13 +1712,8 @@ pub const Set = struct {
|
||||
/// action back into the format used by parse.
|
||||
pub fn format(
|
||||
self: Value,
|
||||
comptime layout: []const u8,
|
||||
opts: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
writer: *std.Io.Writer,
|
||||
) !void {
|
||||
_ = layout;
|
||||
_ = opts;
|
||||
|
||||
switch (self) {
|
||||
.leader => |set| {
|
||||
// the leader key was already printed.
|
||||
@@ -1758,26 +1744,34 @@ pub const Set = struct {
|
||||
/// that is shared between calls to nested levels of the set.
|
||||
/// For example, 'a>b>c=x' and 'a>b>d=y' will re-use the 'a>b' written
|
||||
/// to the buffer before flushing it to the formatter with 'c=x' and 'd=y'.
|
||||
pub fn formatEntries(self: Value, buffer_stream: anytype, formatter: anytype) !void {
|
||||
pub fn formatEntries(
|
||||
self: Value,
|
||||
buffer: *std.Io.Writer,
|
||||
formatter: EntryFormatter,
|
||||
) !void {
|
||||
switch (self) {
|
||||
.leader => |set| {
|
||||
// We'll rewind to this position after each sub-entry,
|
||||
// sharing the prefix between siblings.
|
||||
const pos = try buffer_stream.getPos();
|
||||
const pos = buffer.end;
|
||||
|
||||
var iter = set.bindings.iterator();
|
||||
while (iter.next()) |binding| {
|
||||
buffer_stream.seekTo(pos) catch unreachable; // can't fail
|
||||
std.fmt.format(buffer_stream.writer(), ">{s}", .{binding.key_ptr.*}) catch return error.OutOfMemory;
|
||||
try binding.value_ptr.*.formatEntries(buffer_stream, formatter);
|
||||
// I'm not exactly if this is safe for any arbitrary
|
||||
// writer since the Writer interface does not have any
|
||||
// rewind functions, but for our use case of a
|
||||
// fixed-size buffer writer this should work just fine.
|
||||
buffer.end = pos;
|
||||
buffer.print(">{f}", .{binding.key_ptr.*}) catch return error.OutOfMemory;
|
||||
try binding.value_ptr.*.formatEntries(buffer, formatter);
|
||||
}
|
||||
},
|
||||
|
||||
.leaf => |leaf| {
|
||||
// When we get to the leaf, the buffer_stream contains
|
||||
// the full sequence of keys needed to reach this action.
|
||||
std.fmt.format(buffer_stream.writer(), "={s}", .{leaf.action}) catch return error.OutOfMemory;
|
||||
try formatter.formatEntry([]const u8, buffer_stream.getWritten());
|
||||
buffer.print("={f}", .{leaf.action}) catch return error.OutOfMemory;
|
||||
try formatter.formatEntry([]const u8, buffer.buffer[0..buffer.end]);
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -3234,11 +3228,8 @@ test "action: format" {
|
||||
|
||||
const a: Action = .{ .text = "👻" };
|
||||
|
||||
var buf: std.ArrayListUnmanaged(u8) = .empty;
|
||||
defer buf.deinit(alloc);
|
||||
|
||||
const writer = buf.writer(alloc);
|
||||
try a.format("", .{}, writer);
|
||||
|
||||
try testing.expectEqualStrings("text:\\xf0\\x9f\\x91\\xbb", buf.items);
|
||||
var buf: std.Io.Writer.Allocating = .init(alloc);
|
||||
defer buf.deinit();
|
||||
try a.format(&buf.writer);
|
||||
try testing.expectEqualStrings("text:\\xf0\\x9f\\x91\\xbb", buf.written());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user