Soc Virnyl Estela: 11 build: update to Zig 0.12.0 build: upgrade to Zig 0.13.0 build: change name to zig-spoon in zon file build: add more files to include in zon gitignore: add .zig-cache to gitignore ci: upgrade to Zig 0.13.0 ci: fix download url of Zig 0.13.0 change to std.process.ArgIteratorPosix replace std.os.linux to std.posix os -> posix fmt: run zig fmt 18 files changed, 95 insertions(+), 87 deletions(-)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~leon_plickat/public-inbox/patches/53501/mbox | git am -3Learn more about email & git
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl> --- build.zig | 20 ++++++++------ build.zig.zon | 1 + example/input-demo.zig | 18 ++++++------ example/menu.zig | 8 +++--- lib/Term.zig | 63 +++++++++++++++++++++++------------------- 5 files changed, 60 insertions(+), 50 deletions(-) diff --git a/build.zig b/build.zig index f92ea45..9d464a7 100644 --- a/build.zig @@ -1,14 +1,18 @@ const std = @import("std"); -const Builder = std.build.Builder; +const Build = std.Build; -pub fn build(b: *Builder) !void { +pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const spoon_mod = b.addModule("spoon", .{ - .source_file = .{ .path = "import.zig" }, + .root_source_file = .{ .path = "import.zig" }, + .target = target, + .optimize = optimize, }); + // spoon_mod.addImport("spoon", spoon_mod); + const tests = b.addTest( .{ .root_source_file = .{ .path = "test_main.zig" }, @@ -28,7 +32,7 @@ pub fn build(b: *Builder) !void { .optimize = optimize, }, ); - exe.addModule("spoon", spoon_mod); + exe.root_module.addImport("spoon", spoon_mod); b.installArtifact(exe); } @@ -41,7 +45,7 @@ pub fn build(b: *Builder) !void { .optimize = optimize, }, ); - exe.addModule("spoon", spoon_mod); + exe.root_module.addImport("spoon", spoon_mod); exe.linkLibC(); b.installArtifact(exe); } @@ -55,7 +59,7 @@ pub fn build(b: *Builder) !void { .optimize = optimize, }, ); - exe.addModule("spoon", spoon_mod); + exe.root_module.addImport("spoon", spoon_mod); b.installArtifact(exe); } @@ -68,7 +72,7 @@ pub fn build(b: *Builder) !void { .optimize = optimize, }, ); - exe.addModule("spoon", spoon_mod); + exe.root_module.addImport("spoon", spoon_mod); b.installArtifact(exe); } @@ -81,7 +85,7 @@ pub fn build(b: *Builder) !void { .optimize = optimize, }, ); - exe.addModule("spoon", spoon_mod); + exe.root_module.addImport("spoon", spoon_mod); b.installArtifact(exe); } } diff --git a/build.zig.zon b/build.zig.zon index e6ffd66..71c611c 100644 --- a/build.zig.zon @@ -1,4 +1,5 @@ .{ .name = "spoon", .version = "0.1.0", + .paths = .{""}, } diff --git a/example/input-demo.zig b/example/input-demo.zig index 994a8a4..572fa63 100644 --- a/example/input-demo.zig +++ b/example/input-demo.zig @@ -1,7 +1,7 @@ const std = @import("std"); const mem = std.mem; const heap = std.heap; -const os = std.os; +const os = std.os.linux; const unicode = std.unicode; const spoon = @import("spoon"); @@ -15,29 +15,29 @@ var empty = true; pub fn main() !void { const force_legacy = blk: { var i: usize = 1; - while (i < os.argv.len) : (i += 1) { - if (mem.eql(u8, mem.span(os.argv[i]), "--force-legacy")) break :blk true; + while (i < std.os.argv.len) : (i += 1) { + if (mem.eql(u8, mem.span(std.os.argv[i]), "--force-legacy")) break :blk true; } break :blk false; }; const mouse = blk: { var i: usize = 1; - while (i < os.argv.len) : (i += 1) { - if (mem.eql(u8, mem.span(os.argv[i]), "--mouse")) break :blk true; + while (i < std.os.argv.len) : (i += 1) { + if (mem.eql(u8, mem.span(std.os.argv[i]), "--mouse")) break :blk true; } break :blk false; }; try term.init(.{}); - defer term.deinit(); + try term.deinit(); - try os.sigaction(os.SIG.WINCH, &os.Sigaction{ + try std.posix.sigaction(os.SIG.WINCH, &os.Sigaction{ .handler = .{ .handler = handleSigWinch }, .mask = os.empty_sigset, .flags = 0, }, null); - var fds: [1]os.pollfd = undefined; + var fds: [1]std.posix.pollfd = undefined; fds[0] = .{ .fd = term.tty.?, .events = os.POLL.IN, @@ -54,7 +54,7 @@ pub fn main() !void { try render(); while (loop) { - _ = try os.poll(&fds, -1); + _ = try std.posix.poll(&fds, -1); read = try term.readInput(&buf); empty = false; diff --git a/example/menu.zig b/example/menu.zig index fac21e9..855bd97 100644 --- a/example/menu.zig +++ b/example/menu.zig @@ -2,7 +2,7 @@ const std = @import("std"); const heap = std.heap; const math = std.math; const mem = std.mem; -const os = std.os; +const os = std.posix.system; const spoon = @import("spoon"); @@ -13,9 +13,9 @@ var cursor: usize = 0; pub fn main() !void { try term.init(.{}); - defer term.deinit(); + try term.deinit(); - try os.sigaction(os.SIG.WINCH, &os.Sigaction{ + try std.posix.sigaction(os.SIG.WINCH, &os.Sigaction{ .handler = .{ .handler = handleSigWinch }, .mask = os.empty_sigset, .flags = 0, @@ -38,7 +38,7 @@ pub fn main() !void { var buf: [16]u8 = undefined; while (loop) { - _ = try os.poll(&fds, -1); + _ = try std.posix.poll(&fds, -1); const read = try term.readInput(&buf); var it = spoon.inputParser(buf[0..read]); diff --git a/lib/Term.zig b/lib/Term.zig index db030c2..962fd5e 100644 --- a/lib/Term.zig +++ b/lib/Term.zig @@ -19,14 +19,13 @@ const std = @import("std"); const ascii = std.ascii; const io = std.io; const mem = std.mem; -const os = std.os; +const os = std.posix.system; +const WriteError = std.posix.WriteError; +const OpenError = std.posix.OpenError; const unicode = std.unicode; const debug = std.debug; const math = std.math; -// Workaround for bad libc integration of zigs std. -const constants = if (builtin.link_libc and builtin.os.tag == .linux) os.linux else os.system; - const Attribute = @import("Attribute.zig"); const spells = @import("spells.zig"); const rpw = @import("restricted_padding_writer.zig"); @@ -59,7 +58,7 @@ currently_rendering: bool = false, tty: ?os.fd_t = null, /// Dumb writer. Don't use. -const Writer = io.Writer(os.fd_t, os.WriteError, os.write); +const Writer = io.Writer(os.fd_t, WriteError, std.posix.write); fn writer(self: Self) Writer { return .{ .context = self.tty.? }; } @@ -73,12 +72,13 @@ fn bufferedWriter(self: Self) BufferedWriter { pub fn init(self: *Self, term_config: TermConfig) !void { // Only allow a single successful call to init. debug.assert(self.tty == null); + const flags = os.O{ .ACCMODE = std.posix.ACCMODE.RDWR }; self.* = .{ - .tty = try os.open(term_config.tty_name, constants.O.RDWR, 0), + .tty = try std.posix.open(term_config.tty_name, flags, 0), }; } -pub fn deinit(self: *Self) void { +pub fn deinit(self: *Self) !void { debug.assert(!self.currently_rendering); // Allow multiple calls to deinit, even if init never succeeded. This makes @@ -88,7 +88,7 @@ pub fn deinit(self: *Self) void { // It's probably a good idea to cook the terminal on exit. if (!self.cooked) self.cook() catch {}; - os.close(self.tty.?); + std.posix.close(self.tty.?); self.tty = null; } @@ -96,7 +96,7 @@ pub fn readInput(self: *Self, buffer: []u8) !usize { debug.assert(self.tty != null); debug.assert(!self.currently_rendering); debug.assert(!self.cooked); - return try os.read(self.tty.?, buffer); + return try std.posix.read(self.tty.?, buffer); } /// Enter raw mode. @@ -111,11 +111,10 @@ pub fn uncook(self: *Self, config: AltScreenConfig) !void { // https://viewsourcecode.org/snaptoken/kilo/02.enteringRawMode.html. // TODO: IUTF8 ? - self.cooked_termios = try os.tcgetattr(self.tty.?); + self.cooked_termios = try std.posix.tcgetattr(self.tty.?); errdefer self.cook() catch {}; var raw = self.cooked_termios; - // ECHO: Stop the terminal from displaying pressed keys. // ICANON: Disable canonical ("cooked") mode. Allows us to read inputs // byte-wise instead of line-wise. @@ -123,10 +122,7 @@ pub fn uncook(self: *Self, config: AltScreenConfig) !void { // can handle them as normal escape sequences. // IEXTEN: Disable input preprocessing. This allows us to handle Ctrl-V, // which would otherwise be intercepted by some terminals. - raw.lflag &= ~@as( - constants.tcflag_t, - constants.ECHO | constants.ICANON | constants.ISIG | constants.IEXTEN, - ); + raw.lflag = os.tc_lflag_t{ .ECHO = false, .ICANON = false, .ISIG = false, .IEXTEN = false }; // IXON: Disable software control flow. This allows us to handle Ctrl-S // and Ctrl-Q. @@ -138,25 +134,34 @@ pub fn uncook(self: *Self, config: AltScreenConfig) !void { // remotely modern. // ISTRIP: Disable stripping the 8th bit of characters. Likely has no effect // on anything remotely modern. - raw.iflag &= ~@as( - constants.tcflag_t, - constants.IXON | constants.ICRNL | constants.BRKINT | constants.INPCK | constants.ISTRIP, - ); + raw.iflag = os.tc_iflag_t{ + .IXON = false, + .ICRNL = false, + .BRKINT = false, + .INPCK = false, + .ISTRIP = false, + }; // Disable output processing. Common output processing includes prefixing // newline with a carriage return. - raw.oflag &= ~@as(constants.tcflag_t, constants.OPOST); + raw.oflag = os.tc_oflag_t{ + .OPOST = false, + }; // Set the character size to 8 bits per byte. Likely has no efffect on // anything remotely modern. - raw.cflag |= constants.CS8; + raw.cflag = os.tc_cflag_t{ + .CSIZE = os.CSIZE.CS8, + }; // With these settings, the read syscall will immediately return when it // can't get any bytes. This allows poll to drive our loop. - raw.cc[constants.V.TIME] = 0; - raw.cc[constants.V.MIN] = 0; + // os.V.TIME is index 5 + raw.cc[5] = 0; + // os.V.MIN is index 6 + raw.cc[6] = 0; - try os.tcsetattr(self.tty.?, .FLUSH, raw); + try std.posix.tcsetattr(self.tty.?, .FLUSH, raw); var bufwriter = self.bufferedWriter(); const wrtr = bufwriter.writer(); @@ -203,17 +208,17 @@ pub fn cook(self: *Self) !void { ); try bufwriter.flush(); - try os.tcsetattr(self.tty.?, .FLUSH, self.cooked_termios); + try std.posix.tcsetattr(self.tty.?, .FLUSH, self.cooked_termios); } pub fn fetchSize(self: *Self) !void { debug.assert(self.tty != null); if (self.cooked) return; - var size = mem.zeroes(constants.winsize); - const err = os.system.ioctl(self.tty.?, constants.T.IOCGWINSZ, @intFromPtr(&size)); - if (os.errno(err) != .SUCCESS) { - return os.unexpectedErrno(@as(os.system.E, @enumFromInt(err))); + var size = mem.zeroes(os.winsize); + const err = os.ioctl(self.tty.?, os.T.IOCGWINSZ, @intFromPtr(&size)); + if (std.posix.errno(err) != .SUCCESS) { + return std.posix.unexpectedErrno(@as(os.E, @enumFromInt(err))); } self.height = size.ws_row; self.width = size.ws_col; -- 2.45.2
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl> --- build.zig | 14 +++++++------- build.zig.zon | 7 ++++++- lib/colour_description.zig | 2 +- lib/input.zig | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/build.zig b/build.zig index 9d464a7..f9b7f58 100644 --- a/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *Build) !void { const optimize = b.standardOptimizeOption(.{}); const spoon_mod = b.addModule("spoon", .{ - .root_source_file = .{ .path = "import.zig" }, + .root_source_file = b.path("import.zig"), .target = target, .optimize = optimize, }); @@ -15,7 +15,7 @@ pub fn build(b: *Build) !void { const tests = b.addTest( .{ - .root_source_file = .{ .path = "test_main.zig" }, + .root_source_file = b.path("test_main.zig"), .target = target, .optimize = optimize, }, @@ -27,7 +27,7 @@ pub fn build(b: *Build) !void { const exe = b.addExecutable( .{ .name = "menu", - .root_source_file = .{ .path = "example/menu.zig" }, + .root_source_file = b.path("example/menu.zig"), .target = target, .optimize = optimize, }, @@ -40,7 +40,7 @@ pub fn build(b: *Build) !void { const exe = b.addExecutable( .{ .name = "menu-libc", - .root_source_file = .{ .path = "example/menu.zig" }, + .root_source_file = b.path("example/menu.zig"), .target = target, .optimize = optimize, }, @@ -54,7 +54,7 @@ pub fn build(b: *Build) !void { const exe = b.addExecutable( .{ .name = "input-demo", - .root_source_file = .{ .path = "example/input-demo.zig" }, + .root_source_file = b.path("example/input-demo.zig"), .target = target, .optimize = optimize, }, @@ -67,7 +67,7 @@ pub fn build(b: *Build) !void { const exe = b.addExecutable( .{ .name = "colours", - .root_source_file = .{ .path = "example/colours.zig" }, + .root_source_file = b.path("example/colours.zig"), .target = target, .optimize = optimize, }, @@ -80,7 +80,7 @@ pub fn build(b: *Build) !void { const exe = b.addExecutable( .{ .name = "table-256-colours", - .root_source_file = .{ .path = "example/table-256-colours.zig" }, + .root_source_file = b.path("example/table-256-colours.zig"), .target = target, .optimize = optimize, }, diff --git a/build.zig.zon b/build.zig.zon index 71c611c..50b7f7f 100644 --- a/build.zig.zon @@ -1,5 +1,10 @@ .{ .name = "spoon", .version = "0.1.0", - .paths = .{""}, + .paths = .{ + "build.zig", + "build.zig.zon", + "LICENSE" + }, + .dependencies = .{} } diff --git a/lib/colour_description.zig b/lib/colour_description.zig index e6673b4..b58f681 100644 --- a/lib/colour_description.zig +++ b/lib/colour_description.zig @@ -114,7 +114,7 @@ test "parse colours string (bad input)" { const colour_names = blk: { @setEvalBranchQuota(100000); - break :blk std.ComptimeStringMap(Colour, .{ + break :blk std.StaticStringMap(Colour).initComptime(.{ // Terminal colours. .{ "none", .none }, .{ "black", .black }, diff --git a/lib/input.zig b/lib/input.zig index 3e53ce4..51e2dc6 100644 --- a/lib/input.zig +++ b/lib/input.zig @@ -334,7 +334,7 @@ const InputParser = struct { if (modifiers_str) |_| len += modifiers_str.?.len + ";".len; self.advanceBufferBy(len); } - const sequences = std.ComptimeStringMap(Input, .{ + const sequences = std.StaticStringMap(Input).initComptime(.{ .{ "1", .{ .content = .home } }, .{ "2", .{ .content = .insert } }, .{ "3", .{ .content = .delete } }, -- 2.45.2
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl> --- build.zig.zon | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.zig.zon b/build.zig.zon index 50b7f7f..ffe4218 100644 --- a/build.zig.zon @@ -1,9 +1,10 @@ .{ - .name = "spoon", + .name = "zig-spoon", .version = "0.1.0", .paths = .{ "build.zig", "build.zig.zon", + "import.zig", "LICENSE" }, .dependencies = .{} -- 2.45.2
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl> --- build.zig.zon | 1 + 1 file changed, 1 insertion(+) diff --git a/build.zig.zon b/build.zig.zon index ffe4218..b836d73 100644 --- a/build.zig.zon @@ -4,6 +4,7 @@ .paths = .{ "build.zig", "build.zig.zon", + "lib", "import.zig", "LICENSE" }, -- 2.45.2
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl> --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e73c965..8be35bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ zig-cache/ +.zig-cache/ zig-out/ -- 2.45.2
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl> --- .builds/alpine.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.builds/alpine.yml b/.builds/alpine.yml index ad2c85c..677ea04 100644 --- a/.builds/alpine.yml +++ b/.builds/alpine.yml @@ -6,10 +6,10 @@ sources: - https://git.sr.ht/~leon_plickat/zig-spoon tasks: - install_deps: | - wget -q https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz - tar -xvf zig-linux-x86_64-0.11.0.tar.xz 1>/dev/null - sudo mv zig-linux-x86_64-0.11.0/zig /usr/bin/ - sudo mv zig-linux-x86_64-0.11.0/lib /usr/lib/zig + wget -q https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.13.0.tar.xz + tar -xvf zig-linux-x86_64-0.13.0.tar.xz 1>/dev/null + sudo mv zig-linux-x86_64-0.13.0/zig /usr/bin/ + sudo mv zig-linux-x86_64-0.13.0/lib /usr/lib/zig - build: | cd zig-spoon zig build -- 2.45.2
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl> --- .builds/alpine.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.builds/alpine.yml b/.builds/alpine.yml index 677ea04..fda2f45 100644 --- a/.builds/alpine.yml +++ b/.builds/alpine.yml @@ -6,7 +6,7 @@ sources: - https://git.sr.ht/~leon_plickat/zig-spoon tasks: - install_deps: | - wget -q https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.13.0.tar.xz + wget -q https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz tar -xvf zig-linux-x86_64-0.13.0.tar.xz 1>/dev/null sudo mv zig-linux-x86_64-0.13.0/zig /usr/bin/ sudo mv zig-linux-x86_64-0.13.0/lib /usr/lib/zig -- 2.45.2
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl> --- example/input-demo.zig | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/example/input-demo.zig b/example/input-demo.zig index 572fa63..5fd3689 100644 --- a/example/input-demo.zig +++ b/example/input-demo.zig @@ -2,6 +2,7 @@ const std = @import("std"); const mem = std.mem; const heap = std.heap; const os = std.os.linux; +const argv = std.process.ArgIteratorPosix; const unicode = std.unicode; const spoon = @import("spoon"); @@ -15,15 +16,15 @@ var empty = true; pub fn main() !void { const force_legacy = blk: { var i: usize = 1; - while (i < std.os.argv.len) : (i += 1) { - if (mem.eql(u8, mem.span(std.os.argv[i]), "--force-legacy")) break :blk true; + while (i < argv.len) : (i += 1) { + if (mem.eql(u8, mem.span(argv[i]), "--force-legacy")) break :blk true; } break :blk false; }; const mouse = blk: { var i: usize = 1; - while (i < std.os.argv.len) : (i += 1) { - if (mem.eql(u8, mem.span(std.os.argv[i]), "--mouse")) break :blk true; + while (i < argv.len) : (i += 1) { + if (mem.eql(u8, mem.span(argv[i]), "--mouse")) break :blk true; } break :blk false; }; -- 2.45.2
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl> --- example/input-demo.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/input-demo.zig b/example/input-demo.zig index 5fd3689..cd191d2 100644 --- a/example/input-demo.zig +++ b/example/input-demo.zig @@ -1,7 +1,7 @@ const std = @import("std"); const mem = std.mem; const heap = std.heap; -const os = std.os.linux; +const os = std.posix; const argv = std.process.ArgIteratorPosix; const unicode = std.unicode; -- 2.45.2
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl> --- example/input-demo.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example/input-demo.zig b/example/input-demo.zig index cd191d2..d60a9ce 100644 --- a/example/input-demo.zig +++ b/example/input-demo.zig @@ -1,7 +1,7 @@ const std = @import("std"); const mem = std.mem; const heap = std.heap; -const os = std.posix; +const posix = std.posix; const argv = std.process.ArgIteratorPosix; const unicode = std.unicode; @@ -32,13 +32,13 @@ pub fn main() !void { try term.init(.{}); try term.deinit(); - try std.posix.sigaction(os.SIG.WINCH, &os.Sigaction{ + try posix.sigaction(os.SIG.WINCH, &os.Sigaction{ .handler = .{ .handler = handleSigWinch }, .mask = os.empty_sigset, .flags = 0, }, null); - var fds: [1]std.posix.pollfd = undefined; + var fds: [1]posix.pollfd = undefined; fds[0] = .{ .fd = term.tty.?, .events = os.POLL.IN, @@ -55,7 +55,7 @@ pub fn main() !void { try render(); while (loop) { - _ = try std.posix.poll(&fds, -1); + _ = try posix.poll(&fds, -1); read = try term.readInput(&buf); empty = false; -- 2.45.2
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl> --- build.zig.zon | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index b836d73..a6f81d8 100644 --- a/build.zig.zon @@ -1,12 +1 @@ -.{ - .name = "zig-spoon", - .version = "0.1.0", - .paths = .{ - "build.zig", - "build.zig.zon", - "lib", - "import.zig", - "LICENSE" - }, - .dependencies = .{} -} +.{ .name = "zig-spoon", .version = "0.1.0", .paths = .{ "build.zig", "build.zig.zon", "lib", "import.zig", "LICENSE" }, .dependencies = .{} } -- 2.45.2