{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}


{-|
Module      : $header$
Copyright   : (c) Laurent P René de Cotret, 2020
License     : GNU GPL, version 2 or above
Maintainer  : laurent.decotret@outlook.com
Stability   : internal
Portability : portable

Reading configuration from file
-}

module Text.Pandoc.Filter.Plot.Configuration (
      configuration
    , configurationPathMeta
    , defaultConfiguration
) where

import           Data.Maybe             (fromMaybe)
import           Data.Text              (Text, pack, unpack)
import qualified Data.Text.IO           as TIO
import           Data.Yaml
import           Data.Yaml.Config       (ignoreEnv, loadYamlSettings)

import           Text.Pandoc.Definition (Format(..), Pandoc(..), MetaValue(..), lookupMeta)

import Text.Pandoc.Filter.Plot.Monad   

-- | Read configuration from a YAML file. The

-- keys are exactly the same as for code blocks.

--

-- If a key is not present, its value will be set

-- to the default value. Parsing errors result in thrown exceptions.

configuration :: FilePath -> IO Configuration
configuration :: FilePath -> IO Configuration
configuration fp :: FilePath
fp = ([FilePath] -> [Value] -> EnvUsage -> IO ConfigPrecursor
forall settings.
FromJSON settings =>
[FilePath] -> [Value] -> EnvUsage -> IO settings
loadYamlSettings [FilePath
fp] [] EnvUsage
ignoreEnv) IO ConfigPrecursor
-> (ConfigPrecursor -> IO Configuration) -> IO Configuration
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConfigPrecursor -> IO Configuration
renderConfig


-- | Default configuration values.

--

-- @since 0.5.0.0

defaultConfiguration :: Configuration
defaultConfiguration :: Configuration
defaultConfiguration = 
    $WConfiguration :: FilePath
-> Bool
-> Int
-> SaveFormat
-> Format
-> Verbosity
-> LogSink
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> Bool
-> Bool
-> Configuration
Configuration
        { defaultDirectory :: FilePath
defaultDirectory  = "plots/"
        , defaultWithSource :: Bool
defaultWithSource = Bool
False
        , defaultDPI :: Int
defaultDPI        = 80
        , defaultSaveFormat :: SaveFormat
defaultSaveFormat = SaveFormat
PNG
        , captionFormat :: Format
captionFormat     = Script -> Format
Format "markdown+tex_math_dollars"

        , logVerbosity :: Verbosity
logVerbosity      = Verbosity
Warning
        , logSink :: LogSink
logSink           = LogSink
StdErr
        
        , matplotlibPreamble :: Script
matplotlibPreamble  = Script
forall a. Monoid a => a
mempty
        , plotlyPythonPreamble :: Script
plotlyPythonPreamble= Script
forall a. Monoid a => a
mempty
        , plotlyRPreamble :: Script
plotlyRPreamble     = Script
forall a. Monoid a => a
mempty
        , matlabPreamble :: Script
matlabPreamble      = Script
forall a. Monoid a => a
mempty
        , mathematicaPreamble :: Script
mathematicaPreamble = Script
forall a. Monoid a => a
mempty
        , octavePreamble :: Script
octavePreamble      = Script
forall a. Monoid a => a
mempty
        , ggplot2Preamble :: Script
ggplot2Preamble     = Script
forall a. Monoid a => a
mempty
        , gnuplotPreamble :: Script
gnuplotPreamble     = Script
forall a. Monoid a => a
mempty
        , graphvizPreamble :: Script
graphvizPreamble    = Script
forall a. Monoid a => a
mempty

        , matplotlibExe :: FilePath
matplotlibExe       = if Bool
isWindows then "python" else "python3"
        , matlabExe :: FilePath
matlabExe           = "matlab"
        , plotlyPythonExe :: FilePath
plotlyPythonExe     = if Bool
isWindows then "python" else "python3"
        , plotlyRExe :: FilePath
plotlyRExe          = "Rscript"
        , mathematicaExe :: FilePath
mathematicaExe      = "math"
        , octaveExe :: FilePath
octaveExe           = "octave"
        , ggplot2Exe :: FilePath
ggplot2Exe          = "Rscript"
        , gnuplotExe :: FilePath
gnuplotExe          = "gnuplot"
        , graphvizExe :: FilePath
graphvizExe         = "dot"
        
        , matplotlibTightBBox :: Bool
matplotlibTightBBox   = Bool
False
        , matplotlibTransparent :: Bool
matplotlibTransparent = Bool
False
        }


