improve pretty printing stuff

This commit is contained in:
Rhiannon Morris 2020-07-15 12:07:04 +02:00
parent 0c187fff29
commit 74f2e30955
2 changed files with 14 additions and 10 deletions

View file

@ -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

View file

@ -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