ref: ui: Refactor code to eliminate requirement for change_ in UIOpts.

--change is already stored in balanceaccum_ in ReportOpts, so it does
not need to be stored in UIOpts too.
This commit is contained in:
Stephen Morgan 2021-08-08 23:01:07 +10:00 committed by Simon Michael
parent 50f73b7434
commit 54c73ff759
2 changed files with 8 additions and 10 deletions

View File

@ -29,7 +29,6 @@ import Hledger
import Hledger.Cli hiding (progname,prognameandversion) import Hledger.Cli hiding (progname,prognameandversion)
import Hledger.UI.UIOptions import Hledger.UI.UIOptions
import Hledger.UI.UITypes import Hledger.UI.UITypes
import Hledger.UI.UIState (toggleHistorical)
import Hledger.UI.Theme import Hledger.UI.Theme
import Hledger.UI.AccountsScreen import Hledger.UI.AccountsScreen
import Hledger.UI.RegisterScreen import Hledger.UI.RegisterScreen
@ -110,8 +109,7 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{inputopts_=_iopts,reportspec_=rsp
depth_ =queryDepth $ _rsQuery rspec, -- query's depth part depth_ =queryDepth $ _rsQuery rspec, -- query's depth part
period_=periodfromoptsandargs, -- query's date part period_=periodfromoptsandargs, -- query's date part
no_elide_=True, -- avoid squashing boring account names, for a more regular tree (unlike hledger) no_elide_=True, -- avoid squashing boring account names, for a more regular tree (unlike hledger)
empty_=not $ empty_ ropts, -- show zero items by default, hide them with -E (unlike hledger) empty_=not $ empty_ ropts -- show zero items by default, hide them with -E (unlike hledger)
balanceaccum_=Historical -- show historical balances by default (unlike hledger)
} }
} }
} }
@ -155,7 +153,6 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{inputopts_=_iopts,reportspec_=rsp
ui = ui =
(sInit scr) d True $ (sInit scr) d True $
(if change_ uopts' then toggleHistorical else id) -- XXX
UIState{ UIState{
astartupopts=uopts' astartupopts=uopts'
,aopts=uopts' ,aopts=uopts'

View File

@ -6,9 +6,11 @@
module Hledger.UI.UIOptions module Hledger.UI.UIOptions
where where
import Data.Default import Data.Default (def)
import Data.List (intercalate) import Data.List (intercalate)
import System.Environment import Data.Maybe (fromMaybe)
import Lens.Micro (set)
import System.Environment (getArgs)
import Hledger.Cli hiding (packageversion, progname, prognameandversion) import Hledger.Cli hiding (packageversion, progname, prognameandversion)
import Hledger.UI.Theme (themeNames) import Hledger.UI.Theme (themeNames)
@ -64,13 +66,11 @@ uimode = (mode "hledger-ui" (setopt "command" "ui" def)
-- hledger-ui options, used in hledger-ui and above -- hledger-ui options, used in hledger-ui and above
data UIOpts = UIOpts { data UIOpts = UIOpts {
watch_ :: Bool watch_ :: Bool
,change_ :: Bool
,cliopts_ :: CliOpts ,cliopts_ :: CliOpts
} deriving (Show) } deriving (Show)
defuiopts = UIOpts defuiopts = UIOpts
{ watch_ = False { watch_ = False
, change_ = False
, cliopts_ = def , cliopts_ = def
} }
@ -78,10 +78,11 @@ defuiopts = UIOpts
rawOptsToUIOpts :: RawOpts -> IO UIOpts rawOptsToUIOpts :: RawOpts -> IO UIOpts
rawOptsToUIOpts rawopts = checkUIOpts <$> do rawOptsToUIOpts rawopts = checkUIOpts <$> do
cliopts <- rawOptsToCliOpts rawopts -- show historical balance by default (unlike hledger)
let accum = fromMaybe Historical $ balanceAccumulationOverride rawopts
cliopts <- set balanceaccum accum <$> rawOptsToCliOpts rawopts
return defuiopts { return defuiopts {
watch_ = boolopt "watch" rawopts watch_ = boolopt "watch" rawopts
,change_ = boolopt "change" rawopts
,cliopts_ = cliopts ,cliopts_ = cliopts
} }