-- | Extact path to configuration from the metadata in a Pandoc document.

-- The path to the configuration file should be under the @plot-configuration@ key.

-- In case there is no such metadata, return the default configuration.

--

-- For example, at the top of a markdown file:

--

-- @

--     ---

--     title: My document

--     author: John Doe

--     plot-configuration: /path/to/file.yml

--     ---     

-- @

--

-- The same can be specified via the command line using Pandoc's @-M@ flag:

--

-- > pandoc --filter pandoc-plot -M plot-configuration="path/to/file.yml" ...

--

-- @since 0.6.0.0

configurationPathMeta :: Pandoc -> Maybe FilePath
configurationPathMeta :: Pandoc -> Maybe FilePath
configurationPathMeta (Pandoc meta :: Meta
meta _) = 
        Script -> Meta -> Maybe MetaValue
lookupMeta "plot-configuration" Meta
meta Maybe MetaValue -> (MetaValue -> Maybe FilePath) -> Maybe FilePath
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MetaValue -> Maybe FilePath
getPath
    where
        getPath :: MetaValue -> Maybe FilePath
getPath (MetaString s :: Script
s) = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just (Script -> FilePath
unpack Script
s)
        getPath _              = Maybe FilePath
forall a. Maybe a
Nothing


-- We define a precursor type because preambles are best specified as file paths,

-- but we want to read those files before building a full

-- @Configuration@ value.

data ConfigPrecursor = ConfigPrecursor
    { ConfigPrecursor -> FilePath
_defaultDirectory  :: !FilePath    -- ^ The default directory where figures will be saved.

    , ConfigPrecursor -> Bool
_defaultWithSource :: !Bool        -- ^ The default behavior of whether or not to include links to source code and high-res

    , ConfigPrecursor -> Int
_defaultDPI        :: !Int         -- ^ The default dots-per-inch value for generated figures. Renderers might ignore this.

    , ConfigPrecursor -> SaveFormat
_defaultSaveFormat :: !SaveFormat  -- ^ The default save format of generated figures.

    , ConfigPrecursor -> Format
_captionFormat     :: !Format      -- ^ Caption format in Pandoc notation, e.g. "markdown+tex_math_dollars".

    
    , ConfigPrecursor -> LoggingPrecursor
_logPrec           :: !LoggingPrecursor

    , ConfigPrecursor -> MatplotlibPrecursor
_matplotlibPrec    :: !MatplotlibPrecursor
    , ConfigPrecursor -> MatlabPrecursor
_matlabPrec        :: !MatlabPrecursor
    , ConfigPrecursor -> PlotlyPythonPrecursor
_plotlyPythonPrec  :: !PlotlyPythonPrecursor
    , ConfigPrecursor -> PlotlyRPrecursor
_plotlyRPrec       :: !PlotlyRPrecursor
    , ConfigPrecursor -> MathematicaPrecursor
_mathematicaPrec   :: !MathematicaPrecursor
    , ConfigPrecursor -> OctavePrecursor
_octavePrec        :: !OctavePrecursor
    , ConfigPrecursor -> GGPlot2Precursor
_ggplot2Prec       :: !GGPlot2Precursor
    , ConfigPrecursor -> GNUPlotPrecursor
_gnuplotPrec       :: !GNUPlotPrecursor
    , ConfigPrecursor -> GraphvizPrecursor
_graphvizPrec      :: !GraphvizPrecursor
    }

defaultConfigPrecursor :: ConfigPrecursor
defaultConfigPrecursor :: ConfigPrecursor
defaultConfigPrecursor =  
    $WConfigPrecursor :: FilePath
