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 Data.Text.Lazy (Text)
import qualified Data.Text.Lazy.IO as Text import qualified Data.Text.Lazy.IO as Text
import qualified Options.Applicative as Opt import qualified Options.Applicative as Opt
import System.IO (hPutStrLn, stderr) import System.IO (hPrint, stderr)
import System.FilePath (makeRelative) import System.FilePath (makeRelative)
import Text.Printf (printf) import Text.Printf (printf)
import Control.Applicative import Control.Applicative
@ -16,7 +16,8 @@ import SinglePage
import Depend import Depend
#ifdef PRETTY_VERBOSE #ifdef PRETTY_VERBOSE
import Text.Show.Pretty (ppShow) import qualified Text.Show.Pretty as PP
import qualified Text.PrettyPrint as PP
#endif #endif
data Options = data Options =
@ -119,13 +120,7 @@ main2 opts@(Options
printV :: Show a => Options -> a -> IO () printV :: Show a => Options -> a -> IO ()
printV (Options {verbose}) x = printV (Options {verbose}) x = when verbose $ hPrint stderr x
when verbose $ hPutStrLn stderr $
#ifdef PRETTY_VERBOSE
ppShow x
#else
show x
#endif
readYAML :: YAML.FromYAML a => FilePath -> IO a readYAML :: YAML.FromYAML a => FilePath -> IO a
readYAML file = ByteString.readFile file >>= decode1Must file readYAML file = ByteString.readFile file >>= decode1Must file
@ -141,4 +136,12 @@ writeOutput :: Maybe FilePath -> Text -> IO ()
writeOutput (Just f) = Text.writeFile f writeOutput (Just f) = Text.writeFile f
writeOutput Nothing = Text.putStrLn 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 -Wall -threaded -rtsopts -with-rtsopts=-N
if flag(pretty-verbose) if flag(pretty-verbose)
build-depends: build-depends:
pretty ^>= 1.1.3.6,
pretty-show ^>= 1.10 pretty-show ^>= 1.10
cpp-options: -DPRETTY_VERBOSE cpp-options: -DPRETTY_VERBOSE