2module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows,
3 writeSource, writeSourceText, readSource,
6-- System helper functions.
7import Control.Monad (when)
8import qualified Data.Text as T
9import qualified Data.Text.IO as TIO
10import System.Directory (getTemporaryDirectory
12 , removeDirectoryRecursive
13 , createDirectoryIfMissing
16import System.FilePath ((</>), normalise, isAbsolute, dropFileName)
20import Control.Exception as CE
24import System.Environment (getEnv, setEnv, getExecutablePath)
27catchIO :: IO a -> (IOError -> IO a) -> IO a
30throwIO :: IOError -> IO a
34isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
36tempfile :: IO (FilePath, Handle)
37tempfile = do dir <- getTemporaryDirectory
38 openTempFile (normalise dir) "idris"
40-- | Read a source file, same as readFile but make sure the encoding is utf-8.
41readSource :: FilePath -> IO String
42readSource f = do h <- openFile f ReadMode
46-- | Write a source file, same as writeFile except the encoding is set to utf-8
47writeSource :: FilePath -> String -> IO ()
48writeSource f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> hPutStr h s)
50-- | Write a utf-8 source file from Text
51writeSourceText :: FilePath -> T.Text -> IO ()
52writeSourceText f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> TIO.hPutStr h s)
54withTempdir :: String -> (FilePath -> IO a) -> IO a
55withTempdir subdir callback
56 = do dir <- getTemporaryDirectory
57 let tmpDir = (normalise dir) </> subdir
58 removeLater <- catchIO (createDirectoryIfMissing True tmpDir >> return True)
59 (\ ioError -> if isAlreadyExistsError ioError then return False
62 result <- callback tmpDir
63 when removeLater $ removeDirectoryRecursive tmpDir
66rmFile :: FilePath -> IO ()
67rmFile f = do putStrLn $ "Removing " ++ f
68 catchIO (removeFile f)
69 (\ioerr -> putStrLn $ "WARNING: Cannot remove file "
70 ++ f ++ ", Error msg:" ++ show ioerr)
74setupBundledCC = when hasBundledToolchain
76 exePath <- getExecutablePath
78 tcDir <- return getToolchainDir
79 absolute <- return $ isAbsolute tcDir
83 else dropFileName exePath ++ tcDir
84 let pathSep = if isWindows then ";" else ":"
85 present <- doesDirectoryExist target
87 $ do newPath <- return $ target ++ pathSep ++ path
90setupBundledCC = return ()
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list