-> Bool
-> Int
-> SaveFormat
-> Format
-> LoggingPrecursor
-> MatplotlibPrecursor
-> MatlabPrecursor
-> PlotlyPythonPrecursor
-> PlotlyRPrecursor
-> MathematicaPrecursor
-> OctavePrecursor
-> GGPlot2Precursor
-> GNUPlotPrecursor
-> GraphvizPrecursor
-> ConfigPrecursor
ConfigPrecursor
        { _defaultDirectory :: FilePath
_defaultDirectory  = Configuration -> FilePath
defaultDirectory Configuration
defaultConfiguration
        , _defaultWithSource :: Bool
_defaultWithSource = Configuration -> Bool
defaultWithSource Configuration
defaultConfiguration
        , _defaultDPI :: Int
_defaultDPI        = Configuration -> Int
defaultDPI Configuration
defaultConfiguration
        , _defaultSaveFormat :: SaveFormat
_defaultSaveFormat = Configuration -> SaveFormat
defaultSaveFormat Configuration
defaultConfiguration
        , _captionFormat :: Format
_captionFormat     = Configuration -> Format
captionFormat Configuration
defaultConfiguration

        , _logPrec :: LoggingPrecursor
_logPrec           = Verbosity -> Maybe FilePath -> LoggingPrecursor
LoggingPrecursor (Configuration -> Verbosity
logVerbosity Configuration
defaultConfiguration) Maybe FilePath
forall a. Maybe a
Nothing -- _logFilePath=Nothing implies log to stderr

        
        , _matplotlibPrec :: MatplotlibPrecursor
_matplotlibPrec    = Maybe FilePath -> Bool -> Bool -> FilePath -> MatplotlibPrecursor
MatplotlibPrecursor Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> Bool
matplotlibTightBBox Configuration
defaultConfiguration) (Configuration -> Bool
matplotlibTransparent Configuration
defaultConfiguration) (Configuration -> FilePath
matplotlibExe Configuration
defaultConfiguration)
        , _matlabPrec :: MatlabPrecursor
_matlabPrec        = Maybe FilePath -> FilePath -> MatlabPrecursor
MatlabPrecursor Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
matlabExe Configuration
defaultConfiguration)
        , _plotlyPythonPrec :: PlotlyPythonPrecursor
_plotlyPythonPrec  = Maybe FilePath -> FilePath -> PlotlyPythonPrecursor
PlotlyPythonPrecursor Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
plotlyPythonExe Configuration
defaultConfiguration)
        , _plotlyRPrec :: PlotlyRPrecursor
_plotlyRPrec       = Maybe FilePath -> FilePath -> PlotlyRPrecursor
PlotlyRPrecursor      Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
plotlyRExe Configuration
defaultConfiguration)
        , _mathematicaPrec :: MathematicaPrecursor
_mathematicaPrec   = Maybe FilePath -> FilePath -> MathematicaPrecursor
MathematicaPrecursor  Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
mathematicaExe Configuration
defaultConfiguration)
        , _octavePrec :: OctavePrecursor
_octavePrec        = Maybe FilePath -> FilePath -> OctavePrecursor
OctavePrecursor       Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
octaveExe Configuration
defaultConfiguration)
        , _ggplot2Prec :: GGPlot2Precursor
_ggplot2Prec       = Maybe FilePath -> FilePath -> GGPlot2Precursor
GGPlot2Precursor      Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
ggplot2Exe Configuration
defaultConfiguration)
        , _gnuplotPrec :: GNUPlotPrecursor
_gnuplotPrec       = Maybe FilePath -> FilePath -> GNUPlotPrecursor
GNUPlotPrecursor      Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
gnuplotExe Configuration
defaultConfiguration)
        , _graphvizPrec :: GraphvizPrecursor
_graphvizPrec      = Maybe FilePath -> FilePath -> GraphvizPrecursor
GraphvizPrecursor     Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
graphvizExe Configuration
defaultConfiguration)
        }


data LoggingPrecursor = LoggingPrecursor { LoggingPrecursor -> Verbosity
_logVerbosity :: !Verbosity
                                         , LoggingPrecursor -> Maybe FilePath
_logFilePath  :: !(Maybe FilePath)
                                         }

-- Separate YAML clauses have their own types.

data MatplotlibPrecursor = MatplotlibPrecursor
        { MatplotlibPrecursor -> Maybe FilePath
_matplotlibPreamble    :: !(Maybe FilePath)
        , MatplotlibPrecursor -> Bool
_matplotlibTightBBox   :: !Bool
        , MatplotlibPrecursor -> Bool
_matplotlibTransparent :: !Bool
        , MatplotlibPrecursor -> FilePath
_matplotlibExe         :: !FilePath
        }
