ui: --watch date tracking fixes
- move the period only if it's "current" (contains the old "today" date) - make it work on all screens, not just accounts
This commit is contained in:
parent
e3a7f6697e
commit
9952f93e97
@ -34,6 +34,7 @@ module Hledger.Data.Dates (
|
|||||||
getCurrentYear,
|
getCurrentYear,
|
||||||
nulldate,
|
nulldate,
|
||||||
spanContainsDate,
|
spanContainsDate,
|
||||||
|
periodContainsDate,
|
||||||
parsedateM,
|
parsedateM,
|
||||||
parsedate,
|
parsedate,
|
||||||
showDate,
|
showDate,
|
||||||
@ -212,6 +213,11 @@ spanContainsDate (DateSpan Nothing (Just e)) d = d < e
|
|||||||
spanContainsDate (DateSpan (Just b) Nothing) d = d >= b
|
spanContainsDate (DateSpan (Just b) Nothing) d = d >= b
|
||||||
spanContainsDate (DateSpan (Just b) (Just e)) d = d >= b && d < e
|
spanContainsDate (DateSpan (Just b) (Just e)) d = d >= b && d < e
|
||||||
|
|
||||||
|
-- | Does the period include the given date ?
|
||||||
|
-- (Here to avoid import cycle).
|
||||||
|
periodContainsDate :: Period -> Day -> Bool
|
||||||
|
periodContainsDate p = spanContainsDate (periodAsDateSpan p)
|
||||||
|
|
||||||
-- | Calculate the intersection of a number of datespans.
|
-- | Calculate the intersection of a number of datespans.
|
||||||
spansIntersect [] = nulldatespan
|
spansIntersect [] = nulldatespan
|
||||||
spansIntersect [d] = d
|
spansIntersect [d] = d
|
||||||
|
|||||||
@ -289,9 +289,10 @@ asHandle ui0@UIState{
|
|||||||
-- EvKey (KChar 'l') [MCtrl] -> do
|
-- EvKey (KChar 'l') [MCtrl] -> do
|
||||||
VtyEvent (EvKey KEsc []) -> continue $ resetScreens d ui
|
VtyEvent (EvKey KEsc []) -> continue $ resetScreens d ui
|
||||||
VtyEvent (EvKey (KChar c) []) | c `elem` ['?'] -> continue $ setMode Help ui
|
VtyEvent (EvKey (KChar c) []) | c `elem` ['?'] -> continue $ setMode Help ui
|
||||||
-- XXX handles FileChange/DateChange events only in Normal mode ?
|
-- XXX AppEvents currently handled only in Normal mode
|
||||||
-- XXX be sure we don't leave unconsumed events piling up
|
-- XXX be sure we don't leave unconsumed events piling up
|
||||||
AppEvent DateChange -> continue $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui
|
AppEvent (DateChange old _) | periodContainsDate (reportPeriod ui) old ->
|
||||||
|
continue $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui
|
||||||
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] ->
|
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] ->
|
||||||
liftIO (uiReloadJournal copts d ui) >>= continue
|
liftIO (uiReloadJournal copts d ui) >>= continue
|
||||||
VtyEvent (EvKey (KChar 'I') []) -> continue $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui)
|
VtyEvent (EvKey (KChar 'I') []) -> continue $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui)
|
||||||
|
|||||||
@ -92,7 +92,6 @@ esHandle ui@UIState{
|
|||||||
(pos,f) = case parsewithString hledgerparseerrorpositionp esError of
|
(pos,f) = case parsewithString hledgerparseerrorpositionp esError of
|
||||||
Right (f,l,c) -> (Just (l, Just c),f)
|
Right (f,l,c) -> (Just (l, Just c),f)
|
||||||
Left _ -> (endPos, journalFilePath j)
|
Left _ -> (endPos, journalFilePath j)
|
||||||
-- AppEvent DateChange -> continue $ regenerateScreens j d ui
|
|
||||||
e | e `elem` [VtyEvent (EvKey (KChar 'g') [])] ->
|
e | e `elem` [VtyEvent (EvKey (KChar 'g') [])] ->
|
||||||
liftIO (uiReloadJournal copts d (popScreen ui)) >>= continue . uiCheckBalanceAssertions d
|
liftIO (uiReloadJournal copts d (popScreen ui)) >>= continue . uiCheckBalanceAssertions d
|
||||||
-- (ej, _) <- liftIO $ journalReloadIfChanged copts d j
|
-- (ej, _) <- liftIO $ journalReloadIfChanged copts d j
|
||||||
|
|||||||
@ -161,13 +161,14 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}} j = do
|
|||||||
-- start a background thread reporting changes in the current date
|
-- start a background thread reporting changes in the current date
|
||||||
-- use async for proper child termination in GHCI
|
-- use async for proper child termination in GHCI
|
||||||
let
|
let
|
||||||
watchDate lastd = do
|
watchDate old = do
|
||||||
threadDelay 1000000 -- 1s
|
threadDelay 1000000 -- 1s
|
||||||
d <- getCurrentDay
|
new <- getCurrentDay
|
||||||
when (d /= lastd) $ do
|
when (new /= old) $ do
|
||||||
-- dbg1IO "datechange" DateChange -- XXX don't uncomment until dbg*IO fixed to use traceIO, GHC may block/end thread
|
let dc = DateChange old new
|
||||||
writeChan eventChan DateChange
|
-- dbg1IO "datechange" dc -- XXX don't uncomment until dbg*IO fixed to use traceIO, GHC may block/end thread
|
||||||
watchDate d
|
writeChan eventChan dc
|
||||||
|
watchDate new
|
||||||
|
|
||||||
withAsync
|
withAsync
|
||||||
(getCurrentDay >>= watchDate)
|
(getCurrentDay >>= watchDate)
|
||||||
|
|||||||
@ -267,7 +267,8 @@ rsHandle ui@UIState{
|
|||||||
VtyEvent (EvKey (KChar 'q') []) -> halt ui
|
VtyEvent (EvKey (KChar 'q') []) -> halt ui
|
||||||
VtyEvent (EvKey KEsc []) -> continue $ resetScreens d ui
|
VtyEvent (EvKey KEsc []) -> continue $ resetScreens d ui
|
||||||
VtyEvent (EvKey (KChar c) []) | c `elem` ['?'] -> continue $ setMode Help ui
|
VtyEvent (EvKey (KChar c) []) | c `elem` ['?'] -> continue $ setMode Help ui
|
||||||
AppEvent DateChange -> continue $ regenerateScreens j d ui
|
AppEvent (DateChange old _) | periodContainsDate (reportPeriod ui) old ->
|
||||||
|
continue $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui
|
||||||
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] ->
|
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] ->
|
||||||
liftIO (uiReloadJournal copts d ui) >>= continue
|
liftIO (uiReloadJournal copts d ui) >>= continue
|
||||||
VtyEvent (EvKey (KChar 'I') []) -> continue $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui)
|
VtyEvent (EvKey (KChar 'I') []) -> continue $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui)
|
||||||
|
|||||||
@ -129,7 +129,8 @@ tsHandle ui@UIState{aScreen=s@TransactionScreen{tsTransaction=(i,t)
|
|||||||
VtyEvent (EvKey (KChar 'E') []) -> suspendAndResume $ void (runEditor pos f) >> uiReloadJournalIfChanged copts d j ui
|
VtyEvent (EvKey (KChar 'E') []) -> suspendAndResume $ void (runEditor pos f) >> uiReloadJournalIfChanged copts d j ui
|
||||||
where
|
where
|
||||||
(pos,f) = let GenericSourcePos f l c = tsourcepos t in (Just (l, Just c),f)
|
(pos,f) = let GenericSourcePos f l c = tsourcepos t in (Just (l, Just c),f)
|
||||||
AppEvent DateChange -> continue $ regenerateScreens j d ui
|
AppEvent (DateChange old _) | periodContainsDate (reportPeriod ui) old ->
|
||||||
|
continue $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui
|
||||||
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> do
|
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> do
|
||||||
d <- liftIO getCurrentDay
|
d <- liftIO getCurrentDay
|
||||||
ej <- liftIO $ journalReload copts
|
ej <- liftIO $ journalReload copts
|
||||||
|
|||||||
@ -104,6 +104,11 @@ moveReportPeriodToDate :: Day -> UIState -> UIState
|
|||||||
moveReportPeriodToDate d ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts@ReportOpts{period_=p}}}} =
|
moveReportPeriodToDate d ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts@ReportOpts{period_=p}}}} =
|
||||||
ui{aopts=uopts{cliopts_=copts{reportopts_=ropts{period_=periodMoveTo d p}}}}
|
ui{aopts=uopts{cliopts_=copts{reportopts_=ropts{period_=periodMoveTo d p}}}}
|
||||||
|
|
||||||
|
-- | Get the report period.
|
||||||
|
reportPeriod :: UIState -> Period
|
||||||
|
reportPeriod UIState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ReportOpts{period_=p}}}} =
|
||||||
|
p
|
||||||
|
|
||||||
-- | Set the report period.
|
-- | Set the report period.
|
||||||
setReportPeriod :: Period -> UIState -> UIState
|
setReportPeriod :: Period -> UIState -> UIState
|
||||||
setReportPeriod p ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}} =
|
setReportPeriod p ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}} =
|
||||||
|
|||||||
@ -83,8 +83,8 @@ data Name =
|
|||||||
deriving (Ord, Show, Eq)
|
deriving (Ord, Show, Eq)
|
||||||
|
|
||||||
data AppEvent =
|
data AppEvent =
|
||||||
FileChange
|
FileChange -- one of the Journal's files has been added/modified/removed
|
||||||
| DateChange
|
| DateChange Day Day -- the current date has changed since last checked (with the old and new values)
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
-- | hledger-ui screen types & instances.
|
-- | hledger-ui screen types & instances.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user