From 9c6bae6963d63327db1a33020483d24f2ed7b740 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 17 Jul 2024 11:14:41 +0200 Subject: [PATCH] add tui --- build.zig | 22 ++++++++++++++++++---- flake.nix | 4 +++- justfile | 8 +++++--- src/{ => gui}/main.zig | 0 src/tui/main.zig | 11 +++++++++++ 5 files changed, 37 insertions(+), 8 deletions(-) rename src/{ => gui}/main.zig (100%) create mode 100644 src/tui/main.zig diff --git a/build.zig b/build.zig index bc7da3d..8869bef 100644 --- a/build.zig +++ b/build.zig @@ -30,19 +30,21 @@ pub fn build(b: *Build) !void { } else { try buildNative(b, target, optimize, dep_sokol, dep_cimgui); } + + try buildTui(b, target, optimize); } fn buildNative(b: *Build, target: ResolvedTarget, optimize: OptimizeMode, dep_sokol: *Dependency, dep_cimgui: *Dependency) !void { const demo = b.addExecutable(.{ .name = "demo", - .root_source_file = b.path("src/main.zig"), + .root_source_file = b.path("src/gui/main.zig"), .target = target, .optimize = optimize, }); demo.root_module.addImport("sokol", dep_sokol.module("sokol")); demo.root_module.addImport("cimgui", dep_cimgui.module("cimgui")); b.installArtifact(demo); - b.step("run", "Run demo").dependOn(&b.addRunArtifact(demo).step); + b.step("run-gui", "Run demo").dependOn(&b.addRunArtifact(demo).step); } fn buildWasm(b: *Build, target: ResolvedTarget, optimize: OptimizeMode, dep_sokol: *Dependency, dep_cimgui: *Dependency) !void { @@ -50,7 +52,7 @@ fn buildWasm(b: *Build, target: ResolvedTarget, optimize: OptimizeMode, dep_soko // needs to be linked in a separate build step with the Emscripten linker const demo = b.addStaticLibrary(.{ .name = "demo", - .root_source_file = b.path("src/main.zig"), + .root_source_file = b.path("src/gui/main.zig"), .target = target, .optimize = optimize, }); @@ -86,5 +88,17 @@ fn buildWasm(b: *Build, target: ResolvedTarget, optimize: OptimizeMode, dep_soko // ...and a special run step to start the web build output via 'emrun' const run = sokol.emRunStep(b, .{ .name = "demo", .emsdk = dep_emsdk }); run.step.dependOn(&link_step.step); - b.step("run", "Run demo").dependOn(&run.step); + b.step("run-gui", "Run demo").dependOn(&run.step); +} + +fn buildTui(b: *Build, target: ResolvedTarget, optimize: OptimizeMode) !void { + const tui = b.addExecutable(.{ + .name = "demo", + .root_source_file = b.path("src/tui/main.zig"), + .target = target, + .optimize = optimize, + }); + + b.installArtifact(tui); + b.step("run-tui", "Run TUI").dependOn(&b.addRunArtifact(tui).step); } diff --git a/flake.nix b/flake.nix index dae3e4a..ba09ebe 100644 --- a/flake.nix +++ b/flake.nix @@ -12,8 +12,10 @@ zls ]; buildInputs = [ - alsa-lib lldb + + # GUI + alsa-lib xorg.libX11 xorg.libXcursor xorg.libXi diff --git a/justfile b/justfile index 112626b..6e63522 100644 --- a/justfile +++ b/justfile @@ -2,6 +2,8 @@ alias b := build build: zig build -alias r := run -run: - zig build run +gui: + zig build run-gui + +tui: + zig build run-tui diff --git a/src/main.zig b/src/gui/main.zig similarity index 100% rename from src/main.zig rename to src/gui/main.zig diff --git a/src/tui/main.zig b/src/tui/main.zig new file mode 100644 index 0000000..a0aa24c --- /dev/null +++ b/src/tui/main.zig @@ -0,0 +1,11 @@ +const std = @import("std"); + +pub fn main() !void { + const stdout = std.io.getStdOut().writer(); + try stdout.print("Can spawn process: {}\n", .{std.process.can_spawn}); + + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + const alloc = gpa.allocator(); + var lldb_child = std.process.Child.init(&[_][]const u8{"lldb-vscode"}, alloc); + _ = try lldb_child.spawnAndWait(); +}