{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes       #-}
{-# 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

Rendering Octave plots code blocks
-}

module Text.Pandoc.Filter.Plot.Renderers.Octave (
      octaveSupportedSaveFormats
    , octaveCommand
    , octaveCapture
    , octaveAvailable
) where

import           Text.Pandoc.Filter.Plot.Renderers.Prelude


octaveSupportedSaveFormats :: [SaveFormat]
octaveSupportedSaveFormats :: [SaveFormat]
octaveSupportedSaveFormats = [SaveFormat
PNG, SaveFormat
PDF, SaveFormat
SVG, SaveFormat
JPG, SaveFormat
EPS, SaveFormat
GIF, SaveFormat
TIF]


octaveCommand :: OutputSpec -> Text -> Text
octaveCommand :: OutputSpec -> Text -> Text
octaveCommand OutputSpec{FilePath
FigureSpec
oFigurePath :: OutputSpec -> FilePath
oScriptPath :: OutputSpec -> FilePath
oFigureSpec :: OutputSpec -> FigureSpec
oFigurePath :: FilePath
oScriptPath :: FilePath
oFigureSpec :: FigureSpec
..} Text
exe = [st|#{exe} --no-gui --no-window-system "#{oScriptPath}"|]


octaveAvailable :: PlotM Bool
octaveAvailable :: PlotM Bool
octaveAvailable = do
    Maybe Executable
mexe <- Toolkit -> PlotM (Maybe Executable)
executable Toolkit
Octave
    case Maybe Executable
mexe of 
        Maybe Executable
Nothing -> Bool -> PlotM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
        Just (Executable FilePath
dir Text
exe) -> 
            FilePath -> Text -> PlotM Bool
commandSuccess FilePath
dir [st|#{exe} -h|]


octaveCapture :: FigureSpec -> FilePath -> Script
octaveCapture :: FigureSpec -> FilePath -> Text
octaveCapture = (FigureSpec -> FilePath -> Text) -> FigureSpec -> FilePath -> Text
appendCapture FigureSpec -> FilePath -> Text
octaveCaptureFragment


octaveCaptureFragment :: FigureSpec -> FilePath -> Script
octaveCaptureFragment :: FigureSpec -> FilePath -> Text
octaveCaptureFragment FigureSpec
_ FilePath
fname = [st|
saveas(gcf, '#{fname}')
|]