module Reanimate.Driver.Magick
  ( magickCmd
  ) where

import System.IO.Unsafe (unsafePerformIO)
import System.Directory (findExecutable)

{-# NOINLINE magickCmd #-}
-- |The name of the ImageMagick command. On Unix-like operating systems, the
-- command \'convert\' does not conflict with the name of other commands. On
-- Windows, ImageMagick version 7 is readily available, the command \'magick\'
-- should be present, and is preferred over \'convert\'. If it is not present,
-- \'convert\' is assumed to be the relevant command.
magickCmd :: String
-- The use of 'unsafeperformIO' is justified on the basis that if \'magick\' is
-- found once, it will always be present.
magickCmd :: String
magickCmd = IO String -> String
forall a. IO a -> a
unsafePerformIO (IO String -> String) -> IO String -> String
forall a b. (a -> b) -> a -> b
$ do
  Maybe String
mPath <- String -> IO (Maybe String)
findExecutable String
"magick"
  String -> IO String
forall (f :: * -> *) a. Applicative f => a -> f a
pure (String -> IO String) -> String -> IO String
forall a b. (a -> b) -> a -> b
$ String -> (String -> String) -> Maybe String -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe String
"convert" (String -> String -> String
forall a b. a -> b -> a
const String
"magick") Maybe String
mPath