Skip to content
Merged
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: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ env:
ZIG_VERSION: "0.16.0"

jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v2
with:
version: ${{ env.ZIG_VERSION }}
- run: zig fmt --check src tests examples build.zig

build:
strategy:
fail-fast: false
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ coverage/
# OS files
Thumbs.db
desktop.ini
# macOS writes an AppleDouble sidecar next to every file on a filesystem that
# cannot hold extended attributes (exFAT, NTFS, most network shares). They are
# metadata for a file that is already tracked, and they turn up in their
# thousands.
._*

# Temporary files
*.tmp
Expand Down
3 changes: 2 additions & 1 deletion examples/calendar.zig
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const Model = struct {
help_s = help_s.fg(zz.Color.gray(10));
help_s = help_s.inline_style(true);

const content = std.fmt.allocPrint(alloc,
const content = std.fmt.allocPrint(
alloc,
"{s}\n\n{s}\n\n{s}\n\n{s}",
.{
title_s.render(alloc, "Calendar Demo") catch "Calendar",
Expand Down
20 changes: 10 additions & 10 deletions examples/data_table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ const Model = struct {
};

const rows = [_][]const []const u8{
&.{ "01", "Alice", "Platform", "Berlin", "Engineer", "5y", "4.8", "$120k" },
&.{ "02", "Bob", "Growth", "Lisbon", "PM", "3y", "4.1", "$110k" },
&.{ "03", "Carol", "Platform", "Tokyo", "Staff Eng", "9y", "4.9", "$180k" },
&.{ "04", "Dan", "Infra", "Berlin", "SRE", "2y", "4.3", "$130k" },
&.{ "05", "Eve", "Growth", "Lisbon", "Designer", "1y", "4.5", "$95k" },
&.{ "06", "Frank", "Infra", "Singapore", "Eng Manager", "7y", "4.6", "$160k" },
&.{ "07", "Grace", "Platform", "Berlin", "Engineer", "4y", "4.7", "$125k" },
&.{ "08", "Heidi", "Sec", "Tel Aviv", "Security Eng", "6y", "4.4", "$140k" },
&.{ "09", "Ivan", "Growth", "Lisbon", "Engineer", "2y", "4.0", "$105k" },
&.{ "10", "Judy", "Platform", "Tokyo", "Engineer", "3y", "4.2", "$118k" },
&.{ "01", "Alice", "Platform", "Berlin", "Engineer", "5y", "4.8", "$120k" },
&.{ "02", "Bob", "Growth", "Lisbon", "PM", "3y", "4.1", "$110k" },
&.{ "03", "Carol", "Platform", "Tokyo", "Staff Eng", "9y", "4.9", "$180k" },
&.{ "04", "Dan", "Infra", "Berlin", "SRE", "2y", "4.3", "$130k" },
&.{ "05", "Eve", "Growth", "Lisbon", "Designer", "1y", "4.5", "$95k" },
&.{ "06", "Frank", "Infra", "Singapore", "Eng Manager", "7y", "4.6", "$160k" },
&.{ "07", "Grace", "Platform", "Berlin", "Engineer", "4y", "4.7", "$125k" },
&.{ "08", "Heidi", "Sec", "Tel Aviv", "Security Eng", "6y", "4.4", "$140k" },
&.{ "09", "Ivan", "Growth", "Lisbon", "Engineer", "2y", "4.0", "$105k" },
&.{ "10", "Judy", "Platform", "Tokyo", "Engineer", "3y", "4.2", "$118k" },
};

pub fn init(self: *Model, ctx: *zz.Context) zz.Cmd(Msg) {
Expand Down
3 changes: 2 additions & 1 deletion examples/gauge.zig
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ const Model = struct {
help_s = help_s.fg(zz.Color.gray(10));
help_s = help_s.inline_style(true);

const content = std.fmt.allocPrint(alloc,
const content = std.fmt.allocPrint(
alloc,
"{s}\n\n{s}\n\n{s}\n\n{s}\n\n{s}",
.{
title,
Expand Down
3 changes: 2 additions & 1 deletion examples/sortable_table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const Model = struct {
help_s = help_s.fg(zz.Color.gray(10));
help_s = help_s.inline_style(true);

const content = std.fmt.allocPrint(alloc,
const content = std.fmt.allocPrint(
alloc,
"{s}\n\n{s}\n\n{s}",
.{
title_s.render(alloc, "Sortable Table Demo") catch "",
Expand Down
3 changes: 2 additions & 1 deletion examples/sub_program.zig
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ const Model = struct {

const active_label = if (self.active == 0) "A" else "B";

const content = std.fmt.allocPrint(alloc,
const content = std.fmt.allocPrint(
alloc,
"{s}\n\nActive: {s}\n\n{s}\n\n{s}",
.{
title_s.render(alloc, "Sub-Program Demo") catch "Sub-Program",
Expand Down
3 changes: 2 additions & 1 deletion examples/text_overflow.zig
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ const Model = struct {
label_style = label_style.fg(zz.Color.gray(12));
label_style = label_style.inline_style(true);

const content = std.fmt.allocPrint(alloc,
const content = std.fmt.allocPrint(
alloc,
"{s}\n\n{s} visible (default):\n{s}\n\n{s} hidden (clip):\n{s}\n\n{s} ellipsis:\n{s}\n\n{s} word_wrap:\n{s}\n\n{s} char_wrap:\n{s}\n\nPress q to quit",
.{
title,
Expand Down
3 changes: 2 additions & 1 deletion examples/virtual_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ const Model = struct {
help_s = help_s.fg(zz.Color.gray(10));
help_s = help_s.inline_style(true);

const content = std.fmt.allocPrint(alloc,
const content = std.fmt.allocPrint(
alloc,
"{s}\n\n{s}\n\n{s}",
.{
title_s.render(alloc, std.fmt.allocPrint(alloc, "Virtual List - {d} items", .{TOTAL_ITEMS}) catch "Virtual List") catch "Virtual List",
Expand Down
10 changes: 4 additions & 6 deletions src/core/program.zig
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ pub fn Program(comptime Model: type) type {
.raw = .{ .nanoseconds = @intCast(deadline_offset_ns) },
.clock = .boot,
});
deadline.wait(self.io) catch unreachable;
// A wait that fails (a cancelled or interrupted sleep)
// just means this frame is not paced; `unreachable` here
// would be undefined behaviour in a release build.
deadline.wait(self.io) catch {};
}
}
}
Expand Down Expand Up @@ -814,11 +817,6 @@ pub fn Program(comptime Model: type) type {
return @intCast(ns);
}

fn sleepNs(io: std.Io, nanoseconds: u64) void {
if (nanoseconds == 0) return;
std.Io.sleep(io, .fromNanoseconds(nanoseconds), .boot) catch unreachable;
}

fn resetFrameAllocator(self: *Self) void {
_ = self.arena.reset(.retain_capacity);
self.context.allocator = self.arena.allocator();
Expand Down
2 changes: 1 addition & 1 deletion tests/unicode_tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test "charWidth: emoji are wide" {
defer zz.unicode.setWidthStrategy(.legacy_wcwidth);
try testing.expectEqual(@as(usize, 2), zz.unicode.charWidth(0x1F600)); // grinning face
try testing.expectEqual(@as(usize, 2), zz.unicode.charWidth(0x1F680)); // rocket
try testing.expectEqual(@as(usize, 2), zz.unicode.charWidth(0x2615)); // hot beverage
try testing.expectEqual(@as(usize, 2), zz.unicode.charWidth(0x2615)); // hot beverage
}

test "charWidth: combining marks are zero-width" {
Expand Down
Loading