From afcc24be5e4821a9317e3d561f4b73dac60aa062 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Tue, 31 Mar 2026 17:11:03 -0700 Subject: [PATCH] fix watchlist loading --- src/commands/common.zig | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/commands/common.zig b/src/commands/common.zig index 953c340..b06cf5c 100644 --- a/src/commands/common.zig +++ b/src/commands/common.zig @@ -1,5 +1,6 @@ const std = @import("std"); const zfin = @import("../root.zig"); +const srf = @import("srf"); pub const fmt = @import("../format.zig"); // ── Default CLI colors (match TUI default Monokai theme) ───── @@ -319,20 +320,22 @@ pub fn buildPortfolioData( // ── Watchlist loading ──────────────────────────────────────── -/// Load a watchlist file using the library's SRF deserializer. +/// Load a watchlist SRF file containing symbol records. /// Returns owned symbol strings. Returns null if file missing or empty. pub fn loadWatchlist(allocator: std.mem.Allocator, path: []const u8) ?[][]const u8 { const file_data = std.fs.cwd().readFileAlloc(allocator, path, 1024 * 1024) catch return null; defer allocator.free(file_data); - var portfolio = zfin.cache.deserializePortfolio(allocator, file_data) catch return null; - defer portfolio.deinit(); + const WatchEntry = struct { symbol: []const u8 }; - if (portfolio.lots.len == 0) return null; + var reader = std.Io.Reader.fixed(file_data); + var it = srf.iterator(&reader, allocator, .{ .alloc_strings = false }) catch return null; + defer it.deinit(); var syms: std.ArrayList([]const u8) = .empty; - for (portfolio.lots) |lot| { - const duped = allocator.dupe(u8, lot.symbol) catch continue; + while (it.next() catch null) |fields| { + const entry = fields.to(WatchEntry) catch continue; + const duped = allocator.dupe(u8, entry.symbol) catch continue; syms.append(allocator, duped) catch { allocator.free(duped); continue;