dev!: ui: Rename fields of UIOpts for consistency.
In code, either replace the name with the new name, or use the lenses instead. watch_ -> uoWatch cliopts_ -> uoCliOpts
This commit is contained in:
parent
7f7f1a2cdf
commit
765466c392
@ -49,7 +49,7 @@ accountsScreen = AccountsScreen{
|
|||||||
|
|
||||||
asInit :: Day -> Bool -> UIState -> UIState
|
asInit :: Day -> Bool -> UIState -> UIState
|
||||||
asInit d reset ui@UIState{
|
asInit d reset ui@UIState{
|
||||||
aopts=UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}},
|
aopts=UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}},
|
||||||
ajournal=j,
|
ajournal=j,
|
||||||
aScreen=s@AccountsScreen{}
|
aScreen=s@AccountsScreen{}
|
||||||
} =
|
} =
|
||||||
@ -103,7 +103,7 @@ asInit d reset ui@UIState{
|
|||||||
asInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
asInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
||||||
|
|
||||||
asDraw :: UIState -> [Widget Name]
|
asDraw :: UIState -> [Widget Name]
|
||||||
asDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec}}
|
asDraw UIState{aopts=_uopts@UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec}}
|
||||||
,ajournal=j
|
,ajournal=j
|
||||||
,aScreen=s@AccountsScreen{}
|
,aScreen=s@AccountsScreen{}
|
||||||
,aMode=mode
|
,aMode=mode
|
||||||
@ -223,7 +223,7 @@ asDrawItem (acctwidth, balwidth) selected AccountsScreenItem{..} =
|
|||||||
asHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
|
asHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
|
||||||
asHandle ui0@UIState{
|
asHandle ui0@UIState{
|
||||||
aScreen=scr@AccountsScreen{..}
|
aScreen=scr@AccountsScreen{..}
|
||||||
,aopts=UIOpts{cliopts_=copts}
|
,aopts=UIOpts{uoCliOpts=copts}
|
||||||
,ajournal=j
|
,ajournal=j
|
||||||
,aMode=mode
|
,aMode=mode
|
||||||
} ev = do
|
} ev = do
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import Data.Void (Void)
|
|||||||
import Graphics.Vty (Event(..),Key(..),Modifier(..))
|
import Graphics.Vty (Event(..),Key(..),Modifier(..))
|
||||||
import Text.Megaparsec
|
import Text.Megaparsec
|
||||||
import Text.Megaparsec.Char
|
import Text.Megaparsec.Char
|
||||||
|
import Lens.Micro ((^.))
|
||||||
|
|
||||||
import Hledger.Cli hiding (progname,prognameandversion)
|
import Hledger.Cli hiding (progname,prognameandversion)
|
||||||
import Hledger.UI.UIOptions
|
import Hledger.UI.UIOptions
|
||||||
@ -42,7 +43,7 @@ esInit _ _ ui@UIState{aScreen=ErrorScreen{}} = ui
|
|||||||
esInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
esInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
||||||
|
|
||||||
esDraw :: UIState -> [Widget Name]
|
esDraw :: UIState -> [Widget Name]
|
||||||
esDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{}}
|
esDraw UIState{aopts=UIOpts{uoCliOpts=copts}
|
||||||
,aScreen=ErrorScreen{..}
|
,aScreen=ErrorScreen{..}
|
||||||
,aMode=mode
|
,aMode=mode
|
||||||
} =
|
} =
|
||||||
@ -75,7 +76,7 @@ esDraw _ = error "draw function called with wrong screen type, should not happen
|
|||||||
|
|
||||||
esHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
|
esHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
|
||||||
esHandle ui@UIState{aScreen=ErrorScreen{..}
|
esHandle ui@UIState{aScreen=ErrorScreen{..}
|
||||||
,aopts=UIOpts{cliopts_=copts}
|
,aopts=UIOpts{uoCliOpts=copts}
|
||||||
,ajournal=j
|
,ajournal=j
|
||||||
,aMode=mode
|
,aMode=mode
|
||||||
}
|
}
|
||||||
@ -181,8 +182,8 @@ uiReloadJournalIfChanged copts d j ui = do
|
|||||||
-- fail, enter (or update) the error screen. Or if balance assertions
|
-- fail, enter (or update) the error screen. Or if balance assertions
|
||||||
-- are disabled, do nothing.
|
-- are disabled, do nothing.
|
||||||
uiCheckBalanceAssertions :: Day -> UIState -> UIState
|
uiCheckBalanceAssertions :: Day -> UIState -> UIState
|
||||||
uiCheckBalanceAssertions d ui@UIState{aopts=UIOpts{cliopts_=copts}, ajournal=j}
|
uiCheckBalanceAssertions d ui@UIState{ajournal=j}
|
||||||
| ignore_assertions_ . balancingopts_ $ inputopts_ copts = ui
|
| ui^.ignore_assertions = ui
|
||||||
| otherwise =
|
| otherwise =
|
||||||
case journalCheckBalanceAssertions j of
|
case journalCheckBalanceAssertions j of
|
||||||
Nothing -> ui
|
Nothing -> ui
|
||||||
|
|||||||
@ -44,7 +44,7 @@ writeChan = BC.writeBChan
|
|||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
opts@UIOpts{cliopts_=copts@CliOpts{inputopts_=iopts,rawopts_=rawopts}} <- getHledgerUIOpts
|
opts@UIOpts{uoCliOpts=copts@CliOpts{inputopts_=iopts,rawopts_=rawopts}} <- getHledgerUIOpts
|
||||||
-- when (debug_ $ cliopts_ opts) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show opts)
|
-- when (debug_ $ cliopts_ opts) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show opts)
|
||||||
|
|
||||||
-- always generate forecasted periodic transactions; their visibility will be toggled by the UI.
|
-- always generate forecasted periodic transactions; their visibility will be toggled by the UI.
|
||||||
@ -59,7 +59,7 @@ main = do
|
|||||||
_ -> withJournalDo copts' (runBrickUi opts)
|
_ -> withJournalDo copts' (runBrickUi opts)
|
||||||
|
|
||||||
runBrickUi :: UIOpts -> Journal -> IO ()
|
runBrickUi :: UIOpts -> Journal -> IO ()
|
||||||
runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{inputopts_=_iopts,reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}} j = do
|
runBrickUi uopts@UIOpts{uoCliOpts=copts@CliOpts{inputopts_=_iopts,reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}} j = do
|
||||||
d <- getCurrentDay
|
d <- getCurrentDay
|
||||||
|
|
||||||
let
|
let
|
||||||
@ -102,7 +102,7 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{inputopts_=_iopts,reportspec_=rsp
|
|||||||
-- It's cleaner and less conflicting to keep the former out of the latter.
|
-- It's cleaner and less conflicting to keep the former out of the latter.
|
||||||
|
|
||||||
uopts' = uopts{
|
uopts' = uopts{
|
||||||
cliopts_=copts{
|
uoCliOpts=copts{
|
||||||
reportspec_=rspec{
|
reportspec_=rspec{
|
||||||
_rsQuery=filteredQuery $ _rsQuery rspec, -- query with depth/date parts removed
|
_rsQuery=filteredQuery $ _rsQuery rspec, -- query with depth/date parts removed
|
||||||
_rsReportOpts=ropts{
|
_rsReportOpts=ropts{
|
||||||
@ -168,7 +168,7 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{inputopts_=_iopts,reportspec_=rsp
|
|||||||
|
|
||||||
-- print (length (show ui)) >> exitSuccess -- show any debug output to this point & quit
|
-- print (length (show ui)) >> exitSuccess -- show any debug output to this point & quit
|
||||||
|
|
||||||
if not (watch_ uopts')
|
if not (uoWatch uopts')
|
||||||
then
|
then
|
||||||
void $ Brick.defaultMain brickapp ui
|
void $ Brick.defaultMain brickapp ui
|
||||||
|
|
||||||
|
|||||||
@ -56,7 +56,7 @@ rsSetAccount a forceinclusive scr@RegisterScreen{} =
|
|||||||
rsSetAccount _ _ scr = scr
|
rsSetAccount _ _ scr = scr
|
||||||
|
|
||||||
rsInit :: Day -> Bool -> UIState -> UIState
|
rsInit :: Day -> Bool -> UIState -> UIState
|
||||||
rsInit d reset ui@UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}}, ajournal=j, aScreen=s@RegisterScreen{..}} =
|
rsInit d reset ui@UIState{aopts=_uopts@UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}}, ajournal=j, aScreen=s@RegisterScreen{..}} =
|
||||||
ui{aScreen=s{rsList=newitems'}}
|
ui{aScreen=s{rsList=newitems'}}
|
||||||
where
|
where
|
||||||
-- gather arguments and queries
|
-- gather arguments and queries
|
||||||
@ -134,7 +134,7 @@ rsInit d reset ui@UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_
|
|||||||
rsInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
rsInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
||||||
|
|
||||||
rsDraw :: UIState -> [Widget Name]
|
rsDraw :: UIState -> [Widget Name]
|
||||||
rsDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec}}
|
rsDraw UIState{aopts=_uopts@UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec}}
|
||||||
,aScreen=RegisterScreen{..}
|
,aScreen=RegisterScreen{..}
|
||||||
,aMode=mode
|
,aMode=mode
|
||||||
} =
|
} =
|
||||||
@ -275,7 +275,7 @@ rsDrawItem (datewidth,descwidth,acctswidth,changewidth,balwidth) selected Regist
|
|||||||
rsHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
|
rsHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
|
||||||
rsHandle ui@UIState{
|
rsHandle ui@UIState{
|
||||||
aScreen=s@RegisterScreen{..}
|
aScreen=s@RegisterScreen{..}
|
||||||
,aopts=UIOpts{cliopts_=copts}
|
,aopts=UIOpts{uoCliOpts=copts}
|
||||||
,ajournal=j
|
,ajournal=j
|
||||||
,aMode=mode
|
,aMode=mode
|
||||||
} ev = do
|
} ev = do
|
||||||
|
|||||||
@ -41,7 +41,7 @@ transactionScreen = TransactionScreen{
|
|||||||
}
|
}
|
||||||
|
|
||||||
tsInit :: Day -> Bool -> UIState -> UIState
|
tsInit :: Day -> Bool -> UIState -> UIState
|
||||||
tsInit _d _reset ui@UIState{aopts=UIOpts{cliopts_=CliOpts{reportspec_=_rspec}}
|
tsInit _d _reset ui@UIState{aopts=UIOpts{}
|
||||||
,ajournal=_j
|
,ajournal=_j
|
||||||
,aScreen=s@TransactionScreen{tsTransaction=(_,t),tsTransactions=nts}
|
,aScreen=s@TransactionScreen{tsTransaction=(_,t),tsTransactions=nts}
|
||||||
,aPrevScreens=prevscreens
|
,aPrevScreens=prevscreens
|
||||||
@ -60,7 +60,7 @@ tsInit _d _reset ui@UIState{aopts=UIOpts{cliopts_=CliOpts{reportspec_=_rspec}}
|
|||||||
tsInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
tsInit _ _ _ = error "init function called with wrong screen type, should not happen" -- PARTIAL:
|
||||||
|
|
||||||
tsDraw :: UIState -> [Widget Name]
|
tsDraw :: UIState -> [Widget Name]
|
||||||
tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}}
|
tsDraw UIState{aopts=UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}}
|
||||||
,ajournal=j
|
,ajournal=j
|
||||||
,aScreen=TransactionScreen{tsTransaction=(i,t')
|
,aScreen=TransactionScreen{tsTransaction=(i,t')
|
||||||
,tsTransactions=nts
|
,tsTransactions=nts
|
||||||
@ -133,7 +133,7 @@ tsDraw _ = error "draw function called with wrong screen type, should not happen
|
|||||||
|
|
||||||
tsHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
|
tsHandle :: UIState -> BrickEvent Name AppEvent -> EventM Name (Next UIState)
|
||||||
tsHandle ui@UIState{aScreen=TransactionScreen{tsTransaction=(i,t), tsTransactions=nts}
|
tsHandle ui@UIState{aScreen=TransactionScreen{tsTransaction=(i,t), tsTransactions=nts}
|
||||||
,aopts=UIOpts{cliopts_=copts}
|
,aopts=UIOpts{uoCliOpts=copts}
|
||||||
,ajournal=j
|
,ajournal=j
|
||||||
,aMode=mode
|
,aMode=mode
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,17 +66,17 @@ 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
|
{ uoWatch :: Bool
|
||||||
, uoTheme :: Maybe String
|
, uoTheme :: Maybe String
|
||||||
, uoRegister :: Maybe String
|
, uoRegister :: Maybe String
|
||||||
, cliopts_ :: CliOpts
|
, uoCliOpts :: CliOpts
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
defuiopts = UIOpts
|
defuiopts = UIOpts
|
||||||
{ watch_ = False
|
{ uoWatch = False
|
||||||
, uoTheme = Nothing
|
, uoTheme = Nothing
|
||||||
, uoRegister = Nothing
|
, uoRegister = Nothing
|
||||||
, cliopts_ = defcliopts
|
, uoCliOpts = defcliopts
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Process a RawOpts into a UIOpts.
|
-- | Process a RawOpts into a UIOpts.
|
||||||
@ -85,10 +85,10 @@ rawOptsToUIOpts :: RawOpts -> IO UIOpts
|
|||||||
rawOptsToUIOpts rawopts = do
|
rawOptsToUIOpts rawopts = do
|
||||||
cliopts <- set balanceaccum accum <$> rawOptsToCliOpts rawopts
|
cliopts <- set balanceaccum accum <$> rawOptsToCliOpts rawopts
|
||||||
return defuiopts {
|
return defuiopts {
|
||||||
watch_ = boolopt "watch" rawopts
|
uoWatch = boolopt "watch" rawopts
|
||||||
,uoTheme = checkTheme <$> maybestringopt "theme" rawopts
|
,uoTheme = checkTheme <$> maybestringopt "theme" rawopts
|
||||||
,uoRegister = maybestringopt "register" rawopts
|
,uoRegister = maybestringopt "register" rawopts
|
||||||
,cliopts_ = cliopts
|
,uoCliOpts = cliopts
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
-- show historical balance by default (unlike hledger)
|
-- show historical balance by default (unlike hledger)
|
||||||
@ -105,7 +105,7 @@ getHledgerUIOpts = do
|
|||||||
rawOptsToUIOpts cmdargopts
|
rawOptsToUIOpts cmdargopts
|
||||||
|
|
||||||
instance HasCliOpts UIOpts where
|
instance HasCliOpts UIOpts where
|
||||||
cliOpts f uiopts = (\x -> uiopts{cliopts_=x}) <$> f (cliopts_ uiopts)
|
cliOpts f uiopts = (\x -> uiopts{uoCliOpts=x}) <$> f (uoCliOpts uiopts)
|
||||||
|
|
||||||
instance HasInputOpts UIOpts where
|
instance HasInputOpts UIOpts where
|
||||||
inputOpts = cliOpts.inputOpts
|
inputOpts = cliOpts.inputOpts
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user