data MatlabPrecursor        = MatlabPrecursor       {MatlabPrecursor -> Maybe FilePath
_matlabPreamble       :: !(Maybe FilePath), MatlabPrecursor -> FilePath
_matlabExe       :: !FilePath}
data PlotlyPythonPrecursor  = PlotlyPythonPrecursor {PlotlyPythonPrecursor -> Maybe FilePath
_plotlyPythonPreamble :: !(Maybe FilePath), PlotlyPythonPrecursor -> FilePath
_plotlyPythonExe :: !FilePath}
data PlotlyRPrecursor       = PlotlyRPrecursor      {PlotlyRPrecursor -> Maybe FilePath
_plotlyRPreamble      :: !(Maybe FilePath), PlotlyRPrecursor -> FilePath
_plotlyRExe      :: !FilePath}
data MathematicaPrecursor   = MathematicaPrecursor  {MathematicaPrecursor -> Maybe FilePath
_mathematicaPreamble  :: !(Maybe FilePath), MathematicaPrecursor -> FilePath
_mathematicaExe  :: !FilePath}
data OctavePrecursor        = OctavePrecursor       {OctavePrecursor -> Maybe FilePath
_octavePreamble       :: !(Maybe FilePath), OctavePrecursor -> FilePath
_octaveExe       :: !FilePath}
data GGPlot2Precursor       = GGPlot2Precursor      {GGPlot2Precursor -> Maybe FilePath
_ggplot2Preamble      :: !(Maybe FilePath), GGPlot2Precursor -> FilePath
_ggplot2Exe      :: !FilePath}
data GNUPlotPrecursor       = GNUPlotPrecursor      {GNUPlotPrecursor -> Maybe FilePath
_gnuplotPreamble      :: !(Maybe FilePath), GNUPlotPrecursor -> FilePath
_gnuplotExe      :: !FilePath}
data GraphvizPrecursor      = GraphvizPrecursor     {GraphvizPrecursor -> Maybe FilePath
_graphvizPreamble     :: !(Maybe FilePath), GraphvizPrecursor -> FilePath
_graphvizExe     :: !FilePath}

instance FromJSON LoggingPrecursor where
    parseJSON :: Value -> Parser LoggingPrecursor
parseJSON (Object v :: Object
v) = 
        Verbosity -> Maybe FilePath -> LoggingPrecursor
LoggingPrecursor (Verbosity -> Maybe FilePath -> LoggingPrecursor)
-> Parser Verbosity -> Parser (Maybe FilePath -> LoggingPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe Verbosity)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? "verbosity" Parser (Maybe Verbosity) -> Verbosity -> Parser Verbosity
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> Verbosity
logVerbosity Configuration
defaultConfiguration)
                         Parser (Maybe FilePath -> LoggingPrecursor)
-> Parser (Maybe FilePath) -> Parser LoggingPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? "filepath"
    parseJSON _ = FilePath -> Parser LoggingPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser LoggingPrecursor)
-> FilePath -> Parser LoggingPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat ["Could not parse logging configuration. "]

instance FromJSON MatplotlibPrecursor where
    parseJSON :: Value -> Parser MatplotlibPrecursor
parseJSON (Object v :: Object
v) = 
        Maybe FilePath -> Bool -> Bool -> FilePath -> MatplotlibPrecursor
MatplotlibPrecursor
            (Maybe FilePath -> Bool -> Bool -> FilePath -> MatplotlibPrecursor)
-> Parser (Maybe FilePath)
-> Parser (Bool -> Bool -> FilePath -> MatplotlibPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK)
            Parser (Bool -> Bool -> FilePath -> MatplotlibPrecursor)
-> Parser Bool -> Parser (Bool -> FilePath -> MatplotlibPrecursor)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
MatplotlibTightBBoxK)   Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> Bool
matplotlibTightBBox Configuration
defaultConfiguration) 
            Parser (Bool -> FilePath -> MatplotlibPrecursor)
-> Parser Bool -> Parser (FilePath -> MatplotlibPrecursor)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
MatplotlibTransparentK) Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> Bool
matplotlibTransparent Configuration
defaultConfiguration)
            Parser (FilePath -> MatplotlibPrecursor)
-> Parser FilePath -> Parser MatplotlibPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK)  Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
matplotlibExe Configuration
defaultConfiguration)
    parseJSON _ = FilePath -> Parser MatplotlibPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser MatplotlibPrecursor)
-> FilePath -> Parser MatplotlibPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat ["Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Matplotlib, " configuration."]

instance FromJSON MatlabPrecursor where
    parseJSON :: Value -> Parser MatlabPrecursor
parseJSON (Object v :: Object
v) = Maybe FilePath -> FilePath -> MatlabPrecursor
MatlabPrecursor (Maybe FilePath -> FilePath -> MatlabPrecursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> MatlabPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> MatlabPrecursor)
-> Parser FilePath -> Parser MatlabPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
matlabExe Configuration
defaultConfiguration)
    parseJSON _ = FilePath -> Parser MatlabPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser MatlabPrecursor)
