add market value of lots to CLI/TUI display
This commit is contained in:
parent
86a764dca9
commit
c5a4d68899
2 changed files with 9 additions and 3 deletions
|
|
@ -739,9 +739,12 @@ pub fn printLotRow(out: *std.Io.Writer, color: bool, lot: zfin.Lot, current_pric
|
|||
const lot_gl_money = fmt.fmtMoney(&lot_gl_buf, lot_gl_abs);
|
||||
const lot_sign: []const u8 = if (gl >= 0) "+" else "-";
|
||||
|
||||
var lot_mv_buf: [24]u8 = undefined;
|
||||
const lot_mv = fmt.fmtMoney(&lot_mv_buf, lot.shares * use_price);
|
||||
|
||||
try cli.setFg(out, color, cli.CLR_MUTED);
|
||||
try out.print(" " ++ fmt.sym_col_spec ++ " {d:>8.1} {s:>10} {s:>10} {s:>16} ", .{
|
||||
status_str, lot.shares, fmt.fmtMoney2(&lot_price_buf, lot.open_price), "", "",
|
||||
status_str, lot.shares, fmt.fmtMoney2(&lot_price_buf, lot.open_price), "", lot_mv,
|
||||
});
|
||||
try cli.reset(out, color);
|
||||
try cli.setGainLoss(out, color, gl);
|
||||
|
|
|
|||
|
|
@ -2197,8 +2197,9 @@ const App = struct {
|
|||
var date_buf: [10]u8 = undefined;
|
||||
const date_str = lot.open_date.format(&date_buf);
|
||||
|
||||
// Compute lot gain/loss if we have a price
|
||||
// Compute lot gain/loss and market value if we have a price
|
||||
var lot_gl_str: []const u8 = "";
|
||||
var lot_mv_str: []const u8 = "";
|
||||
var lot_positive = true;
|
||||
if (self.portfolio_summary) |s| {
|
||||
if (row.pos_idx < s.allocations.len) {
|
||||
|
|
@ -2211,6 +2212,8 @@ const App = struct {
|
|||
lot_gl_str = try std.fmt.allocPrint(arena, "{s}{s}", .{
|
||||
if (gl >= 0) @as([]const u8, "+") else @as([]const u8, "-"), lot_gl_money,
|
||||
});
|
||||
var lot_mv_buf: [24]u8 = undefined;
|
||||
lot_mv_str = try std.fmt.allocPrint(arena, "{s}", .{fmt.fmtMoney(&lot_mv_buf, lot.shares * use_price)});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2221,7 +2224,7 @@ const App = struct {
|
|||
const lot_date_col = try std.fmt.allocPrint(arena, "{s} {s}", .{ date_str, indicator });
|
||||
const acct_col: []const u8 = lot.account orelse "";
|
||||
const text = try std.fmt.allocPrint(arena, " " ++ fmt.sym_col_spec ++ " {d:>8.1} {s:>10} {s:>10} {s:>16} {s:>14} {s:>8} {s:>13} {s}", .{
|
||||
status_str, lot.shares, lot_price_str, "", "", lot_gl_str, "", lot_date_col, acct_col,
|
||||
status_str, lot.shares, lot_price_str, "", lot_mv_str, lot_gl_str, "", lot_date_col, acct_col,
|
||||
});
|
||||
const base_style = if (is_cursor) th.selectStyle() else th.mutedStyle();
|
||||
const gl_col_style = if (is_cursor) th.selectStyle() else if (lot_positive) th.positiveStyle() else th.negativeStyle();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue