module Agda.Utils.IO.TempFile
( writeToTempFile
) where
import qualified Control.Exception as E
import qualified System.Directory as D
import qualified System.IO as IO
writeToTempFile :: String -> IO FilePath
writeToTempFile :: String -> IO String
writeToTempFile String
content = do
String
dir <- IO String
D.getTemporaryDirectory
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
E.bracket (String -> String -> IO (String, Handle)
IO.openTempFile String
dir String
"agda2-mode") (Handle -> IO ()
IO.hClose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) forall a b. (a -> b) -> a -> b
$ \ (String
filepath, Handle
handle) -> do
Handle -> TextEncoding -> IO ()
IO.hSetEncoding Handle
handle TextEncoding
IO.utf8
Handle -> String -> IO ()
IO.hPutStr Handle
handle String
content
forall (m :: * -> *) a. Monad m => a -> m a
return String
filepath