From 30cce4188f6c30f02cc82030f5faeb56812661fc Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 4 Sep 2015 08:14:36 -0700 Subject: [PATCH] ui: acc: g key reloads the journal On the accounts screen, the g key now reloads the journal if possible. With large journals, there may be a noticeable delay before the screen updates. If there's a problem reading the journal file(s), this has no effect. --- hledger-ui/Hledger/UI/AccountsScreen.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hledger-ui/Hledger/UI/AccountsScreen.hs b/hledger-ui/Hledger/UI/AccountsScreen.hs index 690919e5d..2d6da1be3 100644 --- a/hledger-ui/Hledger/UI/AccountsScreen.hs +++ b/hledger-ui/Hledger/UI/AccountsScreen.hs @@ -122,6 +122,7 @@ drawAccountsScreen _st@AppState{aopts=uopts, ajournal=j, aScreen=AccountsScreen{ -- ("up/down/pgup/pgdown/home/end", "move") ("-+1234567890", "adjust depth limit") ,("right/enter", "show transactions") + ,("g", "reload") ,("q", "quit") ] @@ -192,7 +193,11 @@ drawAccountsItem (acctwidth, balwidth) selected (indent, _fullacct, displayacct, | otherwise = id handleAccountsScreen :: AppState -> Vty.Event -> EventM (Next AppState) -handleAccountsScreen st@AppState{aScreen=scr@AccountsScreen{asState=l}} e = do +handleAccountsScreen st@AppState{ + aScreen=scr@AccountsScreen{asState=l} + ,aopts=UIOpts{cliopts_=copts} + ,ajournal=j + } e = do d <- liftIO getCurrentDay -- c <- getContext -- let h = c^.availHeightL @@ -206,6 +211,13 @@ handleAccountsScreen st@AppState{aScreen=scr@AccountsScreen{asState=l}} e = do case e of Vty.EvKey Vty.KEsc [] -> halt st Vty.EvKey (Vty.KChar 'q') [] -> halt st + -- Vty.EvKey (Vty.KChar 'l') [Vty.MCtrl] -> do + Vty.EvKey (Vty.KChar 'g') [] -> do + (ej, changed) <- liftIO $ journalReloadIfChanged copts j + case (changed, ej) of + (True, Right j') -> reload st{ajournal=j'} + -- (True, Left err) -> continue st{amsg=err} -- XXX report parse error + _ -> continue st Vty.EvKey (Vty.KChar '-') [] -> reload $ decDepth st Vty.EvKey (Vty.KChar '+') [] -> reload $ incDepth st Vty.EvKey (Vty.KChar '1') [] -> reload $ setDepth 1 st