packages feed

pretty-simple 4.1.0.0 → 4.1.1.0

raw patch · 7 files changed

+69/−17 lines, 7 files

Files

CHANGELOG.md view
@@ -1,4 +1,18 @@ +## 4.1.1.0++*   Make the pretty-printed output with `outputOptionsCompact` enabled a little+    more compact.+    [#110](https://github.com/cdepillabout/pretty-simple/pull/110).+    Thanks [@juhp](https://github.com/juhp)!+*   Add a `--compact` / `-C` flag to the `pretty-simple` executable that enables+    `outputOptionsCompact`.+    [#111](https://github.com/cdepillabout/pretty-simple/pull/111).+    Thanks again @juhp!+*   Add `pTraceWith` and `pTraceShowWith` to `Debug.Pretty.Simple`.+    [#104](https://github.com/cdepillabout/pretty-simple/pull/104).+    Thanks [@LeviButcher](https://github.com/LeviButcher)!+ ## 4.1.0.0  *   Fix a regression which arose in 4.0, whereby excess spaces would be inserted for unusual strings like dates and IP addresses.
README.md view
@@ -37,7 +37,7 @@  `pretty-simple` can be used to print `bar` in an easy-to-read format: -![example screenshot](/img/pretty-simple-example-screenshot.png?raw=true "example screenshot")+![example screenshot](https://raw.githubusercontent.com/cdepillabout/pretty-simple/master/img/pretty-simple-example-screenshot.png)  ## Usage @@ -175,7 +175,7 @@ `pretty-simple` can be used to pretty-print the JSON-encoded `bar` in an easy-to-read format: -![json example screenshot](/img/pretty-simple-json-example-screenshot.png?raw=true "json example screenshot")+![json example screenshot](https://raw.githubusercontent.com/cdepillabout/pretty-simple/master/img/pretty-simple-json-example-screenshot.png)  (You can find the `lazyByteStringToString`, `putLazyByteStringLn`, and `putLazyTextLn` in the [`ExampleJSON.hs`](example/ExampleJSON.hs)@@ -186,17 +186,16 @@ `pretty-simple` includes a command line executable that can be used to pretty-print anything passed in on stdin. -It can be installed to `~/.local/bin/` with the following command. Note that you-must enable the `buildexe` flag, since it will not be built by default:+It can be installed to `~/.local/bin/` with the following command.  ```sh-$ stack install pretty-simple-2.2.0.1 --flag pretty-simple:buildexe+$ stack install pretty-simple ```  When run on the command line, you can paste in the Haskell datatype you want to be formatted, then hit <kbd>Ctrl</kbd>-<kbd>D</kbd>: -![cli example screenshot](/img/pretty-simple-cli-screenshot.png?raw=true "cli example screenshot")+![cli example screenshot](https://raw.githubusercontent.com/cdepillabout/pretty-simple/master/img/pretty-simple-cli-screenshot.png)  This is very useful if you accidentally print out a Haskell data type with `print` instead of `pPrint`.
app/Main.hs view
@@ -29,22 +29,25 @@ import qualified Data.Text.Lazy.IO as LT import Data.Version (showVersion) import Options.Applicative-       ( Parser, ReadM, execParser, fullDesc, help, helper, info, infoOption, long-       , option, progDesc, readerError, short, showDefaultWith, str, value)+       ( Parser, ReadM, execParser, fullDesc, help, helper, info, infoOption+       , long, option, progDesc, readerError, short, showDefaultWith, str+       , switch, value) import Paths_pretty_simple (version) import Text.Pretty.Simple        ( pStringOpt, OutputOptions        , defaultOutputOptionsDarkBg        , defaultOutputOptionsLightBg        , defaultOutputOptionsNoColor+       , outputOptionsCompact        )  data Color = DarkBg            | LightBg            | NoColor -newtype Args = Args+data Args = Args   { color :: Color+  , compact :: Bool   }  colorReader :: ReadM Color@@ -65,6 +68,11 @@        <> showDefaultWith (const "dark-bg")        <> value DarkBg         )+    <*> switch+        ( long "compact"+       <> short 'C'+       <> help "Compact output"+        )  versionOption :: Parser (a -> a) versionOption =@@ -79,8 +87,7 @@ main = do   args' <- execParser opts   input <- T.getContents-  let printOpt = getPrintOpt $ color args'-      output = pStringOpt printOpt $ unpack input+  let output = pStringOpt (getPrintOpt args') $ unpack input   LT.putStrLn output   where     opts = info (helper <*> versionOption <*> args)@@ -88,7 +95,11 @@      <> progDesc "Format Haskell data types with indentation and highlighting"       ) -    getPrintOpt :: Color -> OutputOptions-    getPrintOpt DarkBg  = defaultOutputOptionsDarkBg-    getPrintOpt LightBg = defaultOutputOptionsLightBg-    getPrintOpt NoColor = defaultOutputOptionsNoColor+    getPrintOpt :: Args -> OutputOptions+    getPrintOpt as =+      (getColorOpt (color as)) {outputOptionsCompact = compact as}++    getColorOpt :: Color -> OutputOptions+    getColorOpt DarkBg  = defaultOutputOptionsDarkBg+    getColorOpt LightBg = defaultOutputOptionsLightBg+    getColorOpt NoColor = defaultOutputOptionsNoColor
pretty-simple.cabal view
@@ -1,5 +1,5 @@ name:                pretty-simple-version:             4.1.0.0+version:             4.1.1.0 synopsis:            pretty printer for data types with a 'Show' instance. description:         Please see <https://github.com/cdepillabout/pretty-simple#readme README.md>. homepage:            https://github.com/cdepillabout/pretty-simple
src/Debug/Pretty/Simple.hs view
@@ -30,6 +30,8 @@   , pTraceEventIO   , pTraceMarker   , pTraceMarkerIO+  , pTraceWith+  , pTraceShowWith     -- * Trace forcing color   , pTraceForceColor   , pTraceIdForceColor@@ -273,6 +275,22 @@ {-# WARNING pTraceMarkerIO "'pTraceMarkerIO' remains in code" #-} pTraceMarkerIO :: String -> IO () pTraceMarkerIO = pTraceMarkerOptIO CheckColorTty defaultOutputOptionsDarkBg++-- | The 'pTraceWith' function pretty prints the result of+-- applying @f to @a and returns back @a+--+-- @since ?+{-# WARNING pTraceWith "'pTraceWith' remains in code" #-}+pTraceWith :: (a -> String) -> a -> a+pTraceWith f a = pTrace (f a) a++-- | The 'pTraceShowWith' function similar to 'pTraceWith' except that+-- @f can return any type that implements Show+--+-- @since ?+{-# WARNING pTraceShowWith "'pTraceShowWith' remains in code" #-}+pTraceShowWith :: Show b => (a -> b) -> a -> a+pTraceShowWith f = (show . f) >>= pTraceShow  ------------------------------------------ -- Helpers
src/Text/Pretty/Simple.hs view
@@ -680,6 +680,15 @@ --         , B --             ( B ( B A ) ) ] ) --+-- >>> pPrintOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} $ [("id", 123), ("state", 1), ("pass", 1), ("tested", 100), ("time", 12345)]+-- [+--     ( "id", 123 ),+--     ( "state", 1 ),+--     ( "pass", 1 ),+--     ( "tested", 100 ),+--     ( "time", 12345 )+-- ]+-- -- __Initial indent__ -- -- >>> pPrintOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsInitialIndent = 3} $ B ( B ( B ( B A ) ) )
src/Text/Pretty/Simple/Internal/Printer.hs view
@@ -255,7 +255,8 @@             spaceIfNeeded = \case               Other (' ' : _) : _ -> mempty               _ -> space-    lineAndCommaSep x y = x <> line' <> annotate Comma "," <> y+    lineAndCommaSep x y = x <> munless (outputOptionsCompact opts) line' <> annotate Comma "," <> y+    munless b x = if b then mempty else x  -- | Determine whether this expression should be displayed on a single line. isSimple :: Expr -> Bool