diff --git a/hledger-ui/Hledger/UI/AccountsScreen.hs b/hledger-ui/Hledger/UI/AccountsScreen.hs index ae967b84d..6d7f98c2f 100644 --- a/hledger-ui/Hledger/UI/AccountsScreen.hs +++ b/hledger-ui/Hledger/UI/AccountsScreen.hs @@ -227,8 +227,8 @@ asHandle ui0@UIState{ ,ajournal=j ,aMode=mode } ev = do - d <- liftIO getCurrentDay let + d = copts^.rsDay nonblanks = V.takeWhile (not . T.null . asItemAccountName) $ _asList^.listElementsL lastnonblankidx = max 0 (length nonblanks - 1) diff --git a/hledger-ui/Hledger/UI/ErrorScreen.hs b/hledger-ui/Hledger/UI/ErrorScreen.hs index 5ff2dcef3..256e815ab 100644 --- a/hledger-ui/Hledger/UI/ErrorScreen.hs +++ b/hledger-ui/Hledger/UI/ErrorScreen.hs @@ -19,9 +19,9 @@ import Control.Monad.IO.Class (liftIO) import Data.Time.Calendar (Day) import Data.Void (Void) import Graphics.Vty (Event(..),Key(..),Modifier(..)) +import Lens.Micro ((^.)) import Text.Megaparsec import Text.Megaparsec.Char -import Lens.Micro ((^.)) import Hledger.Cli hiding (progname,prognameandversion) import Hledger.UI.UIOptions @@ -90,7 +90,7 @@ esHandle ui@UIState{aScreen=ErrorScreen{..} _ -> helpHandle ui ev _ -> do - d <- liftIO getCurrentDay + let d = copts^.rsDay case ev of VtyEvent (EvKey (KChar 'q') []) -> halt ui VtyEvent (EvKey KEsc []) -> continue $ uiCheckBalanceAssertions d $ resetScreens d ui diff --git a/hledger-ui/Hledger/UI/Main.hs b/hledger-ui/Hledger/UI/Main.hs index 0443a7736..0be3d81cf 100644 --- a/hledger-ui/Hledger/UI/Main.hs +++ b/hledger-ui/Hledger/UI/Main.hs @@ -18,6 +18,7 @@ import Data.List.Extra (nubSort) import Data.Maybe (fromMaybe) import qualified Data.Text as T import Graphics.Vty (mkVty) +import Lens.Micro ((^.)) import System.Directory (canonicalizePath) import System.FilePath (takeDirectory) import System.FSNotify (Event(Modified), isPollingManager, watchDir, withManager) @@ -60,9 +61,8 @@ main = do runBrickUi :: UIOpts -> Journal -> IO () runBrickUi uopts@UIOpts{uoCliOpts=copts@CliOpts{inputopts_=_iopts,reportspec_=rspec@ReportSpec{_rsReportOpts=ropts}}} j = do - d <- getCurrentDay - let + today = copts^.rsDay -- hledger-ui's query handling is currently in flux, mixing old and new approaches. -- Related: #1340, #1383, #1387. Some notes and terminology: @@ -136,7 +136,7 @@ runBrickUi uopts@UIOpts{uoCliOpts=copts@CliOpts{inputopts_=_iopts,reportspec_=rs -- Initialising the accounts screen is awkward, requiring -- another temporary UIState value.. ascr' = aScreen $ - asInit d True + asInit today True UIState{ astartupopts=uopts' ,aopts=uopts' @@ -147,7 +147,7 @@ runBrickUi uopts@UIOpts{uoCliOpts=copts@CliOpts{inputopts_=_iopts,reportspec_=rs } ui = - (sInit scr) d True $ + (sInit scr) today True $ UIState{ astartupopts=uopts' ,aopts=uopts' @@ -189,9 +189,9 @@ runBrickUi uopts@UIOpts{uoCliOpts=copts@CliOpts{inputopts_=_iopts,reportspec_=rs writeChan eventChan dc watchDate new - withAsync + withAsync -- run this small task asynchronously: - (getCurrentDay >>= watchDate) + (getCurrentDay >>= watchDate) -- until this main task terminates: $ \_async -> -- start one or more background threads reporting changes in the directories of our files diff --git a/hledger-ui/Hledger/UI/RegisterScreen.hs b/hledger-ui/Hledger/UI/RegisterScreen.hs index 452deb242..37b2de3e7 100644 --- a/hledger-ui/Hledger/UI/RegisterScreen.hs +++ b/hledger-ui/Hledger/UI/RegisterScreen.hs @@ -279,8 +279,8 @@ rsHandle ui@UIState{ ,ajournal=j ,aMode=mode } ev = do - d <- liftIO getCurrentDay let + d = copts^.rsDay journalspan = journalDateSpan False j nonblanks = V.takeWhile (not . T.null . rsItemDate) $ rsList^.listElementsL lastnonblankidx = max 0 (length nonblanks - 1) diff --git a/hledger-ui/Hledger/UI/TransactionScreen.hs b/hledger-ui/Hledger/UI/TransactionScreen.hs index f620ec629..2062ab3a6 100644 --- a/hledger-ui/Hledger/UI/TransactionScreen.hs +++ b/hledger-ui/Hledger/UI/TransactionScreen.hs @@ -147,8 +147,8 @@ tsHandle ui@UIState{aScreen=TransactionScreen{tsTransaction=(i,t), tsTransaction _ -> helpHandle ui ev _ -> do - d <- liftIO getCurrentDay let + d = copts^.rsDay (iprev,tprev) = maybe (i,t) ((i-1),) $ lookup (i-1) nts (inext,tnext) = maybe (i,t) ((i+1),) $ lookup (i+1) nts case ev of @@ -166,7 +166,6 @@ tsHandle ui@UIState{aScreen=TransactionScreen{tsTransaction=(i,t), tsTransaction p = reportPeriod ui e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> do -- plog (if e == AppEvent FileChange then "file change" else "manual reload") "" `seq` return () - d <- liftIO getCurrentDay ej <- liftIO $ journalReload copts case ej of Left err -> continue $ screenEnter d errorScreen{esError=err} ui diff --git a/hledger-web/Hledger/Web/Foundation.hs b/hledger-web/Hledger/Web/Foundation.hs index 51af3baad..262680015 100644 --- a/hledger-web/Hledger/Web/Foundation.hs +++ b/hledger-web/Hledger/Web/Foundation.hs @@ -199,7 +199,7 @@ instance Show Text.Blaze.Markup where show _ = "" getViewData :: Handler ViewData getViewData = do App{appOpts=opts@WebOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{_rsReportOpts}}}, appJournal} <- getYesod - today <- liftIO getCurrentDay + let today = _rsDay rspec -- try to read the latest journal content, keeping the old content -- if there's an error