From 74f2e30955e0e5ed70353893fa457b887e7f382e Mon Sep 17 00:00:00 2001 From: Rhiannon Morris Date: Wed, 15 Jul 2020 12:07:04 +0200 Subject: [PATCH] improve pretty printing stuff --- make-pages/Main.hs | 23 +++++++++++++---------- make-pages/make-pages.cabal | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/make-pages/Main.hs b/make-pages/Main.hs index b1e1bc4..171958b 100644 --- a/make-pages/Main.hs +++ b/make-pages/Main.hs @@ -7,7 +7,7 @@ import qualified Data.YAML as YAML import Data.Text.Lazy (Text) import qualified Data.Text.Lazy.IO as Text import qualified Options.Applicative as Opt -import System.IO (hPutStrLn, stderr) +import System.IO (hPrint, stderr) import System.FilePath (makeRelative) import Text.Printf (printf) import Control.Applicative @@ -16,7 +16,8 @@ import SinglePage import Depend #ifdef PRETTY_VERBOSE -import Text.Show.Pretty (ppShow) +import qualified Text.Show.Pretty as PP +import qualified Text.PrettyPrint as PP #endif data Options = @@ -119,13 +120,7 @@ main2 opts@(Options printV :: Show a => Options -> a -> IO () -printV (Options {verbose}) x = - when verbose $ hPutStrLn stderr $ -#ifdef PRETTY_VERBOSE - ppShow x -#else - show x -#endif +printV (Options {verbose}) x = when verbose $ hPrint stderr x readYAML :: YAML.FromYAML a => FilePath -> IO a readYAML file = ByteString.readFile file >>= decode1Must file @@ -141,4 +136,12 @@ writeOutput :: Maybe FilePath -> Text -> IO () writeOutput (Just f) = Text.writeFile f writeOutput Nothing = Text.putStrLn -data Tag a = String :- a deriving Show +data Tag a = String :- a + +instance Show a => Show (Tag a) where + show (tag :- a) = +#ifdef PRETTY_VERBOSE + PP.render $ PP.hang (PP.text tag <> ":") 2 (PP.ppDoc a) +#else + tag ++ ": " ++ show a +#endif diff --git a/make-pages/make-pages.cabal b/make-pages/make-pages.cabal index a82cbb6..2744d4b 100644 --- a/make-pages/make-pages.cabal +++ b/make-pages/make-pages.cabal @@ -50,5 +50,6 @@ executable make-pages -Wall -threaded -rtsopts -with-rtsopts=-N if flag(pretty-verbose) build-depends: + pretty ^>= 1.1.3.6, pretty-show ^>= 1.10 cpp-options: -DPRETTY_VERBOSE