fix watchlist loading
This commit is contained in:
parent
1f9f90357f
commit
afcc24be5e
1 changed files with 9 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const zfin = @import("../root.zig");
|
const zfin = @import("../root.zig");
|
||||||
|
const srf = @import("srf");
|
||||||
pub const fmt = @import("../format.zig");
|
pub const fmt = @import("../format.zig");
|
||||||
|
|
||||||
// ── Default CLI colors (match TUI default Monokai theme) ─────
|
// ── Default CLI colors (match TUI default Monokai theme) ─────
|
||||||
|
|
@ -319,20 +320,22 @@ pub fn buildPortfolioData(
|
||||||
|
|
||||||
// ── Watchlist loading ────────────────────────────────────────
|
// ── 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.
|
/// Returns owned symbol strings. Returns null if file missing or empty.
|
||||||
pub fn loadWatchlist(allocator: std.mem.Allocator, path: []const u8) ?[][]const u8 {
|
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;
|
const file_data = std.fs.cwd().readFileAlloc(allocator, path, 1024 * 1024) catch return null;
|
||||||
defer allocator.free(file_data);
|
defer allocator.free(file_data);
|
||||||
|
|
||||||
var portfolio = zfin.cache.deserializePortfolio(allocator, file_data) catch return null;
|
const WatchEntry = struct { symbol: []const u8 };
|
||||||
defer portfolio.deinit();
|
|
||||||
|
|
||||||
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;
|
var syms: std.ArrayList([]const u8) = .empty;
|
||||||
for (portfolio.lots) |lot| {
|
while (it.next() catch null) |fields| {
|
||||||
const duped = allocator.dupe(u8, lot.symbol) catch continue;
|
const entry = fields.to(WatchEntry) catch continue;
|
||||||
|
const duped = allocator.dupe(u8, entry.symbol) catch continue;
|
||||||
syms.append(allocator, duped) catch {
|
syms.append(allocator, duped) catch {
|
||||||
allocator.free(duped);
|
allocator.free(duped);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue