Skip to content
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

Add pretty printing without colour #73

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions trial/src/Trial.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ module Trial
, prettyTaggedTrial
, prettyTaggedTrialWith

-- * Pretty printing without colour
, prettyFatalityNoColour
, prettyTrialNoColour
, prettyTrialWithNoColour
, prettyTaggedTrialNoColour
, prettyTaggedTrialWithNoColour

-- * Configuration helpers
-- $phase
, Phase (..)
Expand Down Expand Up @@ -840,6 +847,71 @@ prettyTaggedTrialWith showRes = \case
<> C.i "\nWith the following warnings:\n"
<> foldr (\e -> (<>) (prettyEntry (W, e))) "" es

{- | Print aligned 'Fatality'.

-}
prettyFatalityNoColour :: (Semigroup str, IsString str) => Fatality -> str
prettyFatalityNoColour = \case
E -> "Error "
W -> "Warning"

prettyEntryNoColour :: (Semigroup e, IsString e) => (Fatality, e) -> e
prettyEntryNoColour (f, e) = " * [" <> prettyFatalityNoColour f <> "] " <> e <> "\n"

{- | Pretty-printing of 'Trial'.

-}
prettyTrialNoColour
:: (Show a, Semigroup e, IsString e)
=> Trial e a
-> e
prettyTrialNoColour = prettyTrialWithNoColour show

{- | Similar to 'prettyTrialNoColour', but accepts a function to show Result in the
provided way.

-}
prettyTrialWithNoColour
:: (Semigroup e, IsString e)
=> (a -> String)
-> Trial e a
-> e
prettyTrialWithNoColour showRes = \case
Fiasco es -> "Fiasco:\n"
<> foldr (\e -> (<>) (prettyEntryNoColour e)) "" es
Result es a -> "Result:\n"
<> fromString (unlines $ map (" " <>) $ lines $ showRes a)
<> "\nWith the following warnings:\n"
<> foldr (\e -> (<>) (prettyEntryNoColour (W, e))) "" es

{- | Pretty-printing of 'TaggedTrial'. Similar to
'prettyTrialNoColour', but also prints the resulting @tag@ for 'Result'.

-}
prettyTaggedTrialNoColour
:: (Show a, Semigroup e, IsString e)
=> TaggedTrial e a
-> e
prettyTaggedTrialNoColour = prettyTaggedTrialWithNoColour show

{- | Similar to 'prettyTaggedTrialNoColour', but accepts a function to show the 'Result'
in the provided way.

--}
prettyTaggedTrialWithNoColour
:: (Semigroup e, IsString e)
=> (a -> String)
-> TaggedTrial e a
-> e
prettyTaggedTrialWithNoColour showRes = \case
Fiasco es -> "Fiasco:\n"
<> foldr (\e -> (<>) (prettyEntryNoColour e)) "" es
Result es (tag, a) -> "Result:\n"
<> (" [" <> tag <> "]\n ")
<> fromString (unlines $ map (" " <>) $ lines $ showRes a)
<> "\nWith the following warnings:\n"
<> foldr (\e -> (<>) (prettyEntryNoColour (W, e))) "" es

----------------------------------------------------------------------------
-- Configurations
----------------------------------------------------------------------------
Expand Down
Loading