From f496ec980903a9997aa62580bf096331b01e53e8 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 25 Aug 2015 06:56:04 -0700 Subject: [PATCH] ui: acc: show a better title with filename & query --- hledger-ui/Hledger/UI/AccountsScreen.hs | 20 +++++++++++++++++--- hledger-ui/Hledger/UI/Theme.hs | 4 +++- hledger-ui/Hledger/UI/UIUtils.hs | 7 ++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/hledger-ui/Hledger/UI/AccountsScreen.hs b/hledger-ui/Hledger/UI/AccountsScreen.hs index e4204f6d9..dd5ed974c 100644 --- a/hledger-ui/Hledger/UI/AccountsScreen.hs +++ b/hledger-ui/Hledger/UI/AccountsScreen.hs @@ -11,8 +11,9 @@ import Control.Lens ((^.)) import Control.Monad.IO.Class -- import Data.Default import Data.List --- import Data.Monoid -- +import Data.Monoid import Data.Time.Calendar (Day) +import System.FilePath (takeFileName) import qualified Data.Vector as V import Graphics.Vty as Vty import Brick @@ -56,9 +57,22 @@ initAccountsScreen d args st@AppState{aopts=opts, ajournal=j, aScreen=s@Accounts initAccountsScreen _ _ _ = error "init function called with wrong screen type, should not happen" drawAccountsScreen :: AppState -> [Widget] -drawAccountsScreen st@AppState{aScreen=AccountsScreen{asState=is}} = [ui] +drawAccountsScreen st@AppState{aopts=uopts, ajournal=j, aScreen=AccountsScreen{asState=is}} = [ui] where - label = str "Account " <+> cur <+> str " of " <+> total + label = str "Accounts in " + <+> withAttr ("border" <> "bold") files + <+> borderQuery querystr + <+> str " (" + <+> cur + <+> str " of " + <+> total + <+> str ")" + files = str $ case journalFilePaths j of + [] -> "" + [f] -> takeFileName f + [f,_] -> takeFileName f ++ " (& 1 included file)" + f:fs -> takeFileName f ++ " (& " ++ show (length fs) ++ " included files)" + querystr = query_ $ reportopts_ $ cliopts_ uopts cur = str (case is^.listSelectedL of Nothing -> "-" Just i -> show (i + 1)) diff --git a/hledger-ui/Hledger/UI/Theme.hs b/hledger-ui/Hledger/UI/Theme.hs index 0abba2670..7b44ffc78 100644 --- a/hledger-ui/Hledger/UI/Theme.hs +++ b/hledger-ui/Hledger/UI/Theme.hs @@ -66,7 +66,9 @@ themesList :: [(String, AttrMap)] themesList = [ ("default", attrMap (black `on` white & bold) [ -- default style for this theme - (borderAttr , white `on` black), + (borderAttr , white `on` black & dim), + (borderAttr <> "bold", white `on` black & bold), + (borderAttr <> "query", yellow `on` black & bold), -- ("normal" , black `on` white), ("list" , black `on` white), -- regular list items ("list" <> "selected" , white `on` blue & bold) -- selected list items diff --git a/hledger-ui/Hledger/UI/UIUtils.hs b/hledger-ui/Hledger/UI/UIUtils.hs index 62f49f4c9..472b802b7 100644 --- a/hledger-ui/Hledger/UI/UIUtils.hs +++ b/hledger-ui/Hledger/UI/UIUtils.hs @@ -9,13 +9,14 @@ module Hledger.UI.UIUtils ( ,withBorderAttr ,topBottomBorderWithLabel ,defaultLayout + ,borderQuery ) where import Control.Lens ((^.)) -- import Control.Monad -- import Control.Monad.IO.Class -- import Data.Default --- import Data.Monoid -- +import Data.Monoid import Data.Time.Calendar (Day) import Brick -- import Brick.Widgets.List @@ -121,3 +122,7 @@ withBorderAttr attr = updateAttrMap (applyAttrMappings [(borderAttr, attr)]) -- , str " " -- , hCenter $ str "Press Esc to exit." -- ] + +borderQuery :: String -> Widget +borderQuery "" = str "" +borderQuery qry = str " filtered by: " <+> withAttr (borderAttr <> "query") (str qry)