further cleanup

This commit is contained in:
RadsammyT 2026-03-17 16:08:06 -04:00
commit 037f3020a6
No known key found for this signature in database
3 changed files with 20 additions and 11 deletions

View file

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

View file

@ -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);

View file

@ -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,