diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a004a4..a599587 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,15 +13,20 @@ jobs: - windows-latest - macos-latest zig-version: - - 0.14.0 + - 0.15.1 + - 0.15.2 + - latest runs-on: ${{ matrix.os }} permissions: contents: write steps: - name: Checkout uses: actions/checkout@v4 - - uses: goto-bus-stop/setup-zig@v2 + - uses: mlugg/setup-zig@v2 with: version: ${{ matrix.zig-version }} + cache-key: ${{ matrix.zig-version }} - name: Test run: zig build test --summary all + - name: Build demo example + run: zig build demo-example diff --git a/README.md b/README.md index 1203ed4..d8fed79 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ --- -[![CI](https://github.com/softprops/zig-termsize/actions/workflows/ci.yml/badge.svg)](https://github.com/softprops/zig-termsize/actions/workflows/ci.yml) ![License Info](https://img.shields.io/github/license/softprops/zig-termsize) ![Release](https://img.shields.io/github/v/release/softprops/zig-termsize) ![Zig Support](https://img.shields.io/badge/zig-0.12.0%2F0.13.0-black?logo=zig) +[![CI](https://github.com/softprops/zig-termsize/actions/workflows/ci.yml/badge.svg)](https://github.com/softprops/zig-termsize/actions/workflows/ci.yml) ![License Info](https://img.shields.io/github/license/softprops/zig-termsize) ![Release](https://img.shields.io/github/v/release/softprops/zig-termsize) ![Zig Support](https://img.shields.io/badge/zig-0.15.1%2F0.15.2-black?logo=zig) ## 🍬 features @@ -23,14 +23,14 @@ const termsize = @import("termsize"); pub fn main() !void { std.debug.print( "{any}", - .{termsize.termSize(std.io.getStdOut())}, + .{termsize.termSize(std.fs.File.stdout())}, ); } ``` ## 📼 installing -Create a new exec project with `zig init-exe`. Copy the echo handler example above into `src/main.zig` +Create a new exec project with `zig init`. Copy the echo handler example above into `src/main.zig` Create a `build.zig.zon` file to declare a dependency @@ -78,9 +78,11 @@ pub fn build(b: *std.Build) void { + }).module("termsize"); var exe = b.addExecutable(.{ .name = "your-exe", - .root_source_file = .{ .path = "src/main.zig" }, - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }), }); + // 👇 add the termsize module to executable + exe.root_module.addImport("termsize", termsize); @@ -94,7 +96,7 @@ pub fn build(b: *std.Build) void { Does this look interesting but you're new to zig and feel left out? No problem, zig is young so most us of our new are as well. Here are some resources to help get you up to speed on zig - [the official zig website](https://ziglang.org/) -- [zig's one-page language documentation](https://ziglang.org/documentation/0.13.0/) +- [zig's one-page language documentation](https://ziglang.org/documentation/0.15.2/) - [ziglearn](https://ziglearn.org/) - [ziglings exercises](https://github.com/ratfactor/ziglings) diff --git a/build.zig b/build.zig index 747167d..ca76a3e 100644 --- a/build.zig +++ b/build.zig @@ -18,6 +18,8 @@ pub fn build(b: *std.Build) !void { // create a module to be used internally. const termsize_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, }); // register the module so it can be referenced @@ -27,9 +29,7 @@ pub fn build(b: *std.Build) !void { // Creates a step for unit testing. This only builds the test executable // but does not run it. const main_tests = b.addTest(.{ - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, + .root_module = termsize_module, }); const run_main_tests = b.addRunArtifact(main_tests); @@ -69,9 +69,11 @@ pub fn build(b: *std.Build) !void { var exe = b.addExecutable(.{ .name = example.name, - .root_source_file = b.path(example.src), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path(example.src), + .target = target, + .optimize = optimize, + }), }); exe.root_module.addImport("termsize", termsize_module); diff --git a/build.zig.zon b/build.zig.zon index c89a119..e298646 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -2,7 +2,7 @@ .name = .termsize, .fingerprint = 0x657ac701d6016cd2, .version = "0.1.0", - .minimum_zig_version = "0.14.0", + .minimum_zig_version = "0.15.1", .paths = .{ "build.zig", "build.zig.zon", diff --git a/examples/demo/main.zig b/examples/demo/main.zig index 9f705e9..7f7b2c2 100644 --- a/examples/demo/main.zig +++ b/examples/demo/main.zig @@ -4,6 +4,6 @@ const termsize = @import("termsize"); pub fn main() !void { std.debug.print( "{any}", - .{termsize.termSize(std.io.getStdOut())}, + .{termsize.termSize(std.fs.File.stdout())}, ); } diff --git a/src/main.zig b/src/main.zig index 011657a..1a2bf03 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,6 +1,5 @@ const std = @import("std"); const builtin = @import("builtin"); -const io = std.io; const os = std.os; /// Terminal size dimensions @@ -11,18 +10,16 @@ pub const TermSize = struct { height: u16, }; -/// supports windows, linux, macos -/// /// ## example /// /// ```zig /// const std = @import("std"); -/// const termSize = @import("termSize"); +/// const termSize = @import("termsize"); /// /// fn main() !void { /// std.debug.print( /// "{any}", -/// termSize.termSize(std.os.getStdOut()), +/// termSize.termSize(std.fs.File.stdout()), /// ); /// } /// ``` @@ -65,5 +62,5 @@ pub fn termSize(file: std.fs.File) !?TermSize { } test "termSize" { - std.debug.print("termsize {any}", .{termSize(std.io.getStdOut())}); + std.debug.print("termsize {any}", .{termSize(std.fs.File.stdout())}); }