-> FilePath -> Parser MatlabPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat ["Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Matlab, " configuration."]

instance FromJSON PlotlyPythonPrecursor where
    parseJSON :: Value -> Parser PlotlyPythonPrecursor
parseJSON (Object v :: Object
v) = Maybe FilePath -> FilePath -> PlotlyPythonPrecursor
PlotlyPythonPrecursor (Maybe FilePath -> FilePath -> PlotlyPythonPrecursor)
-> Parser (Maybe FilePath)
-> Parser (FilePath -> PlotlyPythonPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> PlotlyPythonPrecursor)
-> Parser FilePath -> Parser PlotlyPythonPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
plotlyPythonExe Configuration
defaultConfiguration)
    parseJSON _ = FilePath -> Parser PlotlyPythonPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser PlotlyPythonPrecursor)
-> FilePath -> Parser PlotlyPythonPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat ["Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
PlotlyPython, " configuration."]

instance FromJSON PlotlyRPrecursor where
    parseJSON :: Value -> Parser PlotlyRPrecursor
parseJSON (Object v :: Object
v) = Maybe FilePath -> FilePath -> PlotlyRPrecursor
PlotlyRPrecursor (Maybe FilePath -> FilePath -> PlotlyRPrecursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> PlotlyRPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> PlotlyRPrecursor)
-> Parser FilePath -> Parser PlotlyRPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
plotlyRExe Configuration
defaultConfiguration)
    parseJSON _ = FilePath -> Parser PlotlyRPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser PlotlyRPrecursor)
-> FilePath -> Parser PlotlyRPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat ["Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
PlotlyR, " configuration."]

instance FromJSON MathematicaPrecursor where
    parseJSON :: Value -> Parser MathematicaPrecursor
parseJSON (Object v :: Object
v) = Maybe FilePath -> FilePath -> MathematicaPrecursor
MathematicaPrecursor (Maybe FilePath -> FilePath -> MathematicaPrecursor)
-> Parser (Maybe FilePath)
-> Parser (FilePath -> MathematicaPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> MathematicaPrecursor)
-> Parser FilePath -> Parser MathematicaPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
mathematicaExe Configuration
defaultConfiguration)
    parseJSON _ = FilePath -> Parser MathematicaPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser MathematicaPrecursor)
-> FilePath -> Parser MathematicaPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat ["Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Mathematica, " configuration."]

instance FromJSON OctavePrecursor where
    parseJSON :: Value -> Parser OctavePrecursor
parseJSON (Object v :: Object
v) = Maybe FilePath -> FilePath -> OctavePrecursor
OctavePrecursor (Maybe FilePath -> FilePath -> OctavePrecursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> OctavePrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> OctavePrecursor)
-> Parser FilePath -> Parser OctavePrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
octaveExe Configuration
defaultConfiguration)
    parseJSON _ = FilePath -> Parser OctavePrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser OctavePrecursor)
-> FilePath -> Parser OctavePrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat ["Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Octave, " configuration."]

instance FromJSON GGPlot2Precursor where
    parseJSON :: Value -> Parser GGPlot2Precursor
parseJSON (Object v :: Object
v) = Maybe FilePath -> FilePath -> GGPlot2Precursor
GGPlot2Precursor (Maybe FilePath -> FilePath -> GGPlot2Precursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> GGPlot2Precursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> GGPlot2Precursor)
-> Parser FilePath -> Parser GGPlot2Precursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
ggplot2Exe Configuration
defaultConfiguration)
    parseJSON _ = FilePath -> Parser GGPlot2Precursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser GGPlot2Precursor)
-> FilePath -> Parser GGPlot2Precursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat ["Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
GGPlot2, " configuration."]

instance FromJSON GNUPlotPrecursor where
    parseJSON :: Value -> Parser GNUPlotPrecursor
parseJSON (Object v :: Object
v) = Maybe FilePath -> FilePath -> GNUPlotPrecursor
GNUPlotPrecursor (Maybe FilePath -> FilePath -> GNUPlotPrecursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> GNUPlotPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> GNUPlotPrecursor)
-> Parser FilePath -> Parser GNUPlotPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
gnuplotExe Configuration
defaultConfiguration)
    parseJSON _ = FilePath -> Parser GNUPlotPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser GNUPlotPrecursor)
-> FilePath -> Parser GNUPlotPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat ["Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
GNUPlot, " configuration."]

instance FromJSON GraphvizPrecursor where
    parseJSON :: Value -> Parser GraphvizPrecursor
