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.
This commit is contained in:
Simon Michael 2023-09-12 08:36:33 +01:00
parent 936e1b9d0a
commit 7582460e50
3 changed files with 44 additions and 20 deletions

View File

@ -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

View File

@ -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.

View File

@ -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