rio-prettyprint 0.1.6.0 → 0.1.7.0
raw patch · 6 files changed
+117/−6 lines, 6 files
Files
- ChangeLog.md +51/−0
- README.md +19/−0
- rio-prettyprint.cabal +6/−2
- src/RIO/PrettyPrint.hs +17/−2
- src/RIO/PrettyPrint/PrettyException.hs +23/−2
- stack.yaml +1/−0
+ ChangeLog.md view
@@ -0,0 +1,51 @@+# Changelog for rio-prettyprint + +## 0.1.7.0 + +* Add `prettyThrowIO` and `prettyThrowM`, to throw an exception as a + `PrettyException`. +* Add `ppException`, to provide the prettiest available information about an + exception. +* Add `prettyGeneric` and `prettyWith` for greater flexibility with pretty + logging. +* Add `blankLine`. + +## 0.1.6.0 + +* Add `mkBulletedList` for greater flexibility in the format of such lists. +* Improve Haddock documentation. + +## 0.1.5.0 + +* Add `Pretty` instances for `SomeBase Dir` and `SomeBase File`. + +## 0.1.4.0 + +* Add `string` and `mkNarrativeList`. +* The `Show` instance of `PrettyException` is now derived. `displayException` is + now defined, as the `displayException` of the inner exception. + +## 0.1.3.0 + +* Add `SimplePrettyApp`, `mkSimplePrettyApp` and `runSimplePrettyApp`, which + facilitate the provision, and use, of a basic environment including pretty + printing functionality. +* Add `PrettyException` representing pretty exceptions. + +## 0.1.2.0 + +* Expose data constructor of StyleDoc + [#8](https://github.com/commercialhaskell/rio-prettyprint/pull/8) + +## 0.1.1.0 + +* Add `Debug`, `Info` and `OtherLevel` data constructors to type `Style` + (intended to be used like the existing `Warning` and `Error` constructors) and + a `logLevelToStyle` function. +* Add `Secondary` and `Highlight` data constructors to type `Style`. +* `defaultStyles` now includes defaults for the new `Style` values, + corresponding to those used by the `rio` package in its logging output. + +## 0.1.0.0 + +* Initial stable release
+ README.md view
@@ -0,0 +1,19 @@+## rio-prettyprint + +`rio-prettyprint` is a Haskell package that provides a library that combines the +logging capabilities of the +[`rio` package](https://hackage.haskell.org/package/rio) with the pretty +printing capabilities of the +[`annotated-wl-pprint` package](https://hackage.haskell.org/package/annotated-wl-pprint). + +Documents can be annotated with an optional style from a set of named styles, +and the style associated with each named style can be specified as a list of +ANSI Select Graphic Rendition (SGR) commands. These commands are represented by +the constructors of a type provided by the +[`ansi-terminal-types` package](https://hackage.haskell.org/package/ansi-terminal-types) + +The library also provides: + +* a type that represents a simple, non-customisable environments that provide + pretty logging functionality; and +* a type that represents pretty exceptions.
rio-prettyprint.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: rio-prettyprint -version: 0.1.6.0 +version: 0.1.7.0 synopsis: Pretty-printing for RIO description: Combine RIO's log capabilities with pretty printing category: Development @@ -13,10 +13,14 @@ bug-reports: https://github.com/commercialhaskell/rio-prettyprint/issues author: Michael Snoyman maintainer: michael@snoyman.com -copyright: 2018-2019 FP Complete +copyright: 2018-2023 FP Complete license: BSD3 license-file: LICENSE build-type: Simple +extra-source-files: + ChangeLog.md + README.md + stack.yaml source-repository head type: git
src/RIO/PrettyPrint.hs view
@@ -48,6 +48,9 @@ , prettyErrorNoIndent , prettyErrorNoIndentL , prettyErrorNoIndentS + -- | Pretty messages at the specified log level. + , prettyGeneric + , prettyWith -- * Semantic styling functions -- | These are used rather than applying colors or other styling directly, @@ -56,6 +59,7 @@ , displayMilliseconds , logLevelToStyle -- * Formatting utils + , blankLine , bulletedList , spacedBulletedList , mkBulletedList @@ -130,6 +134,13 @@ -- TODO: switch to using implicit callstacks once 7.8 support is dropped +prettyGeneric :: + (HasTerm env, HasCallStack, Pretty b, MonadReader env m, MonadIO m) + => LogLevel + -> b + -> m () +prettyGeneric level = prettyWith level id + prettyWith :: (HasTerm env, HasCallStack, Pretty b, MonadReader env m, MonadIO m) => LogLevel @@ -210,6 +221,10 @@ flow :: String -> StyleDoc flow = fillSep . wordDocs +-- | A blank line. +blankLine :: StyleDoc +blankLine = line <> line + -- | @debug message action@ brackets any output of the specified @action@ with -- an initial and final @message@ at log level 'LevelDebug'. The initial message -- is prefixed with the label @Start:@. The final message is prefixed with @@ -273,9 +288,9 @@ -- ^ Spaced with a blank line between each item? -> Char -- ^ The character to act as the bullet point. - -> [StyleDoc] + -> [StyleDoc] -> StyleDoc -mkBulletedList isSpaced bullet = +mkBulletedList isSpaced bullet = mconcat . intersperse spacer . map ((fromString [bullet] <+>) . align) where spacer = if isSpaced then line <> line else line
src/RIO/PrettyPrint/PrettyException.hs view
@@ -56,10 +56,16 @@ -- module RIO.PrettyPrint.PrettyException ( PrettyException (..) + , ppException + , prettyThrowIO + , prettyThrowM ) where -import RIO ( Exception (..), Show, Typeable ) -import Text.PrettyPrint.Leijen.Extended ( Pretty (..) ) +import RIO + ( Exception (..), Maybe (..), MonadIO, MonadThrow, Show, SomeException + , Typeable, (.), throwIO, throwM + ) +import Text.PrettyPrint.Leijen.Extended ( Pretty (..), StyleDoc, string ) -- | Type representing pretty exceptions. -- @@ -75,3 +81,18 @@ instance Exception PrettyException where displayException (PrettyException e) = displayException e + +-- | Provide the prettiest available information about an exception. +ppException :: SomeException -> StyleDoc +ppException e = case fromException e of + Just (PrettyException e') -> pretty e' + Nothing -> (string . displayException) e + +-- | Synchronously throw the given exception as a 'PrettyException'. +prettyThrowIO :: (Exception e, MonadIO m, Pretty e) => e -> m a +prettyThrowIO = throwIO . PrettyException + +-- | Throw the given exception as a 'PrettyException', when the action is run in +-- the monad @m@. +prettyThrowM :: (Exception e, MonadThrow m, Pretty e) => e -> m a +prettyThrowM = throwM . PrettyException
+ stack.yaml view
@@ -0,0 +1,1 @@+resolver: stack-ghc-9.4.7.yaml