ai: remove edit feature
This commit is contained in:
parent
4a3df7a05b
commit
8124ca0e88
2 changed files with 21 additions and 100 deletions
119
src/tui.zig
119
src/tui.zig
|
|
@ -300,8 +300,6 @@ pub const App = struct {
|
|||
// ETF profile (loaded lazily on quote tab)
|
||||
etf_profile: ?zfin.EtfProfile = null,
|
||||
etf_loaded: bool = false,
|
||||
// Signal to the run loop to launch $EDITOR then restart
|
||||
wants_edit: bool = false,
|
||||
// Analysis tab state
|
||||
analysis_result: ?zfin.analysis.AnalysisResult = null,
|
||||
analysis_loaded: bool = false,
|
||||
|
|
@ -639,15 +637,6 @@ pub const App = struct {
|
|||
self.scroll_offset = 0;
|
||||
return ctx.consumeAndRedraw();
|
||||
},
|
||||
.edit => {
|
||||
if (self.portfolio_path != null or self.watchlist_path != null) {
|
||||
self.wants_edit = true;
|
||||
ctx.quit = true;
|
||||
} else {
|
||||
self.setStatus("No portfolio or watchlist file to edit");
|
||||
return ctx.consumeAndRedraw();
|
||||
}
|
||||
},
|
||||
.reload_portfolio => {
|
||||
self.reloadPortfolioFile();
|
||||
return ctx.consumeAndRedraw();
|
||||
|
|
@ -1245,38 +1234,6 @@ pub const App = struct {
|
|||
if (self.account_map) |*am| am.deinit();
|
||||
}
|
||||
|
||||
fn reloadFiles(self: *App) void {
|
||||
// Reload portfolio
|
||||
if (self.portfolio) |*pf| pf.deinit();
|
||||
self.portfolio = null;
|
||||
if (self.portfolio_path) |path| {
|
||||
const file_data = std.fs.cwd().readFileAlloc(self.allocator, path, 10 * 1024 * 1024) catch null;
|
||||
if (file_data) |d| {
|
||||
defer self.allocator.free(d);
|
||||
if (zfin.cache.deserializePortfolio(self.allocator, d)) |pf| {
|
||||
self.portfolio = pf;
|
||||
} else |_| {}
|
||||
}
|
||||
}
|
||||
|
||||
// Reload watchlist
|
||||
freeWatchlist(self.allocator, self.watchlist);
|
||||
self.watchlist = null;
|
||||
if (self.watchlist_path) |path| {
|
||||
self.watchlist = loadWatchlist(self.allocator, path);
|
||||
}
|
||||
|
||||
// Reset portfolio view state
|
||||
self.portfolio_loaded = false;
|
||||
self.freePortfolioSummary();
|
||||
self.expanded = [_]bool{false} ** 64;
|
||||
self.cursor = 0;
|
||||
self.scroll_offset = 0;
|
||||
self.portfolio_rows.clearRetainingCapacity();
|
||||
}
|
||||
|
||||
/// Reload portfolio file from disk without re-fetching prices.
|
||||
/// Uses cached candle data to recompute summary.
|
||||
fn reloadPortfolioFile(self: *App) void {
|
||||
portfolio_tab.reloadPortfolioFile(self);
|
||||
}
|
||||
|
|
@ -1517,16 +1474,16 @@ pub const App = struct {
|
|||
|
||||
const actions = comptime std.enums.values(keybinds.Action);
|
||||
const action_labels = [_][]const u8{
|
||||
"Quit", "Refresh", "Previous tab", "Next tab",
|
||||
"Tab 1", "Tab 2", "Tab 3", "Tab 4",
|
||||
"Tab 5", "Tab 6", "Scroll down", "Scroll up",
|
||||
"Scroll to top", "Scroll to bottom", "Page down", "Page up",
|
||||
"Select next", "Select prev", "Expand/collapse", "Select symbol",
|
||||
"Change symbol (search)", "This help", "Edit portfolio/watchlist", "Reload portfolio from disk",
|
||||
"Toggle all calls (options)", "Toggle all puts (options)", "Filter +/- 1 NTM", "Filter +/- 2 NTM",
|
||||
"Filter +/- 3 NTM", "Filter +/- 4 NTM", "Filter +/- 5 NTM", "Filter +/- 6 NTM",
|
||||
"Filter +/- 7 NTM", "Filter +/- 8 NTM", "Filter +/- 9 NTM", "Chart: next timeframe",
|
||||
"Chart: prev timeframe", "Sort: next column", "Sort: prev column", "Sort: reverse order",
|
||||
"Quit", "Refresh", "Previous tab", "Next tab",
|
||||
"Tab 1", "Tab 2", "Tab 3", "Tab 4",
|
||||
"Tab 5", "Tab 6", "Scroll down", "Scroll up",
|
||||
"Scroll to top", "Scroll to bottom", "Page down", "Page up",
|
||||
"Select next", "Select prev", "Expand/collapse", "Select symbol",
|
||||
"Change symbol (search)", "This help", "Reload portfolio from disk", "Toggle all calls (options)",
|
||||
"Toggle all puts (options)", "Filter +/- 1 NTM", "Filter +/- 2 NTM", "Filter +/- 3 NTM",
|
||||
"Filter +/- 4 NTM", "Filter +/- 5 NTM", "Filter +/- 6 NTM", "Filter +/- 7 NTM",
|
||||
"Filter +/- 8 NTM", "Filter +/- 9 NTM", "Chart: next timeframe", "Chart: prev timeframe",
|
||||
"Sort: next column", "Sort: prev column", "Sort: reverse order",
|
||||
};
|
||||
|
||||
for (actions, 0..) |action, ai| {
|
||||
|
|
@ -1947,56 +1904,22 @@ pub fn run(allocator: std.mem.Allocator, config: zfin.Config, args: []const []co
|
|||
defer freeWatchlist(allocator, app_inst.watchlist);
|
||||
defer app_inst.deinitData();
|
||||
|
||||
while (true) {
|
||||
{
|
||||
var vx_app = try vaxis.vxfw.App.init(allocator);
|
||||
defer vx_app.deinit();
|
||||
app_inst.vx_app = &vx_app;
|
||||
defer app_inst.vx_app = null;
|
||||
defer {
|
||||
// Free any chart image before vaxis is torn down
|
||||
if (app_inst.chart.image_id) |id| {
|
||||
vx_app.vx.freeImage(vx_app.tty.writer(), id);
|
||||
app_inst.chart.image_id = null;
|
||||
}
|
||||
{
|
||||
var vx_app = try vaxis.vxfw.App.init(allocator);
|
||||
defer vx_app.deinit();
|
||||
app_inst.vx_app = &vx_app;
|
||||
defer app_inst.vx_app = null;
|
||||
defer {
|
||||
// Free any chart image before vaxis is torn down
|
||||
if (app_inst.chart.image_id) |id| {
|
||||
vx_app.vx.freeImage(vx_app.tty.writer(), id);
|
||||
app_inst.chart.image_id = null;
|
||||
}
|
||||
try vx_app.run(app_inst.widget(), .{});
|
||||
}
|
||||
// vx_app is fully torn down here (terminal restored to cooked mode)
|
||||
|
||||
if (!app_inst.wants_edit) break;
|
||||
app_inst.wants_edit = false;
|
||||
|
||||
launchEditor(allocator, app_inst.portfolio_path, app_inst.watchlist_path);
|
||||
app_inst.reloadFiles();
|
||||
app_inst.active_tab = .portfolio;
|
||||
try vx_app.run(app_inst.widget(), .{});
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch $EDITOR on the portfolio and/or watchlist files.
|
||||
fn launchEditor(allocator: std.mem.Allocator, portfolio_path: ?[]const u8, watchlist_path: ?[]const u8) void {
|
||||
const editor = std.posix.getenv("EDITOR") orelse std.posix.getenv("VISUAL") orelse "vi";
|
||||
|
||||
var argv_buf: [4][]const u8 = undefined;
|
||||
var argc: usize = 0;
|
||||
argv_buf[argc] = editor;
|
||||
argc += 1;
|
||||
if (portfolio_path) |p| {
|
||||
argv_buf[argc] = p;
|
||||
argc += 1;
|
||||
}
|
||||
if (watchlist_path) |p| {
|
||||
argv_buf[argc] = p;
|
||||
argc += 1;
|
||||
}
|
||||
const argv = argv_buf[0..argc];
|
||||
|
||||
var child = std.process.Child.init(argv, allocator);
|
||||
|
||||
child.spawn() catch return;
|
||||
_ = child.wait() catch {};
|
||||
}
|
||||
|
||||
// ── Tests ─────────────────────────────────────────────────────────────
|
||||
|
||||
const testing = std.testing;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ pub const Action = enum {
|
|||
select_symbol,
|
||||
symbol_input,
|
||||
help,
|
||||
edit,
|
||||
reload_portfolio,
|
||||
collapse_all_calls,
|
||||
collapse_all_puts,
|
||||
|
|
@ -108,7 +107,6 @@ const default_bindings = [_]Binding{
|
|||
.{ .action = .select_symbol, .key = .{ .codepoint = 's' } },
|
||||
.{ .action = .symbol_input, .key = .{ .codepoint = '/' } },
|
||||
.{ .action = .help, .key = .{ .codepoint = '?' } },
|
||||
.{ .action = .edit, .key = .{ .codepoint = 'e' } },
|
||||
.{ .action = .reload_portfolio, .key = .{ .codepoint = 'R' } },
|
||||
.{ .action = .collapse_all_calls, .key = .{ .codepoint = 'c' } },
|
||||
.{ .action = .collapse_all_puts, .key = .{ .codepoint = 'p' } },
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue