--------------------------------------------------------------------------------
module Patat.Presentation.Display.Internal
    ( DisplaySettings (..)
    , themed
    ) where


--------------------------------------------------------------------------------
import           Patat.Presentation.Internal (Margins)
import           Patat.Presentation.Settings (Wrap)
import qualified Patat.PrettyPrint           as PP
import           Patat.Size                  (Size)
import qualified Patat.Theme                 as Theme
import qualified Skylighting                 as Skylighting


--------------------------------------------------------------------------------
data DisplaySettings = DisplaySettings
    { DisplaySettings -> Size
dsSize      :: !Size
    , DisplaySettings -> Wrap
dsWrap      :: !Wrap
    , DisplaySettings -> Int
dsTabStop   :: !Int
    , DisplaySettings -> Margins
dsMargins   :: !Margins
    , DisplaySettings -> Theme
dsTheme     :: !Theme.Theme
    , DisplaySettings -> SyntaxMap
dsSyntaxMap :: !Skylighting.SyntaxMap
    }


--------------------------------------------------------------------------------
themed
    :: DisplaySettings -> (Theme.Theme -> Maybe Theme.Style) -> PP.Doc -> PP.Doc
themed :: DisplaySettings -> (Theme -> Maybe Style) -> Doc -> Doc
themed DisplaySettings
ds Theme -> Maybe Style
f = case Theme -> Maybe Style
f (DisplaySettings -> Theme
dsTheme DisplaySettings
ds) of
    Maybe Style
Nothing                  -> Doc -> Doc
forall a. a -> a
id
    Just (Theme.Style [])    -> Doc -> Doc
forall a. a -> a
id
    Just (Theme.Style [SGR]
codes) -> [SGR] -> Doc -> Doc
PP.ansi [SGR]
codes