mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-27 04:13:11 +03:00
ui: In account screen, elide amounts which go past the specified width.
Also leave at least 15 spaces width for account names.
This commit is contained in:
parent
21a49b9479
commit
203b12bfd9
@ -100,10 +100,8 @@ asInit d reset ui@UIState{
|
|||||||
AccountsScreenItem{asItemIndentLevel = indent
|
AccountsScreenItem{asItemIndentLevel = indent
|
||||||
,asItemAccountName = fullacct
|
,asItemAccountName = fullacct
|
||||||
,asItemDisplayAccountName = replaceHiddenAccountsNameWith "All" $ if tree_ ropts then shortacct else fullacct
|
,asItemDisplayAccountName = replaceHiddenAccountsNameWith "All" $ if tree_ ropts then shortacct else fullacct
|
||||||
,asItemRenderedAmounts = map showAmountWithoutPrice amts
|
,asItemMixedAmount = Just bal
|
||||||
}
|
}
|
||||||
where
|
|
||||||
amts = amounts . normaliseMixedAmountSquashPricesForDisplay $ mixedAmountStripPrices bal
|
|
||||||
displayitems = map displayitem items
|
displayitems = map displayitem items
|
||||||
-- blanks added for scrolling control, cf RegisterScreen.
|
-- blanks added for scrolling control, cf RegisterScreen.
|
||||||
-- XXX Ugly. Changing to 0 helps when debugging.
|
-- XXX Ugly. Changing to 0 helps when debugging.
|
||||||
@ -111,7 +109,7 @@ asInit d reset ui@UIState{
|
|||||||
AccountsScreenItem{asItemIndentLevel = 0
|
AccountsScreenItem{asItemIndentLevel = 0
|
||||||
,asItemAccountName = ""
|
,asItemAccountName = ""
|
||||||
,asItemDisplayAccountName = ""
|
,asItemDisplayAccountName = ""
|
||||||
,asItemRenderedAmounts = []
|
,asItemMixedAmount = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -144,10 +142,10 @@ asDraw UIState{aopts=_uopts@UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec}}
|
|||||||
displayitems
|
displayitems
|
||||||
maxbalwidthseen =
|
maxbalwidthseen =
|
||||||
-- ltrace "maxbalwidthseen" $
|
-- ltrace "maxbalwidthseen" $
|
||||||
V.maximum $ V.map (\AccountsScreenItem{..} -> sum (map strWidth asItemRenderedAmounts) + 2 * (length asItemRenderedAmounts - 1)) displayitems
|
V.maximum $ V.map (maybe 0 (wbWidth . showMixedAmountB oneLine) . asItemMixedAmount) displayitems
|
||||||
maxbalwidth =
|
maxbalwidth =
|
||||||
-- ltrace "maxbalwidth" $
|
-- ltrace "maxbalwidth" $
|
||||||
max 0 (availwidth - 2 - 4) -- leave 2 whitespace plus least 4 for accts
|
max 0 (availwidth - 2 - 15) -- leave 2 whitespace plus at least 15 for accts
|
||||||
balwidth =
|
balwidth =
|
||||||
-- ltrace "balwidth" $
|
-- ltrace "balwidth" $
|
||||||
min maxbalwidth maxbalwidthseen
|
min maxbalwidth maxbalwidthseen
|
||||||
@ -229,24 +227,17 @@ asDrawItem (acctwidth, balwidth) selected AccountsScreenItem{..} =
|
|||||||
-- c <- getContext
|
-- c <- getContext
|
||||||
-- let showitem = intercalate "\n" . balanceReportItemAsText defreportopts fmt
|
-- let showitem = intercalate "\n" . balanceReportItemAsText defreportopts fmt
|
||||||
render $
|
render $
|
||||||
addamts asItemRenderedAmounts $
|
txt (fitText (Just acctwidth) (Just acctwidth) True True $ T.replicate (asItemIndentLevel) " " <> asItemDisplayAccountName) <+>
|
||||||
str (T.unpack $ fitText (Just acctwidth) (Just acctwidth) True True $ T.replicate (asItemIndentLevel) " " <> asItemDisplayAccountName) <+>
|
txt balspace <+>
|
||||||
str " " <+>
|
splitAmounts balBuilder
|
||||||
str (balspace asItemRenderedAmounts)
|
|
||||||
where
|
where
|
||||||
balspace as = replicate n ' '
|
balBuilder = maybe mempty showamt asItemMixedAmount
|
||||||
where n = max 0 (balwidth - (sum (map strWidth as) + 2 * (length as - 1)))
|
showamt = showMixedAmountB oneLine{displayMinWidth=Just balwidth, displayMaxWidth=Just balwidth}
|
||||||
addamts :: [String] -> Widget Name -> Widget Name
|
balspace = T.replicate (2 + balwidth - wbWidth balBuilder) " "
|
||||||
addamts [] w = w
|
splitAmounts = foldr1 (<+>) . intersperse (str ", ") . map renderamt . T.splitOn ", " . wbToText
|
||||||
addamts [a] w = (<+> renderamt a) w
|
renderamt :: T.Text -> Widget Name
|
||||||
-- foldl' :: (b -> a -> b) -> b -> t a -> b
|
renderamt a | T.any (=='-') a = withAttr (sel $ "list" <> "balance" <> "negative") $ txt a
|
||||||
-- foldl' (Widget -> String -> Widget) -> Widget -> [String] -> Widget
|
| otherwise = withAttr (sel $ "list" <> "balance" <> "positive") $ txt a
|
||||||
addamts (a:as) w = foldl' addamt (addamts [a] w) as
|
|
||||||
addamt :: Widget Name -> String -> Widget Name
|
|
||||||
addamt w a = ((<+> renderamt a) . (<+> str ", ")) w
|
|
||||||
renderamt :: String -> Widget Name
|
|
||||||
renderamt a | '-' `elem` a = withAttr (sel $ "list" <> "balance" <> "negative") $ str a
|
|
||||||
| otherwise = withAttr (sel $ "list" <> "balance" <> "positive") $ str a
|
|
||||||
sel | selected = (<> "selected")
|
sel | selected = (<> "selected")
|
||||||
| otherwise = id
|
| otherwise = id
|
||||||
|
|
||||||
|
@ -133,12 +133,11 @@ data Screen =
|
|||||||
|
|
||||||
-- | An item in the accounts screen's list of accounts and balances.
|
-- | An item in the accounts screen's list of accounts and balances.
|
||||||
data AccountsScreenItem = AccountsScreenItem {
|
data AccountsScreenItem = AccountsScreenItem {
|
||||||
asItemIndentLevel :: Int -- ^ indent level
|
asItemIndentLevel :: Int -- ^ indent level
|
||||||
,asItemAccountName :: AccountName -- ^ full account name
|
,asItemAccountName :: AccountName -- ^ full account name
|
||||||
,asItemDisplayAccountName :: AccountName -- ^ full or short account name to display
|
,asItemDisplayAccountName :: AccountName -- ^ full or short account name to display
|
||||||
,asItemRenderedAmounts :: [String] -- ^ rendered amounts
|
,asItemMixedAmount :: Maybe MixedAmount -- ^ mixed amount to display
|
||||||
}
|
} deriving (Show)
|
||||||
deriving (Show)
|
|
||||||
|
|
||||||
-- | 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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user