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,21 +148,60 @@ 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 | ||||||
|         quickhelp = borderKeysStr [ |           where | ||||||
|            ("?", "help") |             quickhelp = borderKeysStr [ | ||||||
|           ,("right", "register") |                ("?", "help") | ||||||
|           ,("F", "flat?") |               ,("right", "register") | ||||||
|           ,("-+0123456789", "depth") |               ,("F", "flat?") | ||||||
|           --,("/", "filter") |               ,("-+0123456789", "depth") | ||||||
|           --,("DEL", "unfilter") |               --,("/", "filter") | ||||||
|           --,("ESC", "cancel/top") |               --,("DEL", "unfilter") | ||||||
|           ,("a", "add") |               --,("ESC", "cancel/top") | ||||||
|           ,("g", "reload") |               ,("a", "add") | ||||||
|           ,("q", "quit") |               ,("g", "reload") | ||||||
|           ] |               ,("q", "quit") | ||||||
|  |               ] | ||||||
| 
 | 
 | ||||||
| asDraw _ = error "draw function called with wrong screen type, should not happen" | asDraw _ = error "draw function called with wrong screen type, should not happen" | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -47,23 +47,24 @@ esDraw UIState{ --aopts=UIOpts{cliopts_=copts@CliOpts{}} | |||||||
|     -- Minibuffer e -> [minibuffer e, maincontent] |     -- Minibuffer e -> [minibuffer e, maincontent] | ||||||
|     _          -> [maincontent] |     _          -> [maincontent] | ||||||
|   where |   where | ||||||
|     toplabel = |  | ||||||
|           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") |  | ||||||
| 
 |  | ||||||
|     maincontent = Widget Greedy Greedy $ do |     maincontent = Widget Greedy Greedy $ do | ||||||
|       render $ defaultLayout toplabel bottomlabel $ withAttr "error" $ str $ esError |       render $ defaultLayout toplabel bottomlabel $ withAttr "error" $ str $ esError | ||||||
|       where |       where | ||||||
|  |         toplabel = | ||||||
|  |               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") | ||||||
|  | 
 | ||||||
|         bottomlabel = case mode of |         bottomlabel = case mode of | ||||||
|                         -- Minibuffer ed -> minibuffer ed |                         -- Minibuffer ed -> minibuffer ed | ||||||
|                         _             -> quickhelp |                         _             -> quickhelp | ||||||
|         quickhelp = borderKeysStr [ |           where | ||||||
|            ("h", "help") |             quickhelp = borderKeysStr [ | ||||||
|           ,("ESC", "cancel/top") |                ("h", "help") | ||||||
|           ,("E", "editor") |               ,("ESC", "cancel/top") | ||||||
|           ,("g", "reload") |               ,("E", "editor") | ||||||
|           ,("q", "quit") |               ,("g", "reload") | ||||||
|           ] |               ,("q", "quit") | ||||||
|  |               ] | ||||||
| 
 | 
 | ||||||
| esDraw _ = error "draw function called with wrong screen type, should not happen" | esDraw _ = error "draw function called with wrong screen type, should not happen" | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -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,20 +158,51 @@ 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 | ||||||
|         quickhelp = borderKeysStr [ |           where | ||||||
|            ("?", "help") |             quickhelp = borderKeysStr [ | ||||||
|           ,("left", "back") |                ("?", "help") | ||||||
|           ,("right", "transaction") |               ,("left", "back") | ||||||
|           ,("/", "filter") |               ,("right", "transaction") | ||||||
|           ,("DEL", "unfilter") |               ,("/", "filter") | ||||||
|           --,("ESC", "reset") |               ,("DEL", "unfilter") | ||||||
|           ,("a", "add") |               --,("ESC", "reset") | ||||||
|           ,("g", "reload") |               ,("a", "add") | ||||||
|           ,("q", "quit") |               ,("g", "reload") | ||||||
|           ] |               ,("q", "quit") | ||||||
|  |               ] | ||||||
| 
 | 
 | ||||||
| rsDraw _ = error "draw function called with wrong screen type, should not happen" | rsDraw _ = error "draw function called with wrong screen type, should not happen" | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -57,46 +57,48 @@ 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 |  | ||||||
|     toplabel = |  | ||||||
|       str "Transaction " |  | ||||||
|       -- <+> withAttr ("border" <> "bold") (str $ "#" ++ show (tindex t)) |  | ||||||
|       -- <+> str (" ("++show i++" of "++show (length nts)++" in "++acct++")") |  | ||||||
|       <+> (str $ "#" ++ show (tindex t)) |  | ||||||
|       <+> str " (" |  | ||||||
|       <+> withAttr ("border" <> "bold") (str $ show i) |  | ||||||
|       <+> str (" of "++show (length nts)) |  | ||||||
|       <+> togglefilters |  | ||||||
|       <+> borderQueryStr (query_ ropts) |  | ||||||
|       <+> str (" in "++T.unpack (replaceHiddenAccountsNameWith "All" acct)++")") |  | ||||||
|       <+> (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) |  | ||||||
|     maincontent = Widget Greedy Greedy $ do |     maincontent = Widget Greedy Greedy $ do | ||||||
|       render $ defaultLayout toplabel bottomlabel $ str $ |       render $ defaultLayout toplabel bottomlabel $ str $ | ||||||
|         showTransactionUnelidedOneLineAmounts $ |         showTransactionUnelidedOneLineAmounts $ | ||||||
|         -- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real |         -- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real | ||||||
|         t |         t | ||||||
|       where |       where | ||||||
|  |         toplabel = | ||||||
|  |           str "Transaction " | ||||||
|  |           -- <+> withAttr ("border" <> "bold") (str $ "#" ++ show (tindex t)) | ||||||
|  |           -- <+> str (" ("++show i++" of "++show (length nts)++" in "++acct++")") | ||||||
|  |           <+> (str $ "#" ++ show (tindex t)) | ||||||
|  |           <+> str " (" | ||||||
|  |           <+> withAttr ("border" <> "bold") (str $ show i) | ||||||
|  |           <+> str (" of "++show (length nts)) | ||||||
|  |           <+> togglefilters | ||||||
|  |           <+> borderQueryStr (query_ ropts) | ||||||
|  |           <+> str (" in "++T.unpack (replaceHiddenAccountsNameWith "All" acct)++")") | ||||||
|  |           <+> (if ignore_assertions_ copts then withAttr (borderAttr <> "query") (str " ignoring balance assertions") else str "") | ||||||
|  |           where | ||||||
|  |             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) | ||||||
|  | 
 | ||||||
|         bottomlabel = case mode of |         bottomlabel = case mode of | ||||||
|                         -- Minibuffer ed -> minibuffer ed |                         -- Minibuffer ed -> minibuffer ed | ||||||
|                         _             -> quickhelp |                         _             -> quickhelp | ||||||
|         quickhelp = borderKeysStr [ |           where | ||||||
|            ("?", "help") |             quickhelp = borderKeysStr [ | ||||||
|           ,("left", "back") |                ("?", "help") | ||||||
|           ,("up/down", "prev/next") |               ,("left", "back") | ||||||
|           --,("ESC", "cancel/top") |               ,("up/down", "prev/next") | ||||||
|           -- ,("a", "add") |               --,("ESC", "cancel/top") | ||||||
|           ,("E", "editor") |               -- ,("a", "add") | ||||||
|           ,("g", "reload") |               ,("E", "editor") | ||||||
|           ,("q", "quit") |               ,("g", "reload") | ||||||
|           ] |               ,("q", "quit") | ||||||
|  |               ] | ||||||
| 
 | 
 | ||||||
| tsDraw _ = error "draw function called with wrong screen type, should not happen" | tsDraw _ = error "draw function called with wrong screen type, should not happen" | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user