Commit 2415aefd authored by Andrew Gibiansky's avatar Andrew Gibiansky

closes #142

parent 268bf239
......@@ -30,9 +30,7 @@ instance IHaskellDisplay (Renderable a) where
chartData :: Renderable a -> FileFormat -> IO DisplayData
chartData renderable format = do
-- Switch to a temporary directory so that any files we create aren't
-- visible. On Unix, this is usually /tmp.
try (getTemporaryDirectory >>= setCurrentDirectory) :: IO (Either SomeException ())
switchToTmpDir
-- Write the PNG image.
let filename = ".ihaskell-chart.png"
......
......@@ -20,9 +20,7 @@ instance IHaskellDisplay (Diagram Cairo R2) where
diagramData :: Diagram Cairo R2 -> OutputType -> IO DisplayData
diagramData renderable format = do
-- Switch to a temporary directory so that any files we create aren't
-- visible. On Unix, this is usually /tmp.
try (getTemporaryDirectory >>= setCurrentDirectory) :: IO (Either SomeException ())
switchToTmpDir
-- Compute width and height.
let w = width renderable
......
......@@ -29,9 +29,8 @@ instance IHaskellDisplay (Image PixelCMYK16) where display = displayImageAsJpg .
-- main rendering function
displayImageAsJpg :: DynamicImage -> IO Display
displayImageAsJpg renderable = do
-- Switch to a temporary directory so that any files we create aren't
-- visible. On Unix, this is usually /tmp.
try (getTemporaryDirectory >>= setCurrentDirectory) :: IO (Either SomeException ())
switchToTmpDir
let filename = ".ihaskell.juicypixels.jpg"
-- Write the image
saveJpgImage 95 filename renderable
......
......@@ -91,7 +91,8 @@ library
stm -any,
text -any,
utf8-string -any,
vector -any
vector -any,
temporary ==1.2.*
exposed-modules: IHaskell.Display
IHaskell.Convert
......
......@@ -9,6 +9,7 @@ module IHaskell.Display (
Display(..),
DisplayData(..),
printDisplay,
switchToTmpDir,
-- Internal only use
displayFromChan,
......@@ -23,6 +24,10 @@ import qualified Data.ByteString.Base64 as Base64
import qualified Data.ByteString.Char8 as Char
import Data.Aeson (Value)
import System.Directory(getTemporaryDirectory, setCurrentDirectory)
import System.IO.Temp(createTempDirectory)
import Control.Concurrent.STM.TChan
import System.IO.Unsafe (unsafePerformIO)
......@@ -122,3 +127,14 @@ unfoldM f = maybe (return []) (\r -> (r:) <$> unfoldM f) =<< f
-- notebook once the current execution call ends.
printDisplay :: IHaskellDisplay a => a -> IO ()
printDisplay disp = display disp >>= atomically . writeTChan displayChan
-- | Convenience function for client libraries. Switch to a temporary
-- directory so that any files we create aren't visible. On Unix, this is
-- usually /tmp.
switchToTmpDir = void (try switchDir :: IO (Either SomeException ()))
where
switchDir =
getTemporaryDirectory >>=
flip createTempDirectory "ihaskell-display-tmp" >>=
setCurrentDirectory
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment