ui: Use Text instead of String in RegisterScreen.
This commit is contained in:
		
							parent
							
								
									0e59fee251
								
							
						
					
					
						commit
						56e87f934c
					
				| @ -98,17 +98,16 @@ rsInit d reset ui@UIState{aopts=_uopts@UIOpts{cliopts_=CliOpts{reportspec_=rspec | |||||||
|     displayitems = map displayitem items' |     displayitems = map displayitem items' | ||||||
|       where |       where | ||||||
|         displayitem (t, _, _issplit, otheracctsstr, change, bal) = |         displayitem (t, _, _issplit, otheracctsstr, change, bal) = | ||||||
|           RegisterScreenItem{rsItemDate          = T.unpack . showDate $ transactionRegisterDate q thisacctq t |           RegisterScreenItem{rsItemDate          = showDate $ transactionRegisterDate q thisacctq t | ||||||
|                             ,rsItemStatus        = tstatus t |                             ,rsItemStatus        = tstatus t | ||||||
|                             ,rsItemDescription   = T.unpack $ tdescription t |                             ,rsItemDescription   = tdescription t | ||||||
|                             ,rsItemOtherAccounts = T.unpack otheracctsstr |                             ,rsItemOtherAccounts = otheracctsstr | ||||||
|                                                      -- _   -> "<split>"  -- should do this if accounts field width < 30 |                                                      -- _   -> "<split>"  -- should do this if accounts field width < 30 | ||||||
|                             ,rsItemChangeAmount  = showamt change |                             ,rsItemChangeAmount  = showamt change | ||||||
|                             ,rsItemBalanceAmount = showamt bal |                             ,rsItemBalanceAmount = showamt bal | ||||||
|                             ,rsItemTransaction   = t |                             ,rsItemTransaction   = t | ||||||
|                             } |                             } | ||||||
|             where showamt = (\wb -> (wbUnpack wb, wbWidth wb)) |             where showamt = showMixedAmountB oneLine{displayMaxWidth=Just 32} | ||||||
|                           . showMixedAmountB oneLine{displayMaxWidth=Just 32} |  | ||||||
|     -- blank items are added to allow more control of scroll position; we won't allow movement over these. |     -- blank items are added to allow more control of scroll position; we won't allow movement over these. | ||||||
|     -- XXX Ugly. Changing to 0 helps when debugging. |     -- XXX Ugly. Changing to 0 helps when debugging. | ||||||
|     blankitems = replicate 100  -- "100 ought to be enough for anyone" |     blankitems = replicate 100  -- "100 ought to be enough for anyone" | ||||||
| @ -116,8 +115,8 @@ rsInit d reset ui@UIState{aopts=_uopts@UIOpts{cliopts_=CliOpts{reportspec_=rspec | |||||||
|                             ,rsItemStatus        = Unmarked |                             ,rsItemStatus        = Unmarked | ||||||
|                             ,rsItemDescription   = "" |                             ,rsItemDescription   = "" | ||||||
|                             ,rsItemOtherAccounts = "" |                             ,rsItemOtherAccounts = "" | ||||||
|                             ,rsItemChangeAmount  = ("", 0) |                             ,rsItemChangeAmount  = mempty | ||||||
|                             ,rsItemBalanceAmount = ("", 0) |                             ,rsItemBalanceAmount = mempty | ||||||
|                             ,rsItemTransaction   = nulltransaction |                             ,rsItemTransaction   = nulltransaction | ||||||
|                             } |                             } | ||||||
|     -- build the List |     -- build the List | ||||||
| @ -175,8 +174,8 @@ rsDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec}} | |||||||
|         whitespacewidth = 10 -- inter-column whitespace, fixed width |         whitespacewidth = 10 -- inter-column whitespace, fixed width | ||||||
|         minnonamtcolswidth = datewidth + 1 + 2 + 2 -- date column plus at least 1 for status and 2 for desc and accts |         minnonamtcolswidth = datewidth + 1 + 2 + 2 -- date column plus at least 1 for status and 2 for desc and accts | ||||||
|         maxamtswidth = max 0 (totalwidth - minnonamtcolswidth - whitespacewidth) |         maxamtswidth = max 0 (totalwidth - minnonamtcolswidth - whitespacewidth) | ||||||
|         maxchangewidthseen = maximum' $ map (snd . rsItemChangeAmount) displayitems |         maxchangewidthseen = maximum' $ map (wbWidth . rsItemChangeAmount) displayitems | ||||||
|         maxbalwidthseen = maximum' $ map (snd . rsItemBalanceAmount) displayitems |         maxbalwidthseen = maximum' $ map (wbWidth . rsItemBalanceAmount) displayitems | ||||||
|         changewidthproportion = fromIntegral maxchangewidthseen / fromIntegral (maxchangewidthseen + maxbalwidthseen) |         changewidthproportion = fromIntegral maxchangewidthseen / fromIntegral (maxchangewidthseen + maxbalwidthseen) | ||||||
|         maxchangewidth = round $ changewidthproportion * fromIntegral maxamtswidth |         maxchangewidth = round $ changewidthproportion * fromIntegral maxamtswidth | ||||||
|         maxbalwidth = maxamtswidth - maxchangewidth |         maxbalwidth = maxamtswidth - maxchangewidth | ||||||
| @ -235,7 +234,7 @@ rsDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec}} | |||||||
|                          Nothing -> "-" |                          Nothing -> "-" | ||||||
|                          Just i -> show (i + 1) |                          Just i -> show (i + 1) | ||||||
|             total = str $ show $ length nonblanks |             total = str $ show $ length nonblanks | ||||||
|             nonblanks = V.takeWhile (not . null . rsItemDate) $ rsList^.listElementsL |             nonblanks = V.takeWhile (not . T.null . rsItemDate) $ rsList^.listElementsL | ||||||
| 
 | 
 | ||||||
