From 7582460e50cc6823b26e285e7a8ebd87d0ed1f5f Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 12 Sep 2023 08:36:33 +0100 Subject: [PATCH] fix:ui: V key preserves startup valuation, if any (fix #2084) Also: hledger-ui cost/value doc improvement and a useful cost/value test file. --- hledger-ui/Hledger/UI/UIState.hs | 16 ++++++++++------ hledger-ui/hledger-ui.m4.md | 28 ++++++++++++++-------------- hledger-ui/test/value.journal | 20 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 hledger-ui/test/value.journal diff --git a/hledger-ui/Hledger/UI/UIState.hs b/hledger-ui/Hledger/UI/UIState.hs index 5ddc8e94a..106c0ace9 100644 --- a/hledger-ui/Hledger/UI/UIState.hs +++ b/hledger-ui/Hledger/UI/UIState.hs @@ -58,7 +58,7 @@ import Safe import Hledger import Hledger.Cli.CliOptions import Hledger.UI.UITypes -import Hledger.UI.UIOptions (UIOpts) +import Hledger.UI.UIOptions (UIOpts(uoCliOpts)) import Hledger.UI.UIScreens (screenUpdate) -- | Make an initial UI state with the given options, journal, @@ -155,13 +155,17 @@ toggleConversionOp = over conversionop toggleCostMode toggleCostMode (Just NoConversionOp) = Just ToCost toggleCostMode (Just ToCost) = Just NoConversionOp --- | Toggle between showing primary amounts or default valuation. +-- | Toggle between showing primary amounts or values (using valuation specified at startup, or a default). toggleValue :: UIState -> UIState -toggleValue = over value valuationToggleValue +toggleValue ui = over value (valuationToggleValue mstartupvaluation0) ui where - -- | Basic toggling of -V, for hledger-ui. - valuationToggleValue (Just (AtEnd _)) = Nothing - valuationToggleValue _ = Just $ AtEnd Nothing + mstartupvaluation0 = value_ $ _rsReportOpts $ reportspec_ $ uoCliOpts $ astartupopts ui + mdefvaluation = Just (AtEnd Nothing) + -- valuationToggleValue (maybe startupvaluation) (maybe currentvaluation) = ... + valuationToggleValue Nothing Nothing = mdefvaluation + valuationToggleValue Nothing (Just _) = Nothing + valuationToggleValue mstartupvaluation Nothing = mstartupvaluation + valuationToggleValue _ (Just _) = Nothing -- | Set hierarchic account tree mode. setTree :: UIState -> UIState diff --git a/hledger-ui/hledger-ui.m4.md b/hledger-ui/hledger-ui.m4.md index b08921b47..72c15f44a 100644 --- a/hledger-ui/hledger-ui.m4.md +++ b/hledger-ui/hledger-ui.m4.md @@ -190,23 +190,23 @@ With some editors (emacs, vi), the cursor will be positioned at the current tran when invoked from the register and transaction screens, and at the error location (if possible) when invoked from the error screen. -`B` toggles cost mode, showing amounts in their cost's commodity -(like toggling the [`-B/--cost`](https://hledger.org/hledger.html#b-cost) flag). +`B` toggles cost mode, showing amounts converted to their cost's commodity +(see [hledger manual > Cost reporting](hledger.md#cost-reporting). -`V` toggles value mode, showing amounts' current market value in their -default valuation commodity (like toggling the -[`-V/--market`](https://hledger.org/hledger.html#v-market-value) flag). -Note, "current market value" means the value on the report end date if specified, otherwise today. -To see the value on another date, you can temporarily set that as the report end date. -Eg: to see a transaction as it was valued on july 30, -go to the accounts or register screen, -press `/`, -and add ` date:-7/30` to the query. +`V` toggles value mode, showing amounts converted to their market value +(see [hledger manual > Valuation](hledger.md#valuation) flag). +More specifically, -At most one of cost or value mode can be active at once. +1. By default, the `V` key toggles showing end value (`--value=end`) on or off. + The valuation date will be the report end date if specified, otherwise today. -There's not yet any visual reminder when cost or value mode is active; -for now pressing `b` `b` `v` should reliably reset to normal mode. +2. If you started hledger-ui with some other valuation (such as `--value=then,EUR`), + the `V` key toggles that off or on. + +Cost/value tips: +- When showing end value, you can change the report end date without restarting, by pressing `/` and adding a query like ` date:..YYYY-MM-DD`. +- Either cost mode, or value mode, can be active, but not both at once. Cost mode takes precedence. +- There's not yet any visual indicator that cost or value mode is active, other than the amount values. `q` quits the application. diff --git a/hledger-ui/test/value.journal b/hledger-ui/test/value.journal new file mode 100644 index 000000000..b10134611 --- /dev/null +++ b/hledger-ui/test/value.journal @@ -0,0 +1,20 @@ +P 2023-01-01 NORMAL VALUE 1 +P 2023-01-02 NORMAL VALUE 10 +P 2023-01-03 NORMAL VALUE 100 +P 2023-01-04 NORMAL VALUE 1000 +P 2023-09-01 NORMAL VALUE 10000 +P 9999-01-01 NORMAL VALUE 100000 + +2023-01-01 + (a) NORMAL 1 @ COST 2 + +2023-01-02 + (a) NORMAL 1 @ COST 2 + +2023-01-03 + (a) NORMAL 1 @ COST 2 + +2023-01-04 + (a) NORMAL 1 @ COST 2 + +# hledger-ui --register a