{-# 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 -> PlotM Text
octaveCommand :: OutputSpec -> PlotM Text
octaveCommand OutputSpec{..} = do
    FilePath
exe <- Toolkit -> PlotM FilePath
executable Toolkit
Octave
    Text -> PlotM Text
forall (m :: * -> *) a. Monad m => a -> m a
return [st|#{exe} --no-gui --no-window-system "#{oScriptPath}"|]


octaveAvailable :: PlotM Bool
octaveAvailable :: PlotM Bool
octaveAvailable = do
    FilePath
exe <- Toolkit -> PlotM FilePath
executable Toolkit
Octave
    Text -> PlotM Bool
commandSuccess [st|#{exe} -h|]


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