diff --git a/src/config/custom.zig b/src/config/custom.zig index d8c5992..1da9a9f 100644 --- a/src/config/custom.zig +++ b/src/config/custom.zig @@ -14,7 +14,7 @@ pub const UNDEFINED_CMD: []const u8 = "echo \"You forgot to define 'cmd'!\""; pub const customCommandInfo = struct { name: []const u8 = "", cmd: []const u8 = UNDEFINED_CMD, - /// SET TO LABELS LID!!! + /// To be set to the label widget's `lid` id: u64 = 0, /// In frames, the refresh rate for the `cmd` to run again diff --git a/src/main.zig b/src/main.zig index 5e7b543..e2824da 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1080,10 +1080,10 @@ pub fn main() !void { var iter = CustomCommands.binds.iterator(); while (iter.next()) |i| { const concat = try std.mem.concat(state.allocator, u8, - &[_][]u8{ - @constCast(i.key_ptr.*), - @constCast(" "), - @constCast(i.value_ptr.name) + &[_][]const u8{ + i.key_ptr.*, + " ", + i.value_ptr.name } ); try state.custom_binds.append(state.allocator, .{ @@ -1731,22 +1731,30 @@ fn updateCustomInfo(lbl: *Label, ptr: *anyopaque) !void { c.stderr_behavior = .Pipe; c.stdout_behavior = .Pipe; try c.spawn(); + + c.collectOutput(state.allocator, &stdout, &stderr, state.buffer.width) catch { - try stdout.print(state.allocator, "{s}: [Output too long!]", .{i.info.name}); + try stdout.print(state.allocator, "{s}: [Output too long]", .{i.info.name}); }; - if (stdout.items.len > state.buffer.width) { - stdout.clearRetainingCapacity(); - try stdout.print(state.allocator, "{s}: [Output too long!]", .{i.info.name}); - } + const newlineIdx = std.mem.indexOfAny(u8, stdout.items, "\n"); if (newlineIdx) |idx| { stdout.shrinkAndFree(state.allocator, idx); } + + if (stdout.items.len > state.buffer.width) { + stdout.clearRetainingCapacity(); + try stdout.print(state.allocator, "{s}: [Output too long]", .{i.info.name}); + } + _ = try c.wait(); if (stdout.items.len != 0 and !std.ascii.isPrint(stdout.items[stdout.items.len-1])) _ = stdout.pop() else if (stdout.items.len == 0) - try stdout.print(state.allocator, "{s}: [Command didn't print anything!]", .{i.info.name}); + try stdout.print(state.allocator, "{s}: [No output{s}]", .{ + i.info.name, + if (stderr.items.len > 0) ". Check command" else "" + }); state.allocator.free(lbl.text); lbl.text = try state.allocator.dupe(u8, stdout.items); diff --git a/src/tui/components/Label.zig b/src/tui/components/Label.zig index faf9f4e..53aa720 100644 --- a/src/tui/components/Label.zig +++ b/src/tui/components/Label.zig @@ -9,6 +9,7 @@ const TerminalBuffer = @import("../TerminalBuffer.zig"); const Widget = @import("../Widget.zig"); lid: u64, // HACK: we need to differenciate between labels in `updateCustomInfo`. + // The underlying widget ID doesn't have the properties needed. allocator: ?Allocator, text: []const u8, max_width: ?usize,