parseJSON (Object v :: Object
v) = Maybe FilePath -> FilePath -> GraphvizPrecursor
GraphvizPrecursor (Maybe FilePath -> FilePath -> GraphvizPrecursor)
-> Parser (Maybe FilePath)
-> Parser (FilePath -> GraphvizPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> GraphvizPrecursor)
-> Parser FilePath -> Parser GraphvizPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
graphvizExe Configuration
defaultConfiguration)
    parseJSON _ = FilePath -> Parser GraphvizPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser GraphvizPrecursor)
-> FilePath -> Parser GraphvizPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat ["Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Graphviz, " configuration."]


instance FromJSON ConfigPrecursor where
    parseJSON :: Value -> Parser ConfigPrecursor
parseJSON (Value
Null) = ConfigPrecursor -> Parser ConfigPrecursor
forall (m :: * -> *) a. Monad m => a -> m a
return ConfigPrecursor
defaultConfigPrecursor -- In case of empty file

    parseJSON (Object v :: Object
v) = do
        
        FilePath
_defaultDirectory  <- Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
DirectoryK)     Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (ConfigPrecursor -> FilePath
_defaultDirectory ConfigPrecursor
defaultConfigPrecursor)
        Bool
_defaultWithSource <- Object
v Object -> Script -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
WithSourceK)    Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= (ConfigPrecursor -> Bool
_defaultWithSource ConfigPrecursor
defaultConfigPrecursor)
        Int
_defaultDPI        <- Object
v Object -> Script -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
DpiK)           Parser (Maybe Int) -> Int -> Parser Int
forall a. Parser (Maybe a) -> a -> Parser a
.!= (ConfigPrecursor -> Int
_defaultDPI ConfigPrecursor
defaultConfigPrecursor)
        SaveFormat
_defaultSaveFormat <- Object
v Object -> Script -> Parser (Maybe SaveFormat)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
SaveFormatK)    Parser (Maybe SaveFormat) -> SaveFormat -> Parser SaveFormat
forall a. Parser (Maybe a) -> a -> Parser a
.!= (ConfigPrecursor -> SaveFormat
_defaultSaveFormat ConfigPrecursor
defaultConfigPrecursor)
        Format
_captionFormat     <- Object
v Object -> Script -> Parser (Maybe Format)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
CaptionFormatK) Parser (Maybe Format) -> Format -> Parser Format
forall a. Parser (Maybe a) -> a -> Parser a
.!= (ConfigPrecursor -> Format
_captionFormat ConfigPrecursor
defaultConfigPrecursor)

        LoggingPrecursor
