feat(console+core): tui, core

This commit is contained in:
2025-04-24 14:49:18 +02:00
parent 8a39c36aa8
commit 693167bd1d
9 changed files with 305 additions and 188 deletions

View File

@@ -9,7 +9,8 @@ const Item = models.Item;
pub const Tab = struct {
allocator: std.mem.Allocator,
currentLocation: ?*Container,
currentItems: ?std.ArrayList(Item),
currentItems: ?std.ArrayList(*Item),
currentItemsChanged: bool = false,
threadPool: *std.Thread.Pool,
_private: Private,
@@ -41,17 +42,46 @@ pub const Tab = struct {
self.currentLocation = newLocation;
//TODO: Proper error handling
std.Thread.Pool.spawn(self.threadPool, loadItems, .{ self, newLocation }) catch unreachable;
std.Thread.Pool.spawn(self.threadPool, loadItemsWrapper, .{ self, newLocation }) catch unreachable;
}
fn loadItems(self: *Tab, location: *Container) void {
fn loadItemsWrapper(self: *Tab, location: *Container) void {
loadItems(self, location) catch return;
}
fn loadItems(self: *Tab, location: *Container) !void {
if (self._private.currentItemsAllocator) |arena| {
arena.deinit();
}
if (self.currentItems) |items| {
items.deinit();
}
self._private.currentItemsAllocator = std.heap.ArenaAllocator.init(self.allocator);
const arenaAllocator = &self._private.currentItemsAllocator.?;
const arena = arenaAllocator.allocator();
var threadSafeAllocator = std.heap.ThreadSafeAllocator{.child_allocator = arena};
const allocator = threadSafeAllocator.allocator();
errdefer {
arenaAllocator.deinit();
self._private.currentItemsAllocator = null;
}
self.currentItems = std.ArrayList(*Item).init(allocator);
errdefer {
self.currentItems.?.deinit();
self.currentItems = null;
}
while (location.childrenLoading) {
std.Thread.sleep(1 * std.time.ns_per_ms);
}
for (location.children.items) |item| {
_ = item;
const resolvedItem = try location.item.provider.getItemByFullName(item, &.{ .skipChildInit = false }, allocator);
try self.currentItems.?.append(resolvedItem);
self.currentItemsChanged = true;
}
}
@@ -62,6 +92,5 @@ pub const Tab = struct {
if (self._private.currentItemsAllocator) |arena| {
arena.deinit();
}
self.allocator.destroy(self);
}
};