|             -- query = query_ $ reportopts_ $ cliopts_ opts |             -- query = query_ $ reportopts_ $ cliopts_ opts | ||||||
| 
 | 
 | ||||||
| @ -266,21 +265,23 @@ rsDrawItem :: (Int,Int,Int,Int,Int) -> Bool -> RegisterScreenItem -> Widget Name | |||||||
| rsDrawItem (datewidth,descwidth,acctswidth,changewidth,balwidth) selected RegisterScreenItem{..} = | rsDrawItem (datewidth,descwidth,acctswidth,changewidth,balwidth) selected RegisterScreenItem{..} = | ||||||
|   Widget Greedy Fixed $ do |   Widget Greedy Fixed $ do | ||||||
|     render $ |     render $ | ||||||
|       str (fitString (Just datewidth) (Just datewidth) True True rsItemDate) <+> |       txt (fitText (Just datewidth) (Just datewidth) True True rsItemDate) <+> | ||||||
|       str " " <+> |       txt " " <+> | ||||||
|       str (fitString (Just 1) (Just 1) True True (show rsItemStatus)) <+> |       txt (fitText (Just 1) (Just 1) True True (T.pack $ show rsItemStatus)) <+> | ||||||
|       str " " <+> |       txt " " <+> | ||||||
|       str (fitString (Just descwidth) (Just descwidth) True True rsItemDescription) <+> |       txt (fitText (Just descwidth) (Just descwidth) True True rsItemDescription) <+> | ||||||
|       str "  " <+> |       txt "  " <+> | ||||||
|       str (fitString (Just acctswidth) (Just acctswidth) True True rsItemOtherAccounts) <+> |       txt (fitText (Just acctswidth) (Just acctswidth) True True rsItemOtherAccounts) <+> | ||||||
|       str "   " <+> |       txt "   " <+> | ||||||
|       withAttr changeattr (str (fitString (Just changewidth) (Just changewidth) True False $ fst rsItemChangeAmount)) <+> |       withAttr changeattr (txt $ fitText (Just changewidth) (Just changewidth) True False changeAmt) <+> | ||||||
|       str "   " <+> |       txt "   " <+> | ||||||
|       withAttr balattr (str (fitString (Just balwidth) (Just balwidth) True False $ fst rsItemBalanceAmount)) |       withAttr balattr (txt $ fitText (Just balwidth) (Just balwidth) True False balanceAmt) | ||||||
|   where |   where | ||||||
|     changeattr | '-' `elem` fst rsItemChangeAmount = sel $ "list" <> "amount" <> "decrease" |     changeAmt  = wbToText rsItemChangeAmount | ||||||
|  |     balanceAmt = wbToText rsItemBalanceAmount | ||||||
|  |     changeattr | T.any (=='-') changeAmt  = sel $ "list" <> "amount" <> "decrease" | ||||||
|                | otherwise                = sel $ "list" <> "amount" <> "increase" |                | otherwise                = sel $ "list" <> "amount" <> "increase" | ||||||
|     balattr    | '-' `elem` fst rsItemBalanceAmount = sel $ "list" <> "balance" <> "negative" |     balattr    | T.any (=='-') balanceAmt = sel $ "list" <> "balance" <> "negative" | ||||||
|                | otherwise                = sel $ "list" <> "balance" <> "positive" |                | otherwise                = sel $ "list" <> "balance" <> "positive" | ||||||
|     sel | selected  = (<> "selected") |     sel | selected  = (<> "selected") | ||||||
|         | otherwise = id |         | otherwise = id | ||||||
| @ -295,7 +296,7 @@ rsHandle ui@UIState{ | |||||||
|   d <- liftIO getCurrentDay |   d <- liftIO getCurrentDay | ||||||
|   let |   let | ||||||
|     journalspan = journalDateSpan False j |     journalspan = journalDateSpan False j | ||||||
|     nonblanks = V.takeWhile (not . null . rsItemDate) $ rsList^.listElementsL |     nonblanks = V.takeWhile (not . T.null . rsItemDate) $ rsList^.listElementsL | ||||||
|     lastnonblankidx = max 0 (length nonblanks - 1) |     lastnonblankidx = max 0 (length nonblanks - 1) | ||||||
| 
 | 
 | ||||||
|   case mode of |   case mode of | ||||||
|  | |||||||
| @ -38,6 +38,7 @@ Brick.defaultMain brickapp st | |||||||
| 
 | 
 | ||||||
| module Hledger.UI.UITypes where | module Hledger.UI.UITypes where | ||||||
| 
 | 
 | ||||||
|  | import Data.Text (Text) | ||||||
| import Data.Time.Calendar (Day) | import Data.Time.Calendar (Day) | ||||||
| import Brick | import Brick | ||||||
| import Brick.Widgets.List (List) | import Brick.Widgets.List (List) | ||||||
| @ -141,12 +142,12 @@ data AccountsScreenItem = AccountsScreenItem { | |||||||
| 
 | 
 | ||||||
| -- | An item in the register screen's list of transactions in the current account. | -- | An item in the register screen's list of transactions in the current account. | ||||||
| data RegisterScreenItem = RegisterScreenItem { | data RegisterScreenItem = RegisterScreenItem { | ||||||
|    rsItemDate           :: String           -- ^ date |    rsItemDate           :: Text         -- ^ date | ||||||
|   ,rsItemStatus         :: Status       -- ^ transaction status |   ,rsItemStatus         :: Status       -- ^ transaction status | ||||||
|   ,rsItemDescription    :: String           -- ^ description |   ,rsItemDescription    :: Text         -- ^ description | ||||||
|   ,rsItemOtherAccounts  :: String           -- ^ other accounts |   ,rsItemOtherAccounts  :: Text         -- ^ other accounts | ||||||
|   ,rsItemChangeAmount   :: (String, Int)    -- ^ the change to the current account from this transaction |   ,rsItemChangeAmount   :: WideBuilder  -- ^ the change to the current account from this transaction | ||||||
|   ,rsItemBalanceAmount  :: (String, Int)    -- ^ the balance or running total after this transaction |   ,rsItemBalanceAmount  :: WideBuilder  -- ^ the balance or running total after this transaction | ||||||
|   ,rsItemTransaction    :: Transaction  -- ^ the full transaction |   ,rsItemTransaction    :: Transaction  -- ^ the full transaction | ||||||
|   } |   } | ||||||
|   deriving (Show) |   deriving (Show) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user