-----------------------------------------------------------------------------
-- |
  Copyright    :   ( C ) 2011 - 2019  
-- License     :  BSD-style (see the file LICENSE)
--
  Maintainer   :     <  >
-- Stability   :  experimental
-- Portability :  non-portable
--
-- Utility functions to augment the prettyprinter library's interface.
----------------------------------------------------------------------------

module Text.Trifecta.Util.Pretty
  ( AnsiStyle
  , renderIO
  -- * Rendering
  , char
  -- * Styles
  , bold
  , debold
  , underlined
  , deunderline
  -- * Compatibility shims
  , renderPretty
  , columns
  ) where


import Prettyprinter
import Prettyprinter.Render.Terminal
import Prettyprinter.Render.Terminal.Internal (ansiBold, ansiUnderlining)

char :: Char -> Doc a
char = pretty

renderPretty :: Double -> Int -> Doc AnsiStyle -> SimpleDocStream AnsiStyle
renderPretty ribbonFraction page
  = layoutSmart LayoutOptions { layoutPageWidth = AvailablePerLine page ribbonFraction }

debold, deunderline :: AnsiStyle
debold = mempty { ansiBold = Nothing }
deunderline = mempty { ansiUnderlining = Nothing}

columns :: (Maybe Int -> Doc AnsiStyle) -> Doc AnsiStyle
columns f = pageWidth (f . toMaybeInt) where
  toMaybeInt (AvailablePerLine cpl _) = Just cpl
  toMaybeInt Unbounded = Nothing

---------------------------------------------------------------------------
 |
 License     :  BSD-style (see the file LICENSE)

 Stability   :  experimental
 Portability :  non-portable

 Utility functions to augment the prettyprinter library's interface.
--------------------------------------------------------------------------
 * Rendering
 * Styles
 * Compatibility shims
  Copyright    :   ( C ) 2011 - 2019  
  Maintainer   :     <  >

module Text.Trifecta.Util.Pretty
  ( AnsiStyle
  , renderIO
  , char
  , bold
  , debold
  , underlined
  , deunderline
  , renderPretty
  , columns
  ) where


import Prettyprinter
import Prettyprinter.Render.Terminal
import Prettyprinter.Render.Terminal.Internal (ansiBold, ansiUnderlining)

char :: Char -> Doc a
char = pretty

renderPretty :: Double -> Int -> Doc AnsiStyle -> SimpleDocStream AnsiStyle
renderPretty ribbonFraction page
  = layoutSmart LayoutOptions { layoutPageWidth = AvailablePerLine page ribbonFraction }

debold, deunderline :: AnsiStyle
debold = mempty { ansiBold = Nothing }
deunderline = mempty { ansiUnderlining = Nothing}

columns :: (Maybe Int -> Doc AnsiStyle) -> Doc AnsiStyle
columns f = pageWidth (f . toMaybeInt) where
  toMaybeInt (AvailablePerLine cpl _) = Just cpl
  toMaybeInt Unbounded = Nothing
