module Text.Pandoc.Filter.Plot.Renderers.Prelude (
module Prelude
, module Text.Pandoc.Filter.Plot.Types
, Text
, st
, unpack
, commandSuccess
, existsOnPath
, executable
, OutputSpec(..)
) where
import Data.Maybe (isJust)
import Data.Text (Text, unpack)
import System.Directory (findExecutable)
import System.Exit (ExitCode(..))
import System.Process.Typed (runProcess, shell,
setStdout, setStderr,
nullStream)
import Text.Shakespeare.Text (st)
import qualified Turtle as Sh
import Text.Pandoc.Filter.Plot.Types
commandSuccess :: Text -> IO Bool
commandSuccess s = do
ec <- runProcess
$ setStdout nullStream
$ setStderr nullStream
$ shell (unpack s)
return $ ec == ExitSuccess
existsOnPath :: FilePath -> IO Bool
existsOnPath fp = Sh.which (Sh.fromString fp) >>= fmap isJust . return
tryToFindExe :: String -> IO FilePath
tryToFindExe fp = findExecutable fp >>= maybe (return fp) return
executable :: Toolkit -> Configuration -> IO FilePath
executable Matplotlib = tryToFindExe . matplotlibExe
executable PlotlyPython = tryToFindExe . plotlyPythonExe
executable PlotlyR = tryToFindExe . plotlyRExe
executable Matlab = tryToFindExe . matlabExe
executable Mathematica = tryToFindExe . mathematicaExe
executable Octave = tryToFindExe . octaveExe
executable GGPlot2 = tryToFindExe . ggplot2Exe
executable GNUPlot = tryToFindExe . gnuplotExe
executable Graphviz = tryToFindExe . graphvizExe
data OutputSpec = OutputSpec
{ oConfiguration :: Configuration
, oFigureSpec :: FigureSpec
, oScriptPath :: FilePath
, oFigurePath :: FilePath
}