lib: replace pretty-show with pretty-simple

pretty-simple, already used in .ghci, will hopefully give nicer debug
output, including for values which don't have Read-able Show output.
This should mean that we can start removing custom string-like Show
instances that were a workaround for pretty-show.

We are using the latest version (4.0.0.0) to get compact output.
Here's some old pretty-show output:

 CsvRules
   { rdirectives = [ ( "skip" , "1" ) ]
   , rcsvfieldindexes = [ ( "date" , 1 ) , ( "amount" , 2 ) ]
   , rassignments = [ ( "amount" , "%2" ) , ( "date" , "%1" ) ]
   , rconditionalblocks = []
   }

And the new pretty-simple output:

 CsvRules
   { rdirectives=
     [ ( "skip", "1" ) ]
   , rcsvfieldindexes=
     [ ( "date", 1 ), ( "amount", 2 ) ]
   , rassignments=
     [ ( "amount", "%2" ), ( "date", "%1" ) ]
   , rconditionalblocks= []
   }

Non-compact pretty-simple output would be:

 CsvRules
     { rdirectives=
         [
             ( "skip"
             , "1B"
             )
         ]
     , rcsvfieldindexes=
         [
             ( "date"
             , 1
             )
         ,
             ( "amount"
             , 2
             )
         ]
     , rassignments=
         [
             ( "amount"
             , "%2"
             )
         ,
             ( "date"
             , "%1"
             )
         ]
     , rconditionalblocks=[]
     }

Also:

- Account's Show instance no longer converts : to _ in account names

- drop unused pretty-show dependency from hledger, hledger-ui packages

- regenerate hledger-lib with the older hpack that's shipped in stack
This commit is contained in:
Simon Michael 2020-11-10 07:08:29 -08:00
parent 84ee05baa6
commit a97daaf322
15 changed files with 42 additions and 29 deletions

View File

@ -14,7 +14,6 @@ import Data.List.Extra (groupSort, groupOn)
import Data.Maybe (fromMaybe)
import Data.Ord (Down(..))
import qualified Data.Map as M
import qualified Data.Text as T
import Safe (headMay, lookupJustDef)
import Text.Printf
@ -28,12 +27,11 @@ import Hledger.Utils
-- deriving instance Show Account
instance Show Account where
show Account{..} = printf "Account %s (boring:%s, postings:%d, ebalance:%s, ibalance:%s)"
(T.map colonToUnderscore aname) -- hide : so pretty-show doesn't break line
aname
(if aboring then "y" else "n" :: String)
anumpostings
(showMixedAmount aebalance)
(showMixedAmount aibalance)
where colonToUnderscore x = if x == ':' then '_' else x
instance Eq Account where
(==) a b = aname a == aname b -- quick equality test for speed

View File

@ -111,7 +111,6 @@ import Hledger.Utils
-- Help ppShow parse and line-wrap DateSpans better in debug output.
instance Show DateSpan where
show s = "DateSpan " ++ showDateSpan s
-- show s = "DateSpan \"" ++ showDateSpan s ++ "\"" -- quotes to help pretty-show
showDate :: Day -> String
showDate = show

View File

@ -89,6 +89,7 @@ import Control.Monad (when)
import Control.Monad.IO.Class
import Data.List hiding (uncons)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Debug.Trace
import Hledger.Utils.Parse
import Safe (readDef)
@ -97,17 +98,27 @@ import System.Exit
import System.IO.Unsafe (unsafePerformIO)
import Text.Megaparsec
import Text.Printf
import Text.Show.Pretty (ppShow, pPrint)
import Text.Pretty.Simple -- (defaultOutputOptionsDarkBg, OutputOptions(..), pShowOpt, pPrintOpt)
-- | Pretty print. Easier alias for pretty-show's pPrint.
prettyopts =
defaultOutputOptionsDarkBg
-- defaultOutputOptionsLightBg
-- defaultOutputOptionsNoColor
{ outputOptionsIndentAmount=2
, outputOptionsCompact=True
}
-- | Pretty print. Generic alias for pretty-simple's pPrint.
pprint :: Show a => a -> IO ()
pprint = pPrint
pprint = pPrintOpt CheckColorTty prettyopts
-- | Pretty show. Easier alias for pretty-show's ppShow.
-- | Pretty show. Generic alias for pretty-simple's pShow.
pshow :: Show a => a -> String
pshow = ppShow
pshow = TL.unpack . pShowOpt prettyopts
-- | Pretty trace. Easier alias for traceShowId + ppShow.
-- XXX some of the below can be improved with pretty-simple, https://github.com/cdepillabout/pretty-simple#readme
-- | Pretty trace. Easier alias for traceShowId + pShow.
ptrace :: Show a => a -> a
ptrace = traceWith pshow
@ -157,7 +168,7 @@ traceAtWith f a = trace (f a) a
ptraceAt :: Show a => Int -> String -> a -> a
ptraceAt level
| level > 0 && debugLevel < level = flip const
| otherwise = \s a -> let p = ppShow a
| otherwise = \s a -> let p = pshow a
ls = lines p
nlorspace | length ls > 1 = "\n"
| otherwise = " " ++ take (10 - length s) (repeat ' ')
@ -303,7 +314,7 @@ plogAt :: Show a => Int -> String -> a -> a
plogAt lvl
| lvl > 0 && debugLevel < lvl = flip const
| otherwise = \s a ->
let p = ppShow a
let p = pshow a
ls = lines p
nlorspace | length ls > 1 = "\n"
| otherwise = " " ++ take (10 - length s) (repeat ' ')

