ui: refactor draw functions
This commit is contained in:
parent
06a567fe0a
commit
0cb5703ad1
@ -110,42 +110,6 @@ asDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
|||||||
-- Minibuffer e -> [minibuffer e, maincontent]
|
-- Minibuffer e -> [minibuffer e, maincontent]
|
||||||
_ -> [maincontent]
|
_ -> [maincontent]
|
||||||
where
|
where
|
||||||
toplabel =
|
|
||||||
files
|
|
||||||
<+> nonzero
|
|
||||||
<+> str " accounts"
|
|
||||||
<+> withAttr (borderAttr <> "query") (str (if flat_ ropts then " (flat)" else ""))
|
|
||||||
<+> borderQueryStr querystr
|
|
||||||
<+> togglefilters
|
|
||||||
<+> borderDepthStr mdepth
|
|
||||||
<+> str " ("
|
|
||||||
<+> cur
|
|
||||||
<+> str "/"
|
|
||||||
<+> total
|
|
||||||
<+> str ")"
|
|
||||||
<+> (if ignore_assertions_ copts
|
|
||||||
then withAttr (borderAttr <> "query") (str " ignoring balance assertions")
|
|
||||||
else str "")
|
|
||||||
files = case journalFilePaths j of
|
|
||||||
[] -> str ""
|
|
||||||
f:_ -> withAttr ("border" <> "bold") $ str $ takeFileName f
|
|
||||||
-- [f,_:[]] -> (withAttr ("border" <> "bold") $ str $ takeFileName f) <+> str " (& 1 included file)"
|
|
||||||
-- f:fs -> (withAttr ("border" <> "bold") $ str $ takeFileName f) <+> str (" (& " ++ show (length fs) ++ " included files)")
|
|
||||||
querystr = query_ ropts
|
|
||||||
mdepth = depth_ ropts
|
|
||||||
togglefilters =
|
|
||||||
case concat [
|
|
||||||
uiShowClearedStatus $ clearedstatus_ ropts
|
|
||||||
,if real_ ropts then ["real"] else []
|
|
||||||
] of
|
|
||||||
[] -> str ""
|
|
||||||
fs -> str " with " <+> withAttr (borderAttr <> "query") (str $ intercalate ", " fs) <+> str " txns"
|
|
||||||
nonzero | empty_ ropts = str ""
|
|
||||||
| otherwise = withAttr (borderAttr <> "query") (str " nonzero")
|
|
||||||
cur = str (case _asList s ^. listSelectedL of
|
|
||||||
Nothing -> "-"
|
|
||||||
Just i -> show (i + 1))
|
|
||||||
total = str $ show $ V.length $ s ^. asList . listElementsL
|
|
||||||
maincontent = Widget Greedy Greedy $ do
|
maincontent = Widget Greedy Greedy $ do
|
||||||
c <- getContext
|
c <- getContext
|
||||||
let
|
let
|
||||||
@ -184,9 +148,48 @@ asDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
|||||||
render $ defaultLayout toplabel bottomlabel $ renderList (asDrawItem colwidths) True (_asList s)
|
render $ defaultLayout toplabel bottomlabel $ renderList (asDrawItem colwidths) True (_asList s)
|
||||||
|
|
||||||
where
|
where
|
||||||
|
toplabel =
|
||||||
|
files
|
||||||
|
<+> nonzero
|
||||||
|
<+> str " accounts"
|
||||||
|
<+> withAttr (borderAttr <> "query") (str (if flat_ ropts then " (flat)" else ""))
|
||||||
|
<+> borderQueryStr querystr
|
||||||
|
<+> togglefilters
|
||||||
|
<+> borderDepthStr mdepth
|
||||||
|
<+> str " ("
|
||||||
|
<+> cur
|
||||||
|
<+> str "/"
|
||||||
|
<+> total
|
||||||
|
<+> str ")"
|
||||||
|
<+> (if ignore_assertions_ copts
|
||||||
|
then withAttr (borderAttr <> "query") (str " ignoring balance assertions")
|
||||||
|
else str "")
|
||||||
|
where
|
||||||
|
files = case journalFilePaths j of
|
||||||
|
[] -> str ""
|
||||||
|
f:_ -> withAttr ("border" <> "bold") $ str $ takeFileName f
|
||||||
|
-- [f,_:[]] -> (withAttr ("border" <> "bold") $ str $ takeFileName f) <+> str " (& 1 included file)"
|
||||||
|
-- f:fs -> (withAttr ("border" <> "bold") $ str $ takeFileName f) <+> str (" (& " ++ show (length fs) ++ " included files)")
|
||||||
|
querystr = query_ ropts
|
||||||
|
mdepth = depth_ ropts
|
||||||
|
togglefilters =
|
||||||
|
case concat [
|
||||||
|
uiShowClearedStatus $ clearedstatus_ ropts
|
||||||
|
,if real_ ropts then ["real"] else []
|
||||||
|
] of
|
||||||
|
[] -> str ""
|
||||||
|
fs -> str " with " <+> withAttr (borderAttr <> "query") (str $ intercalate ", " fs) <+> str " txns"
|
||||||
|
nonzero | empty_ ropts = str ""
|
||||||
|
| otherwise = withAttr (borderAttr <> "query") (str " nonzero")
|
||||||
|
cur = str (case _asList s ^. listSelectedL of
|
||||||
|
Nothing -> "-"
|
||||||
|
Just i -> show (i + 1))
|
||||||
|
total = str $ show $ V.length $ s ^. asList . listElementsL
|
||||||
|
|
||||||
bottomlabel = case mode of
|
bottomlabel = case mode of
|
||||||
Minibuffer ed -> minibuffer ed
|
Minibuffer ed -> minibuffer ed
|
||||||
_ -> quickhelp
|
_ -> quickhelp
|
||||||
|
where
|
||||||
quickhelp = borderKeysStr [
|
quickhelp = borderKeysStr [
|
||||||
("?", "help")
|
("?", "help")
|
||||||
,("right", "register")
|
,("right", "register")
|
||||||
|
|||||||
@ -46,17 +46,18 @@ esDraw UIState{ --aopts=UIOpts{cliopts_=copts@CliOpts{}}
|
|||||||
Help -> [helpDialog, maincontent]
|
Help -> [helpDialog, maincontent]
|
||||||
-- Minibuffer e -> [minibuffer e, maincontent]
|
-- Minibuffer e -> [minibuffer e, maincontent]
|
||||||
_ -> [maincontent]
|
_ -> [maincontent]
|
||||||
|
where
|
||||||
|
maincontent = Widget Greedy Greedy $ do
|
||||||
|
render $ defaultLayout toplabel bottomlabel $ withAttr "error" $ str $ esError
|
||||||
where
|
where
|
||||||
toplabel =
|
toplabel =
|
||||||
withAttr ("border" <> "bold") (str "Oops. Please fix this problem then press g to reload")
|
withAttr ("border" <> "bold") (str "Oops. Please fix this problem then press g to reload")
|
||||||
-- <+> (if ignore_assertions_ copts then withAttr (borderAttr <> "query") (str " ignoring") else str " not ignoring")
|
-- <+> (if ignore_assertions_ copts then withAttr (borderAttr <> "query") (str " ignoring") else str " not ignoring")
|
||||||
|
|
||||||
maincontent = Widget Greedy Greedy $ do
|
|
||||||
render $ defaultLayout toplabel bottomlabel $ withAttr "error" $ str $ esError
|
|
||||||
where
|
|
||||||
bottomlabel = case mode of
|
bottomlabel = case mode of
|
||||||
-- Minibuffer ed -> minibuffer ed
|
-- Minibuffer ed -> minibuffer ed
|
||||||
_ -> quickhelp
|
_ -> quickhelp
|
||||||
|
where
|
||||||
quickhelp = borderKeysStr [
|
quickhelp = borderKeysStr [
|
||||||
("h", "help")
|
("h", "help")
|
||||||
,("ESC", "cancel/top")
|
,("ESC", "cancel/top")
|
||||||
|
|||||||
@ -113,36 +113,7 @@ rsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
|||||||
-- Minibuffer e -> [minibuffer e, maincontent]
|
-- Minibuffer e -> [minibuffer e, maincontent]
|
||||||
_ -> [maincontent]
|
_ -> [maincontent]
|
||||||
where
|
where
|
||||||
inclusive = not (flat_ ropts) || rsForceInclusive
|
|
||||||
toplabel =
|
|
||||||
withAttr ("border" <> "bold") (str $ T.unpack $ replaceHiddenAccountsNameWith "All" rsAccount)
|
|
||||||
<+> withAttr (borderAttr <> "query") (str $ if inclusive then "" else " (exclusive)")
|
|
||||||
<+> togglefilters
|
|
||||||
<+> str " transactions"
|
|
||||||
<+> borderQueryStr (query_ ropts)
|
|
||||||
-- <+> str " and subs"
|
|
||||||
<+> str " ("
|
|
||||||
<+> cur
|
|
||||||
<+> str "/"
|
|
||||||
<+> total
|
|
||||||
<+> str ")"
|
|
||||||
<+> (if ignore_assertions_ copts then withAttr (borderAttr <> "query") (str " ignoring balance assertions") else str "")
|
|
||||||
togglefilters =
|
|
||||||
case concat [
|
|
||||||
uiShowClearedStatus $ clearedstatus_ ropts
|
|
||||||
,if real_ ropts then ["real"] else []
|
|
||||||
,if empty_ ropts then [] else ["nonzero"]
|
|
||||||
] of
|
|
||||||
[] -> str ""
|
|
||||||
fs -> withAttr (borderAttr <> "query") (str $ " " ++ intercalate ", " fs)
|
|
||||||
cur = str $ case rsList ^. listSelectedL of
|
|
||||||
Nothing -> "-"
|
|
||||||
Just i -> show (i + 1)
|
|
||||||
total = str $ show $ length displayitems
|
|
||||||
displayitems = V.toList $ rsList ^. listElementsL
|
displayitems = V.toList $ rsList ^. listElementsL
|
||||||
|
|
||||||
-- query = query_ $ reportopts_ $ cliopts_ opts
|
|
||||||
|
|
||||||
maincontent = Widget Greedy Greedy $ do
|
maincontent = Widget Greedy Greedy $ do
|
||||||
-- calculate column widths, based on current available width
|
-- calculate column widths, based on current available width
|
||||||
c <- getContext
|
c <- getContext
|
||||||
@ -187,9 +158,40 @@ rsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
|||||||
render $ defaultLayout toplabel bottomlabel $ renderList (rsDrawItem colwidths) True rsList
|
render $ defaultLayout toplabel bottomlabel $ renderList (rsDrawItem colwidths) True rsList
|
||||||
|
|
||||||
where
|
where
|
||||||
|
toplabel =
|
||||||
|
withAttr ("border" <> "bold") (str $ T.unpack $ replaceHiddenAccountsNameWith "All" rsAccount)
|
||||||
|
<+> withAttr (borderAttr <> "query") (str $ if inclusive then "" else " (exclusive)")
|
||||||
|
<+> togglefilters
|
||||||
|
<+> str " transactions"
|
||||||
|
<+> borderQueryStr (query_ ropts)
|
||||||
|
-- <+> str " and subs"
|
||||||
|
<+> str " ("
|
||||||
|
<+> cur
|
||||||
|
<+> str "/"
|
||||||
|
<+> total
|
||||||
|
<+> str ")"
|
||||||
|
<+> (if ignore_assertions_ copts then withAttr (borderAttr <> "query") (str " ignoring balance assertions") else str "")
|
||||||
|
where
|
||||||
|
inclusive = not (flat_ ropts) || rsForceInclusive
|
||||||
|
togglefilters =
|
||||||
|
case concat [
|
||||||
|
uiShowClearedStatus $ clearedstatus_ ropts
|
||||||
|
,if real_ ropts then ["real"] else []
|
||||||
|
,if empty_ ropts then [] else ["nonzero"]
|
||||||
|
] of
|
||||||
|
[] -> str ""
|
||||||
|
fs -> withAttr (borderAttr <> "query") (str $ " " ++ intercalate ", " fs)
|
||||||
|
cur = str $ case rsList ^. listSelectedL of
|
||||||
|
Nothing -> "-"
|
||||||
|
Just i -> show (i + 1)
|
||||||
|
total = str $ show $ length displayitems
|
||||||
|
|
||||||
|
-- query = query_ $ reportopts_ $ cliopts_ opts
|
||||||
|
|
||||||
bottomlabel = case mode of
|
bottomlabel = case mode of
|
||||||
Minibuffer ed -> minibuffer ed
|
Minibuffer ed -> minibuffer ed
|
||||||
_ -> quickhelp
|
_ -> quickhelp
|
||||||
|
where
|
||||||
quickhelp = borderKeysStr [
|
quickhelp = borderKeysStr [
|
||||||
("?", "help")
|
("?", "help")
|
||||||
,("left", "back")
|
,("left", "back")
|
||||||
|
|||||||
@ -57,7 +57,12 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
|||||||
-- Minibuffer e -> [minibuffer e, maincontent]
|
-- Minibuffer e -> [minibuffer e, maincontent]
|
||||||
_ -> [maincontent]
|
_ -> [maincontent]
|
||||||
where
|
where
|
||||||
-- datedesc = show (tdate t) ++ " " ++ tdescription t
|
maincontent = Widget Greedy Greedy $ do
|
||||||
|
render $ defaultLayout toplabel bottomlabel $ str $
|
||||||
|
showTransactionUnelidedOneLineAmounts $
|
||||||
|
-- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real
|
||||||
|
t
|
||||||
|
where
|
||||||
toplabel =
|
toplabel =
|
||||||
str "Transaction "
|
str "Transaction "
|
||||||
-- <+> withAttr ("border" <> "bold") (str $ "#" ++ show (tindex t))
|
-- <+> withAttr ("border" <> "bold") (str $ "#" ++ show (tindex t))
|
||||||
@ -70,6 +75,7 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
|||||||
<+> borderQueryStr (query_ ropts)
|
<+> borderQueryStr (query_ ropts)
|
||||||
<+> str (" in "++T.unpack (replaceHiddenAccountsNameWith "All" acct)++")")
|
<+> str (" in "++T.unpack (replaceHiddenAccountsNameWith "All" acct)++")")
|
||||||
<+> (if ignore_assertions_ copts then withAttr (borderAttr <> "query") (str " ignoring balance assertions") else str "")
|
<+> (if ignore_assertions_ copts then withAttr (borderAttr <> "query") (str " ignoring balance assertions") else str "")
|
||||||
|
where
|
||||||
togglefilters =
|
togglefilters =
|
||||||
case concat [
|
case concat [
|
||||||
uiShowClearedStatus $ clearedstatus_ ropts
|
uiShowClearedStatus $ clearedstatus_ ropts
|
||||||
@ -78,15 +84,11 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}
|
|||||||
] of
|
] of
|
||||||
[] -> str ""
|
[] -> str ""
|
||||||
fs -> withAttr (borderAttr <> "query") (str $ " " ++ intercalate ", " fs)
|
fs -> withAttr (borderAttr <> "query") (str $ " " ++ intercalate ", " fs)
|
||||||
maincontent = Widget Greedy Greedy $ do
|
|
||||||
render $ defaultLayout toplabel bottomlabel $ str $
|
|
||||||
showTransactionUnelidedOneLineAmounts $
|
|
||||||
-- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real
|
|
||||||
t
|
|
||||||
where
|
|
||||||
bottomlabel = case mode of
|
bottomlabel = case mode of
|
||||||
-- Minibuffer ed -> minibuffer ed
|
-- Minibuffer ed -> minibuffer ed
|
||||||
_ -> quickhelp
|
_ -> quickhelp
|
||||||
|
where
|
||||||
quickhelp = borderKeysStr [
|
quickhelp = borderKeysStr [
|
||||||
("?", "help")
|
("?", "help")
|
||||||
,("left", "back")
|
,("left", "back")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user