diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 12:38:55 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 14:56:36 -0300 |
| commit | a9490f3d11e2ad19bb53f994fe506e1c2e094d96 (patch) | |
| tree | 69cfe4e989abcfd5629857089ff9ab5c93dfbc34 /src | |
| parent | dde4979f59bec754b7909a81a40763850f3c29c0 (diff) | |
| download | pardes-a9490f3d11e2ad19bb53f994fe506e1c2e094d96.tar.gz pardes-a9490f3d11e2ad19bb53f994fe506e1c2e094d96.zip | |
idioms #6, std.Io where the host has one, and libc's reasons where it stays: fonts reads a face's tables through std.Io.File (monospaced takes the walk's io), and each host's libc alias says what it is still for (ptys, sockets passing fds, signal handlers and forked children, O_NONBLOCK opens, inotify, the registry's symlinks, a cancelable task's unlink)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
| -rw-r--r-- | src/9p_io.zig | 1 | ||||
| -rw-r--r-- | src/Handover.zig | 1 | ||||
| -rw-r--r-- | src/daemon.zig | 1 | ||||
| -rw-r--r-- | src/file_watch.zig | 1 | ||||
| -rw-r--r-- | src/fonts.zig | 28 | ||||
| -rw-r--r-- | src/fs.zig | 1 | ||||
| -rw-r--r-- | src/gui/gui.zig | 1 | ||||
| -rw-r--r-- | src/host_io.zig | 1 | ||||
| -rw-r--r-- | src/tui/tui.zig | 1 | ||||
| -rw-r--r-- | src/upgrade.zig | 1 |
10 files changed, 23 insertions, 14 deletions
diff --git a/src/9p_io.zig b/src/9p_io.zig index bc122109..e1472006 100644 --- a/src/9p_io.zig +++ b/src/9p_io.zig @@ -1,4 +1,5 @@ const std = @import("std"); +/// libc: sockets, flock'd lock files, and the registry's symlinks, judged with readlink's own truncation and unlinked from signal handlers. const libc = std.c; const builtin = @import("builtin"); const ninep = @import("9p.zig"); diff --git a/src/Handover.zig b/src/Handover.zig index ed52271f..abba41a8 100644 --- a/src/Handover.zig +++ b/src/Handover.zig @@ -30,6 +30,7 @@ const tagline = @import("tagline.zig"); const walk = @import("walk.zig"); const Pardes = pardes.Pardes; const MAX_PANES = pardes.MAX_PANES; +/// libc: fork and exec of a window, and file calls in the cancelable carry task that must not see its cancel (its defer's unlink). const libc = std.c; /// What a grip carries out of its window: one pane with the panes attached diff --git a/src/daemon.zig b/src/daemon.zig index 118fa58a..009b81e3 100644 --- a/src/daemon.zig +++ b/src/daemon.zig @@ -23,6 +23,7 @@ //! the connection is handed to that session, which it talks to from then on. const std = @import("std"); const builtin = @import("builtin"); +/// libc: sockets passing fds (SCM_RIGHTS), fork and setsid, and unlinks a signal handler or a forked child makes. const libc = std.c; const posix = std.posix; const ninep_io = @import("9p_io.zig"); diff --git a/src/file_watch.zig b/src/file_watch.zig index 1e8c450a..56d2d8e5 100644 --- a/src/file_watch.zig +++ b/src/file_watch.zig @@ -11,6 +11,7 @@ //! knows which one it is on. const std = @import("std"); const builtin = @import("builtin"); +/// libc: inotify and kqueue, which std.Io does not have. const libc = std.c; const linux = std.os.linux; const pardes = @import("pardes.zig"); diff --git a/src/fonts.zig b/src/fonts.zig index 505190bd..5f036119 100644 --- a/src/fonts.zig +++ b/src/fonts.zig @@ -16,6 +16,7 @@ //! disagree about how to RASTERIZE a file, never about which files there are. const std = @import("std"); const builtin = @import("builtin"); +/// libc: the tests' scratch fonts, written raw into /tmp. const libc = std.c; /// Where each platform keeps fonts. The `home` list is relative to $HOME (a @@ -152,7 +153,7 @@ fn scan( // e.path points into the walker's own buffer and dies at the next // next(), so the path is spelled out here and copied below const path = std.fmt.bufPrintSentinel(&path_buf, "{s}/{s}", .{ root, e.path }, 0) catch continue; - if (require_monospaced and !monospaced(path)) continue; + if (require_monospaced and !monospaced(io, path)) continue; found[found_len] = .{ .name = arena.dupe(u8, name) catch break, .path = arena.dupe(u8, path) catch break, @@ -237,24 +238,23 @@ test "the picker lists every monospace face rather than the first max_fonts" { /// latin — the range a terminal is actually worn in — which also (deliberately) /// keeps the CJK mono faces whose *later* glyphs are double-width, exactly the /// fonts fontconfig calls "dual-width" and refuses. -fn monospaced(path_z: [*:0]const u8) bool { - const fd = libc.open(path_z, .{ .ACCMODE = .RDONLY, .CLOEXEC = true }); - if (fd < 0) return false; - defer _ = libc.close(fd); +fn monospaced(io: std.Io, path: []const u8) bool { + const file = std.Io.Dir.cwd().openFile(io, path, .{}) catch return false; + defer file.close(io); // 12-byte header + one 16-byte record per table; 256 records is far more // than any real font carries var head: [12 + 16 * 256]u8 = undefined; - const n = libc.pread(fd, &head, head.len, 0); + const n = file.readPositionalAll(io, &head, 0) catch return false; if (n < 12) return false; - const hhea = tableOffset(head[0..@intCast(n)], "hhea") orelse return false; - const hmtx = tableOffset(head[0..@intCast(n)], "hmtx") orelse return false; + const hhea = tableOffset(head[0..n], "hhea") orelse return false; + const hmtx = tableOffset(head[0..n], "hmtx") orelse return false; var hh: [36]u8 = undefined; - if (libc.pread(fd, &hh, hh.len, hhea) != @as(isize, hh.len)) return false; + if ((file.readPositionalAll(io, &hh, hhea) catch return false) != hh.len) return false; const metrics = std.mem.readInt(u16, hh[34..36], .big); const k: usize = @min(@as(usize, metrics), 64); if (k == 0) return false; var mx: [64 * 4]u8 = undefined; - if (libc.pread(fd, &mx, k * 4, hmtx) != @as(isize, @intCast(k * 4))) return false; + if ((file.readPositionalAll(io, mx[0 .. k * 4], hmtx) catch return false) != k * 4) return false; var ref: u16 = 0; for (0..k) |i| { const adv = std.mem.readInt(u16, mx[i * 4 ..][0..2], .big); @@ -337,12 +337,12 @@ test "monospaced reads the advances out of a real sfnt layout" { const path = scratchFont(&path_buf, ".ttf"); defer _ = libc.unlink(path); try writeScratch(path, &f); - try std.testing.expect(monospaced(path)); + try std.testing.expect(monospaced(std.testing.io, path)); // ...and one glyph a different width makes it proportional std.mem.writeInt(u16, f[80 + 4 ..][0..2], 1200, .big); try writeScratch(path, &f); - try std.testing.expect(!monospaced(path)); + try std.testing.expect(!monospaced(std.testing.io, path)); } test "a ttc collection is read through its first face" { @@ -371,12 +371,12 @@ test "a ttc collection is read through its first face" { const path = scratchFont(&path_buf, ".ttc"); defer _ = libc.unlink(path); try writeScratch(path, &f); - try std.testing.expect(monospaced(path)); + try std.testing.expect(monospaced(std.testing.io, path)); // A collection claiming no faces has no first one to read. std.mem.writeInt(u32, f[8..12], 0, .big); try writeScratch(path, &f); - try std.testing.expect(!monospaced(path)); + try std.testing.expect(!monospaced(std.testing.io, path)); } test "the walk finds this machine's monospace faces" { @@ -1,5 +1,6 @@ const std = @import("std"); const limits = @import("memory.zig").limits; +/// libc: opens with O_NONBLOCK (a FIFO must not hang the editor), which std.Io's open has no flag for, and errno mapped to fs's own errors. const libc = std.c; const pardes = @import("pardes.zig"); const config = @import("config.zig"); diff --git a/src/gui/gui.zig b/src/gui/gui.zig index d2e17508..55efeec1 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -2,6 +2,7 @@ const filesystem = @import("../fs.zig"); const std = @import("std"); const builtin = @import("builtin"); const posix = std.posix; +/// libc: pipes and fcntl for the window's wakes, and a test harness's capture files written from the render thread. const libc = std.c; const vaxis = @import("vaxis"); // test modes only: the stdin escape-seq parser const ghostty_vt = @import("ghostty-vt"); // 256-color palette for .index cells diff --git a/src/host_io.zig b/src/host_io.zig index 1b82e6bc..6ce26e41 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -1,6 +1,7 @@ const builtin = @import("builtin"); const std = @import("std"); const posix = std.posix; +/// libc: ptys, fork and exec, signals; and the leaf file calls (/proc, PATH, the prompt rc files), which run with no io: in a forked child, a signal handler, or for callers holding none. const libc = std.c; const pardes = @import("pardes.zig"); const selection_pipe = @import("selection_pipe.zig"); diff --git a/src/tui/tui.zig b/src/tui/tui.zig index 78789f69..5532fdb3 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -2,6 +2,7 @@ const filesystem = @import("../fs.zig"); const std = @import("std"); const builtin = @import("builtin"); const posix = std.posix; +/// libc: termios, signals, kitty shm segments and the fds a terminal hands over. const libc = std.c; const vaxis = @import("vaxis"); const pardes = @import("../pardes.zig"); diff --git a/src/upgrade.zig b/src/upgrade.zig index 0f4532a5..5bd83a30 100644 --- a/src/upgrade.zig +++ b/src/upgrade.zig @@ -15,6 +15,7 @@ //! loaded). const std = @import("std"); const builtin = @import("builtin"); +/// libc: exec of the new build with fds held across it, and /proc/self/exe opened before it. const libc = std.c; const posix = std.posix; const pardes = @import("pardes.zig"); |
