New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Adopt pretty rendering #1136
Conversation
I've read the commits so far.. could you give a little more explanation of the goals and benefits of the proposed approach ? I'm not sure if there's a clear example yet of how it helps, or if you are just laying the groundwork so far. |
Instead of having 4 implementations: showMixedAmountWithoutPrice m = intercalate "\n" $ map showamt as
where
Mixed as = normaliseMixedAmountSquashPricesForDisplay $ mixedAmountStripPrices m
showamt = printf (printf "%%%ds" width) . showAmountWithoutPrice
where
width = maximumDef 0 $ map (length . showAmount) as
cshowMixedAmountWithoutPrice m = intercalate "\n" $ map showamt as
where
Mixed as = normaliseMixedAmountSquashPricesForDisplay $ mixedAmountStripPrices m
showamt a =
(if isNegativeAmount a then color Dull Red else id) $
printf (printf "%%%ds" width) $ showAmountWithoutPrice a
where
width = maximumDef 0 $ map (length . showAmount) as
showMixedAmountOneLineWithoutPrice m = intercalate ", " $ map showAmountWithoutPrice as
where
(Mixed as) = normaliseMixedAmountSquashPricesForDisplay $ stripPrices m
stripPrices (Mixed as) = Mixed $ map stripprice as where stripprice a = a{aprice=Nothing}
cshowMixedAmountOneLineWithoutPrice m = intercalate ", " $ map cshowAmountWithoutPrice as
where
(Mixed as) = normaliseMixedAmountSquashPricesForDisplay $ stripPrices m
stripPrices (Mixed as) = Mixed $ map stripprice as where stripprice a = a{aprice=Nothing} We have kinda one instance Pretty MixedAmount where
pretty = prettyMixedAmountHelper pretty
prettyMixedAmountHelper prettyAmount m = verical `flatAlt` flat where
Mixed as = normaliseMixedAmountSquashPricesForDisplay m
docs = map prettyAmount as
verical = vcatRight docs
flat = encloseSep mempty mempty ", " docs From which we can infer them all showMixedAmountWithoutPrice = showWide . plain . pretty . mixedAmountStripPrices
cshowMixedAmountWithoutPrice = showWide . pretty . mixedAmountStripPrices
showMixedAmountOneLineWithoutPrice = showWide . plain . hgroup . pretty . mixedAmountStripPrices
cshowMixedAmountOneLineWithoutPrice = showWide . hgroup . pretty . mixedAmountStripPrices
After that we can start using Another thing is to get rid of those helpers that can be replaced with adding
It supposed to be clear already. Further work might be about table layout abstraction with text re-flow inside of cells (e.g. for multi-commodity balances |
@ony, thanks. I'm getting clearer on this. I think: Currently for debug info we use the Show typeclass augmented by pretty-show, You propose to replace the user output functions with ansi-wl-pprint's Pretty typeclass. It's probably a great idea but I propose we don't try to get it into 1.16 release. Some issues that come to mind:
|
Sure. I use I'd think this PR more like a branch on the review at this moment. We should drop if during this exploration we'll not benefit or will suffer significantly on performance degradation.
Not sure how this will affect. As I understand tasty is just organizer for tests. For shell tests I think it will be easier to write adapter similar to
Indeed. I switched to
I don't think so 🙊 ( quchen/prettyprinter#103 ). We can push this problem to them 😆 . For |
Great. I'm all for extracting/outsourcing reusable functionality like wide chars, as long as we keep international characters working in hledger.
|
56bc295
to
01f9c70
Compare
What's the status here? I think this has mostly been unified with the addition of |
@Xitian9 , if I understand correctly idea of hledger/hledger-lib/Hledger/Data/Amount.hs Line 468 in ff76927
hledger/hledger-lib/Hledger/Data/Amount.hs Lines 460 to 461 in ff76927
In this proposal idea was a bit different. Instead of passing in options color/no-color that goes through all renderers we return value that can be both colorful and non-colorful. hledger/hledger-lib/Hledger/Utils/Pretty.hs Lines 64 to 66 in 4c27916
Notice that I.e. we can get rid of new hledger/hledger-lib/Hledger/Data/Amount.hs Line 203 in ff76927
I'm not familiar with new code-base, so I'm not sure how right now that information reaches Beside that idea was to get rid of unique names for every data-type and use one overloaded If I would try to re-based this on top of class Render a where
type DisplayOpts a
renderWith :: DisplayOpts a -> a -> Display b
render :: a -> Display (DisplayOpts a)
-- | Some "markup" maybe in some library
data Display opts where
-- | That can be arranged in plain text accounting specifics of output device (e.g. terminal width)
foldDisplayTo :: OutputInfo -> Display Void -> Text
class LiftDisplay a b where
liftDisplay :: Display b -> Display a
unpackDisplayOpts :: a -> b
instance LiftDisplay TransactionDisplayOpts AmountDisplayOpts where
unpackDisplayOpts = amountDisplayOpts
instance Render Transaction where
type DisplayOpts Transaction = TransactionDisplayOpts
render txn = {- ... -} liftDisplay (render amt) {- ... -} It was also an attempt to adopt use of frameworks to construct text output that does all the re-flowing and alignment for us. I don't mind closing this draft PR since I don't have plans to invest into it in near future. |
Ah, I understand. That makes a lot of sense. I'm pushing to move out table rendering infrastructure over to |
Closing for now, we can reactivate this later if needed. |
Purpose of PR
Unify how we render colorful and plain reports in
hledger
so there is no need to have them implemented twice.Libraries considered
This is only my quick look and opinion. Maybe someone have more to add.
pretty
. Quiet old and no recent changes, but used by Cabal. Colors need to be introduced via annotations like inwl-pprint-terminfo
.ansi-wl-pprint
. Have support for colors out of the box viaansi-terminal
that we use right now.prettyprinter
. Seems to be fresh. As inpretty
colors need to be supported via annotations, but there is alreadyprettyprinter-ansi-terminal
that useansi-terminal
.annotated-wl-pprint
. Apparently stripped versionansi-wl-pprint
. Used byrio-prettyprint
(authored by Michael Snoyman).boxes
. Highly oriented on layout management. Nothingtable-layout
. Looks to be highly oriented on how to render tables. No clear composition of primitive objects.Progress
Hledger.Data.Amount
.Hledger.Commands.Balance
.Hledger.Commands.Register
.Hledger.Reports.BalanceReport
.hledger-ui
for potential re-use.