Skip to content

Commit

Permalink
Merge pull request #375 from input-output-hk/newhoggy/minor-prettypri…
Browse files Browse the repository at this point in the history
…nter-fixes

Minor `prettyprinter` fixes
  • Loading branch information
newhoggy authored Nov 17, 2023
2 parents 74fe801 + 926215b commit b3a7387
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cardano-api/internal/Cardano/Api/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ data FileError e = FileError FilePath e
| FileIOError FilePath IOException
deriving (Show, Eq, Functor)

instance Error e => Pretty (FileError e) where
pretty = \case
instance Error e => Error (FileError e) where
prettyError = \case
FileErrorTempFile targetPath tempPath h ->
vsep
[ "Error creating temporary file at: " <> pretty tempPath
Expand Down
12 changes: 10 additions & 2 deletions cardano-api/internal/Cardano/Api/Pretty.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module Cardano.Api.Pretty
( Ann
, Doc
, Pretty(..)
, ShowOf(..)
, viaShow
, prettyToLazyText
, prettyToText
, prettyToString
, pshow
Expand All @@ -17,10 +19,13 @@ module Cardano.Api.Pretty
, white
) where

import qualified Data.Text as Text
import qualified Data.Text.Lazy as TextLazy
import Prettyprinter
import Prettyprinter.Render.Terminal

-- | 'Ann' is the prettyprinter annotation for cardano-api and cardano-cli to enable the printing
-- of colored output. This is a type alias for AnsiStyle.
type Ann = AnsiStyle

newtype ShowOf a = ShowOf a
Expand All @@ -34,8 +39,11 @@ instance Show a => Pretty (ShowOf a) where
prettyToString :: Doc AnsiStyle -> String
prettyToString = show

prettyToText :: Doc AnsiStyle -> TextLazy.Text
prettyToText = renderLazy . layoutPretty defaultLayoutOptions
prettyToLazyText :: Doc AnsiStyle -> TextLazy.Text
prettyToLazyText = renderLazy . layoutPretty defaultLayoutOptions

prettyToText :: Doc AnsiStyle -> Text.Text
prettyToText = TextLazy.toStrict . prettyToLazyText

black :: Doc AnsiStyle -> Doc AnsiStyle
black = annotate (color Black)
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/test/cardano-api-test/Test/Cardano/Api/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ prop_createVrfFileWithOwnerPermissions =
result <- liftIO $ writeLazyByteStringFileWithOwnerPermissions (File file) ""

case result of
Left err -> failWith Nothing $ prettyToString $ pretty @(FileError ()) err
Left err -> failWith Nothing $ prettyToString $ prettyError @(FileError ()) err
Right () -> return ()

fResult <- liftIO . runExceptT $ checkVrfFilePermissions (File file)
Expand Down

0 comments on commit b3a7387

Please sign in to comment.