View File

@ -1,10 +1,10 @@
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.34.2.
-- This file has been generated from package.yaml by hpack version 0.33.0.
--
-- see: https://github.com/sol/hpack
--
-- hash: 24b8acde4649dda5e31d86c9f4f95744af97bae68f0e978144a55baf621d0bc8
-- hash: 8be95614d73bb909eb29a27d8411f09623debad24f7fe84cf42ebc8b851a7ba8
name: hledger-lib
version: 1.19.99
@ -136,7 +136,7 @@ library
, old-time
, parsec >=3
, parser-combinators >=0.4.0
, pretty-show >=1.6.4
, pretty-simple >4 && <5
, regex-tdfa
, safe >=0.2
, split >=0.1
@ -189,7 +189,7 @@ test-suite doctest
, old-time
, parsec >=3
, parser-combinators >=0.4.0
, pretty-show >=1.6.4
, pretty-simple >4 && <5
, regex-tdfa
, safe >=0.2
, split >=0.1
@ -244,7 +244,7 @@ test-suite unittest
, old-time
, parsec >=3
, parser-combinators >=0.4.0
, pretty-show >=1.6.4
, pretty-simple >4 && <5
, regex-tdfa
, safe >=0.2
, split >=0.1

View File

@ -69,7 +69,7 @@ dependencies:
- old-time
- parsec >=3
- parser-combinators >=0.4.0
- pretty-show >=1.6.4
- pretty-simple >4 && <5
- regex-tdfa
- safe >=0.2
- split >=0.1

View File

@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 057371c2b8cf46c32339a64339eaf98ac7247396cf8bb2dad13e99a5931cd62f
-- hash: 4e0beb8ffb64276b8f69f1bc9cf738199248509c23193799370132f748a74612
name: hledger-ui
version: 1.19.99
@ -83,7 +83,6 @@ executable hledger-ui
, megaparsec >=7.0.0 && <9.1
, microlens >=0.4
, microlens-platform >=0.2.3.1
, pretty-show >=1.6.4
, process >=1.2
, safe >=0.2
, split >=0.1

View File

@ -57,7 +57,6 @@ dependencies:
- microlens >=0.4
- microlens-platform >=0.2.3.1
- megaparsec >=7.0.0 && <9.1
- pretty-show >=1.6.4
- process >=1.2
- safe >=0.2
- split >=0.1

View File

@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 3becac2b267d30f6ce283af8e9b43dfa4f6ea374f6854da6c2272779fe3cb12c
-- hash: 4517e1a53a08aa05c53bb06d8591b5591f3ae6f688bf39f809c8f774fbd1d41c
name: hledger
version: 1.19.99
@ -172,7 +172,6 @@ library
, mtl >=2.2.1
, old-time
, parsec >=3
, pretty-show >=1.6.4
, process
, regex-tdfa
, safe >=0.2
@ -223,7 +222,6 @@ executable hledger
, mtl >=2.2.1
, old-time
, parsec >=3
, pretty-show >=1.6.4
, process
, regex-tdfa
, safe >=0.2
@ -275,7 +273,6 @@ test-suite unittest
, mtl >=2.2.1
, old-time
, parsec >=3
, pretty-show >=1.6.4
, process
, regex-tdfa
, safe >=0.2
@ -326,7 +323,6 @@ benchmark bench
, mtl >=2.2.1
, old-time
, parsec >=3
, pretty-show >=1.6.4
, process
, regex-tdfa
, safe >=0.2

View File

@ -126,7 +126,6 @@ dependencies:
- mtl >=2.2.1
- old-time
- parsec >=3
- pretty-show >=1.6.4
- process
- regex-tdfa
- safe >=0.2

View File

@ -12,8 +12,10 @@ packages:
- hledger-ui
- hledger-web
# extra-deps:
extra-deps:
# for hledger-lib:
- pretty-simple-4.0.0.0
- prettyprinter-1.7.0
# for hledger:
# for hledger-ui:
# for hledger-web:

View File

@ -78,3 +78,5 @@ extra-deps:
- resourcet-1.2.4
- http-conduit-1.3.0
- monad-logger-0.3.28
- pretty-simple-4.0.0.0
- prettyprinter-1.7.0

View File

@ -12,4 +12,6 @@ packages:
- hledger-ui
- hledger-web
#extra-deps:
extra-deps:
- pretty-simple-4.0.0.0
- prettyprinter-1.7.0

View File

@ -42,3 +42,5 @@ extra-deps:
- streaming-commons-0.2.1.2
- network-2.7.0.0
- math-functions-0.3.3.0
- pretty-simple-4.0.0.0
- prettyprinter-1.7.0

View File

@ -25,3 +25,5 @@ extra-deps:
- streaming-commons-0.2.1.2
- network-2.7.0.0
- math-functions-0.3.3.0
- pretty-simple-4.0.0.0
- prettyprinter-1.7.0

View File

@ -24,6 +24,8 @@ extra-deps:
# - base-compat-0.11.0
# - http-api-data-0.4.1.1
# for hledger-lib:
- pretty-simple-4.0.0.0
- prettyprinter-1.7.0
# for hledger:
# for hledger-ui:
# for hledger-web: