module Chapelure where

import Chapelure.Handler.Colourful (Config, layoutOptions, render)
import Chapelure.Style (putDocText, renderDoc)
import Chapelure.Types
import Data.Text (Text)
import Prettyprinter (layoutPretty)

-- | Helper for displaying a diagnostic to standard out, using default layout options
displayDiagnostic :: Config -> Diagnostic -> IO ()
displayDiagnostic :: Config -> Diagnostic -> IO ()
displayDiagnostic Config
config Diagnostic
diagnostic = SimpleDocStream Style -> IO ()
putDocText (SimpleDocStream Style -> IO ()) -> SimpleDocStream Style -> IO ()
forall a b. (a -> b) -> a -> b
$ LayoutOptions -> Doc Style -> SimpleDocStream Style
forall ann. LayoutOptions -> Doc ann -> SimpleDocStream ann
layoutPretty (Config -> LayoutOptions
layoutOptions Config
config) (Doc Style -> SimpleDocStream Style)
-> Doc Style -> SimpleDocStream Style
forall a b. (a -> b) -> a -> b
$ Config -> Diagnostic -> Doc Style
render Config
config Diagnostic
diagnostic

-- | Helper for rendering a diagnostic to text, using default layout options
displayDiagnosticAsString :: Config -> Diagnostic -> Text
displayDiagnosticAsString :: Config -> Diagnostic -> Text
displayDiagnosticAsString Config
config Diagnostic
diagnostic = SimpleDocStream Style -> Text
renderDoc (SimpleDocStream Style -> Text) -> SimpleDocStream Style -> Text
forall a b. (a -> b) -> a -> b
$ LayoutOptions -> Doc Style -> SimpleDocStream Style
forall ann. LayoutOptions -> Doc ann -> SimpleDocStream ann
layoutPretty (Config -> LayoutOptions
layoutOptions Config
config) (Doc Style -> SimpleDocStream Style)
-> Doc Style -> SimpleDocStream Style
forall a b. (a -> b) -> a -> b
$ Config -> Diagnostic -> Doc Style
render Config
config Diagnostic
diagnostic