_logPrec           <- Object
v Object -> Script -> Parser (Maybe LoggingPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? "logging"              Parser (Maybe LoggingPrecursor)
-> LoggingPrecursor -> Parser LoggingPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> LoggingPrecursor
_logPrec ConfigPrecursor
defaultConfigPrecursor

        MatplotlibPrecursor
_matplotlibPrec    <- Object
v Object -> Script -> Parser (Maybe MatplotlibPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Matplotlib)       Parser (Maybe MatplotlibPrecursor)
-> MatplotlibPrecursor -> Parser MatplotlibPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> MatplotlibPrecursor
_matplotlibPrec ConfigPrecursor
defaultConfigPrecursor
        MatlabPrecursor
_matlabPrec        <- Object
v Object -> Script -> Parser (Maybe MatlabPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Matlab)           Parser (Maybe MatlabPrecursor)
-> MatlabPrecursor -> Parser MatlabPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> MatlabPrecursor
_matlabPrec ConfigPrecursor
defaultConfigPrecursor
        PlotlyPythonPrecursor
_plotlyPythonPrec  <- Object
v Object -> Script -> Parser (Maybe PlotlyPythonPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
PlotlyPython)     Parser (Maybe PlotlyPythonPrecursor)
-> PlotlyPythonPrecursor -> Parser PlotlyPythonPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> PlotlyPythonPrecursor
_plotlyPythonPrec ConfigPrecursor
defaultConfigPrecursor
        PlotlyRPrecursor
_plotlyRPrec       <- Object
v Object -> Script -> Parser (Maybe PlotlyRPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
PlotlyR)          Parser (Maybe PlotlyRPrecursor)
-> PlotlyRPrecursor -> Parser PlotlyRPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> PlotlyRPrecursor
_plotlyRPrec ConfigPrecursor
defaultConfigPrecursor
        MathematicaPrecursor
_mathematicaPrec   <- Object
v Object -> Script -> Parser (Maybe MathematicaPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Mathematica)      Parser (Maybe MathematicaPrecursor)
-> MathematicaPrecursor -> Parser MathematicaPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> MathematicaPrecursor
_mathematicaPrec ConfigPrecursor
defaultConfigPrecursor
        OctavePrecursor
_octavePrec        <- Object
v Object -> Script -> Parser (Maybe OctavePrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Octave)           Parser (Maybe OctavePrecursor)
-> OctavePrecursor -> Parser OctavePrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> OctavePrecursor
_octavePrec ConfigPrecursor
defaultConfigPrecursor
        GGPlot2Precursor
_ggplot2Prec       <- Object
v Object -> Script -> Parser (Maybe GGPlot2Precursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
GGPlot2)          Parser (Maybe GGPlot2Precursor)
-> GGPlot2Precursor -> Parser GGPlot2Precursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> GGPlot2Precursor
_ggplot2Prec ConfigPrecursor
defaultConfigPrecursor
        GNUPlotPrecursor
_gnuplotPrec       <- Object
v Object -> Script -> Parser (Maybe GNUPlotPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
GNUPlot)          Parser (Maybe GNUPlotPrecursor)
-> GNUPlotPrecursor -> Parser GNUPlotPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> GNUPlotPrecursor
_gnuplotPrec ConfigPrecursor
defaultConfigPrecursor
        GraphvizPrecursor
_graphvizPrec      <- Object
v Object -> Script -> Parser (Maybe GraphvizPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Graphviz)         Parser (Maybe GraphvizPrecursor)
-> GraphvizPrecursor -> Parser GraphvizPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> GraphvizPrecursor
_graphvizPrec ConfigPrecursor
defaultConfigPrecursor

        ConfigPrecursor -> Parser ConfigPrecursor
forall (m :: * -> *) a. Monad m => a -> m a
return (ConfigPrecursor -> Parser ConfigPrecursor)
-> ConfigPrecursor -> Parser ConfigPrecursor
forall a b. (a -> b) -> a -> b
$ $WConfigPrecursor :: FilePath
-> Bool
-> Int
-> SaveFormat
-> Format
-> LoggingPrecursor
-> MatplotlibPrecursor
-> MatlabPrecursor
-> PlotlyPythonPrecursor
-> PlotlyRPrecursor
-> MathematicaPrecursor
-> OctavePrecursor
-> GGPlot2Precursor
-> GNUPlotPrecursor
-> GraphvizPrecursor
-> ConfigPrecursor
ConfigPrecursor{..}
    parseJSON _          = FilePath -> Parser ConfigPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail "Could not parse configuration."


renderConfig :: ConfigPrecursor -> IO Configuration
renderConfig :: ConfigPrecursor -> IO Configuration
renderConfig ConfigPrecursor{..} = do
    let defaultDirectory :: FilePath
defaultDirectory  = FilePath
_defaultDirectory
        defaultWithSource :: Bool
defaultWithSource = Bool
_defaultWithSource
        defaultDPI :: Int
defaultDPI        = Int
_defaultDPI
        defaultSaveFormat :: SaveFormat
defaultSaveFormat = SaveFormat
_defaultSaveFormat
        captionFormat :: Format
captionFormat     = Format
_captionFormat

        logVerbosity :: Verbosity
logVerbosity = LoggingPrecursor -> Verbosity
_logVerbosity LoggingPrecursor
_logPrec
        logSink :: LogSink
logSink      = LogSink -> (FilePath -> LogSink) -> Maybe FilePath -> LogSink
forall b a. b -> (a -> b) -> Maybe a -> b
maybe LogSink
StdErr FilePath -> LogSink
LogFile (LoggingPrecursor -> Maybe FilePath
_logFilePath LoggingPrecursor
_logPrec)

        matplotlibTightBBox :: Bool
matplotlibTightBBox   = MatplotlibPrecursor -> Bool
_matplotlibTightBBox MatplotlibPrecursor
_matplotlibPrec
        matplotlibTransparent :: Bool
matplotlibTransparent = MatplotlibPrecursor -> Bool
_matplotlibTransparent MatplotlibPrecursor
_matplotlibPrec

        matplotlibExe :: FilePath
matplotlibExe   = MatplotlibPrecursor -> FilePath
_matplotlibExe MatplotlibPrecursor
_matplotlibPrec
        matlabExe :: FilePath
matlabExe       = MatlabPrecursor -> FilePath
_matlabExe MatlabPrecursor
_matlabPrec
        plotlyPythonExe :: FilePath
plotlyPythonExe = PlotlyPythonPrecursor -> FilePath
_plotlyPythonExe PlotlyPythonPrecursor
_plotlyPythonPrec
        plotlyRExe :: FilePath
plotlyRExe      = PlotlyRPrecursor -> FilePath
_plotlyRExe PlotlyRPrecursor
_plotlyRPrec
        mathematicaExe :: FilePath
mathematicaExe  = MathematicaPrecursor -> FilePath
_mathematicaExe MathematicaPrecursor
_mathematicaPrec
        octaveExe :: FilePath
octaveExe       = OctavePrecursor -> FilePath
_octaveExe OctavePrecursor
_octavePrec
        ggplot2Exe :: FilePath
ggplot2Exe      = GGPlot2Precursor -> FilePath
_ggplot2Exe GGPlot2Precursor
_ggplot2Prec
        gnuplotExe :: FilePath
gnuplotExe      = GNUPlotPrecursor -> FilePath
_gnuplotExe GNUPlotPrecursor
_gnuplotPrec
        graphvizExe :: FilePath
graphvizExe     = GraphvizPrecursor -> FilePath
_graphvizExe GraphvizPrecursor
_graphvizPrec
    
    Script
matplotlibPreamble   <- Maybe FilePath -> IO Script
readPreamble (MatplotlibPrecursor -> Maybe FilePath
_matplotlibPreamble MatplotlibPrecursor
_matplotlibPrec)
    Script
matlabPreamble       <- Maybe FilePath -> IO Script
readPreamble (MatlabPrecursor -> Maybe FilePath
_matlabPreamble MatlabPrecursor
_matlabPrec)
    Script
plotlyPythonPreamble <- Maybe FilePath -> IO Script
readPreamble (PlotlyPythonPrecursor -> Maybe FilePath
_plotlyPythonPreamble PlotlyPythonPrecursor
_plotlyPythonPrec)
    Script
plotlyRPreamble      <- Maybe FilePath -> IO Script
readPreamble (PlotlyRPrecursor -> Maybe FilePath
_plotlyRPreamble PlotlyRPrecursor
_plotlyRPrec)
    Script
mathematicaPreamble  <- Maybe FilePath -> IO Script
readPreamble (MathematicaPrecursor -> Maybe FilePath
_mathematicaPreamble MathematicaPrecursor
_mathematicaPrec)
    Script
octavePreamble       <- Maybe FilePath -> IO Script
readPreamble (OctavePrecursor -> Maybe FilePath
_octavePreamble OctavePrecursor
_octavePrec)
    Script
ggplot2Preamble      <- Maybe FilePath -> IO Script
readPreamble (GGPlot2Precursor -> Maybe FilePath
_ggplot2Preamble GGPlot2Precursor
_ggplot2Prec)
    Script
gnuplotPreamble      <- Maybe FilePath -> IO Script
readPreamble (GNUPlotPrecursor -> Maybe FilePath
_gnuplotPreamble GNUPlotPrecursor
_gnuplotPrec)
    Script
graphvizPreamble     <- Maybe FilePath -> IO Script
readPreamble (GraphvizPrecursor -> Maybe FilePath
_graphvizPreamble GraphvizPrecursor
_graphvizPrec)

    Configuration -> IO Configuration
forall (m :: * -> *) a. Monad m => a -> m a
return $WConfiguration :: FilePath
-> Bool
-> Int
-> SaveFormat
-> Format
-> Verbosity
-> LogSink
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> Bool
-> Bool
-> Configuration
Configuration{..}
    where
        readPreamble :: Maybe FilePath -> IO Script
readPreamble fp :: Maybe FilePath
fp = IO Script -> Maybe (IO Script) -> IO Script
forall a. a -> Maybe a -> a
fromMaybe IO Script
forall a. Monoid a => a
mempty (Maybe (IO Script) -> IO Script) -> Maybe (IO Script) -> IO Script
forall a b. (a -> b) -> a -> b
$ FilePath -> IO Script
TIO.readFile (FilePath -> IO Script) -> Maybe FilePath -> Maybe (IO Script)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe FilePath
fp


tshow :: Show a => a -> Text
tshow :: a -> Script
tshow = FilePath -> Script
pack (FilePath -> Script) -> (a -> FilePath) -> a -> Script
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> FilePath
forall a. Show a => a -> FilePath
show