From cf0e38bff1633164b7defb2d3715a89420de08e7 Mon Sep 17 00:00:00 2001 From: Kalle Carlbark Date: Mon, 5 Aug 2024 10:49:33 +0200 Subject: [PATCH] Initial commit --- .gitignore | 2 + build.zig | 96 ++++++++++++++++++++++++++++++++++++++++++++ build.zig.zon | 39 ++++++++++++++++++ img/apple-dark.png | Bin 0 -> 13992 bytes src/main.zig | 97 +++++++++++++++++++++++++++++++++++++++++++++ src/root.zig | 10 +++++ 6 files changed, 244 insertions(+) create mode 100644 .gitignore create mode 100644 build.zig create mode 100644 build.zig.zon create mode 100644 img/apple-dark.png create mode 100644 src/main.zig create mode 100644 src/root.zig diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8c8979 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.zig-cache +zig-out diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..fd2a83e --- /dev/null +++ b/build.zig @@ -0,0 +1,96 @@ +const std = @import("std"); + +// Although this function looks imperative, note that its job is to +// declaratively construct a build graph that will be executed by an external +// runner. +pub fn build(b: *std.Build) void { + // Standard target options allows the person running `zig build` to choose + // what target to build for. Here we do not override the defaults, which + // means any target is allowed, and the default is native. Other options + // for restricting supported target set are available. + const target = b.standardTargetOptions(.{}); + + // Standard optimization options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not + // set a preferred release mode, allowing the user to decide how to optimize. + const optimize = b.standardOptimizeOption(.{}); + + const vaxis_dep = b.dependency("vaxis", .{ .target = target, .optimize = optimize }); + const vaxis = vaxis_dep.module("vaxis"); + + const lib = b.addStaticLibrary(.{ + .name = "infoz", + // In this case the main source file is merely a path, however, in more + // complicated build scripts, this could be a generated file. + .root_source_file = b.path("src/root.zig"), + .target = target, + .optimize = optimize, + }); + + // This declares intent for the library to be installed into the standard + // location when the user invokes the "install" step (the default step when + // running `zig build`). + b.installArtifact(lib); + + const exe = b.addExecutable(.{ + .name = "infoz", + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + + exe.root_module.addImport("vaxis", vaxis); + + // This declares intent for the executable to be installed into the + // standard location when the user invokes the "install" step (the default + // step when running `zig build`). + b.installArtifact(exe); + + // This *creates* a Run step in the build graph, to be executed when another + // step is evaluated that depends on it. The next line below will establish + // such a dependency. + const run_cmd = b.addRunArtifact(exe); + + // By making the run step depend on the install step, it will be run from the + // installation directory rather than directly from within the cache directory. + // This is not necessary, however, if the application depends on other installed + // files, this ensures they will be present and in the expected location. + run_cmd.step.dependOn(b.getInstallStep()); + + // This allows the user to pass arguments to the application in the build + // command itself, like this: `zig build run -- arg1 arg2 etc` + if (b.args) |args| { + run_cmd.addArgs(args); + } + + // This creates a build step. It will be visible in the `zig build --help` menu, + // and can be selected like this: `zig build run` + // This will evaluate the `run` step rather than the default, which is "install". + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); + + // Creates a step for unit testing. This only builds the test executable + // but does not run it. + const lib_unit_tests = b.addTest(.{ + .root_source_file = b.path("src/root.zig"), + .target = target, + .optimize = optimize, + }); + + const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); + + const exe_unit_tests = b.addTest(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + + const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); + + // Similar to creating the run step earlier, this exposes a `test` step to + // the `zig build --help` menu, providing a way for the user to request + // running the unit tests. + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&run_lib_unit_tests.step); + test_step.dependOn(&run_exe_unit_tests.step); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..1aa47e1 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,39 @@ +.{ + // This is the default name used by packages depending on this one. For + // example, when a user runs `zig fetch --save `, this field is used + // as the key in the `dependencies` table. Although the user can choose a + // different name, most users will stick with this provided value. + // + // It is redundant to include "zig" in this name because it is already + // within the Zig package namespace. + .name = "infoz", + + // This is a [Semantic Version](https://semver.org/). + // In a future version of Zig it will be used for package deduplication. + .version = "0.0.0", + + // This field is optional. + // This is currently advisory only; Zig does not yet do anything + // with this value. + //.minimum_zig_version = "0.11.0", + + // This field is optional. + // Each dependency must either provide a `url` and `hash`, or a `path`. + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. + // Once all dependencies are fetched, `zig build` no longer requires + // internet connectivity. + .dependencies = .{ + .vaxis = .{ + .url = "https://github.com/rockorager/libvaxis/archive/refs/heads/main.tar.gz", + .hash = "1220dab128b93a06ebca095bd38747f50cf9762b524e39e76de8771685264fd16841", + }, + }, + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + // For example... + //"LICENSE", + //"README.md", + }, +} diff --git a/img/apple-dark.png b/img/apple-dark.png new file mode 100644 index 0000000000000000000000000000000000000000..493e4e1b23d99a1aeafddadd88ce88b664e7c681 GIT binary patch literal 13992 zcmcJ$cT`hd_bwV@L{K_P6$uc)LJK8G2T>q&DJs2p0!Z&gkfPLt-j$9tDGErH-ZdZ? zKv1fY-aFhK-}ijKZ`^b5KWB^+vd7-ptIajnTx-qenTse*bw%>4Ojki55IIump%w^4 zgaj@<5@O)Z4Z|Nozzt#}rzQsiy^p(gYIYg;4Yg3xQUif}xj>-cFc9b%coqB`1o997 zf&Q3+K;o$&5WP!g<6}u6A0xm+Cf9{uZiT1=Mr=Z$h9lmbb5ivy1+D|a)f zH_Fk;P25|G{cjF&;F<86pB?%)i@Spq`!h97sJyeQ6%@fIz$d^ieH99YO1fHFi)%ep z__sLlON!mr-Q7i;pWn;Ni_c4l&)L<6A1)>)#xEeqFDS?h+saYzp&iP~$qf)q8X+bi`L~(>E#-d%{jZYG z{;Q-qX#!&jIB>#WxLHcTwG9@_(B&3OaD5v91w3bC$%c~o(w6+chQhyRk zfw|~c>_UfBH;AZjjO}iot(U}oob@?q@tT$L_%l{12h03p zx3}crR&2LIbqpY(E^XWN7a1jnycj3vAyzgPPAPqH9p6ZIlakejyv$Zy?!Uh&E!YHk*sPp5qu-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czqWc;sI(W-py_P!SJy qC_xpfAWvWbYWu(S&Aki0U{w$Q?5U#bVMh4>E94{fhZPS@U;IDz$-or= literal 0 HcmV?d00001 diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..9b6d0ff --- /dev/null +++ b/src/main.zig @@ -0,0 +1,97 @@ +const std = @import("std"); +const vaxis = @import("vaxis"); + +const log = std.log.scoped(.main); + +const Event = union(enum) { + key_press: vaxis.Key, + winsize: vaxis.Winsize, +}; + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer { + const deinit_status = gpa.deinit(); + if (deinit_status == .leak) { + log.err("memory leak", .{}); + } + } + + const allocator = gpa.allocator(); + + var tty = try vaxis.Tty.init(); + defer tty.deinit(); + + var vx = try vaxis.init(allocator, .{}); + defer vx.deinit(allocator, tty.anyWriter()); + + try vx.resetState(tty.anyWriter()); + + var loop: vaxis.Loop(Event) = .{ .tty = &tty, .vaxis = &vx }; + try loop.init(); + + try loop.start(); + defer loop.stop(); + + const stdout_file = std.io.getStdOut().writer(); + // try stdout_file.writeAll("\x1b[2J"); + // try stdout_file.writeAll("\x1b[9B"); + + // try vx.enterAltScreen(tty.anyWriter()); + try vx.queryTerminal(tty.anyWriter(), 1 * std.time.ns_per_s); + + const image = [_]vaxis.Image{ + try vx.loadImage(allocator, tty.anyWriter(), .{ .path = "/Users/kc/Sync/Images/apple-dark.png" }), + // vaxis.Image.DrawOptions{ .clip_region = .{ .x = 0, .y = 0 } }, + }; + + // defer vx.freeImage(tty.anyWriter(), image[0].id); + + const event = loop.nextEvent(); + switch (event) { + .winsize => |ws| try vx.resize(allocator, tty.anyWriter(), ws), + else => {}, + } + _ = loop.nextEvent(); + const win = vx.window(); + // win.clear(); + // vx.refresh = true; + // win.hideCursor(); + // _ = loop.nextEvent(); + + const dims = try image[0].cellSize(win); + + // try stdout_file.print("{d} - {d}\n", .{ dims.cols, dims.rows }); + + const logo_win = win.child(.{ .y_off = 0, .x_off = 0, .width = .{ .limit = dims.cols }, .height = .{ .limit = dims.rows } }); + logo_win.clear(); + const os_info = win.child(.{ .y_off = 0, .x_off = dims.cols, .width = .{ .limit = 30 }, .height = .{ .limit = 8 } }); + + const system_info = [_]vaxis.Cell.Segment{ + .{ .text = "\tOS: lalal\n" }, + .{ .text = "\tKernel: lalal\n" }, + .{ .text = "\tKernel: lalal\n" }, + .{ .text = "\tKernel: lalal\n" }, + .{ .text = "\tKernel: lalal\n" }, + .{ .text = "\tKernel: lalal\n" }, + .{ .text = "\tKernel: lalal\n" }, + .{ .text = "\tKernel: lalal\n" }, + .{ .text = "\tKernel: lalal\n" }, + .{ .text = "\tKernel: lalal\n" }, + }; + + try image[0].draw(logo_win, .{}); + _ = try os_info.print(&system_info, .{ .wrap = .word }); + try vx.render(tty.anyWriter()); + // try stdout_file.writeAll("\x1b[9B"); + try stdout_file.print("\n\n\n\n\n\n\n\n\n", .{}); + // win.showCursor(); + std.time.sleep(10000000); +} + +test "simple test" { + var list = std.ArrayList(i32).init(std.testing.allocator); + defer list.deinit(); // try commenting this out and see if zig detects the memory leak! + try list.append(42); + try std.testing.expectEqual(@as(i32, 42), list.pop()); +} diff --git a/src/root.zig b/src/root.zig new file mode 100644 index 0000000..ecfeade --- /dev/null +++ b/src/root.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +const testing = std.testing; + +export fn add(a: i32, b: i32) i32 { + return a + b; +} + +test "basic add functionality" { + try testing.expect(add(3, 7) == 10); +}