Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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);
Expand All @@ -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)

Expand Down
14 changes: 8 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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())},
);
}
9 changes: 3 additions & 6 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const std = @import("std");
const builtin = @import("builtin");
const io = std.io;
const os = std.os;

/// Terminal size dimensions
Expand All @@ -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()),
/// );
/// }
/// ```
Expand Down Expand Up @@ -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())});
}