1{-# LANGUAGE OverloadedStrings #-}
10 , getPackageCacheDirFor
21import Control.Concurrent (forkIO)
22import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
23import Control.Monad (forever, join, replicateM_)
24import Control.Monad.Except (ExceptT, runExceptT, throwError, withExceptT)
25import qualified Control.Monad.Reader as R
26import Control.Monad.Trans (liftIO)
27import qualified Network.HTTP.Client as Http
28import qualified Network.HTTP.Client.TLS as Http
29import qualified System.Directory as Dir
30import qualified System.Exit as Exit
31import System.FilePath ((</>))
33import qualified Elm.Package as Pkg
34import qualified Elm.PerUserCache as PerUserCache
35import qualified Elm.Version as V
36import qualified Reporting.Doc as D
37import qualified Reporting.Exit as Exit
38import qualified Reporting.Progress as Progress
50 ExceptT e (R.ReaderT Env IO)
55 { _cacheDir :: FilePath
56 , _worker :: IO () -> IO ()
57 , _httpManager :: Http.Manager
58 , _tell :: Progress.Progress -> IO ()
59 , _ask :: D.Doc -> IO Bool
63try :: Progress.Reporter -> Task a -> IO (Maybe a)
64try (Progress.Reporter tell ask end) task =
65 do root <- PerUserCache.getPackageRoot
67 httpManager <- Http.newManager Http.tlsManagerSettings
68 let env = Env root pool httpManager tell ask
69 result <- R.runReaderT (runExceptT task) env
80run :: Progress.Reporter -> Task a -> IO ()
82 do maybeAnswer <- try reporter task
84 Nothing -> Exit.exitFailure
88throw :: e -> Task_ e a
93mapError :: (x -> y) -> Task_ x a -> Task_ y a
102getPackageCacheDir :: Task_ e FilePath
107getPackageCacheDirFor :: Pkg.Name -> V.Version -> Task_ e FilePath
108getPackageCacheDirFor name version =
109 do cacheDir <- getPackageCacheDir
110 let dir = cacheDir </> Pkg.toFilePath name </> V.toChars version
111 liftIO (Dir.createDirectoryIfMissing True dir)
119report :: Progress.Progress -> Task_ e ()
121 do tell <- R.asks _tell
122 liftIO (tell progress)
125getReporter :: Task (Progress.Progress -> IO ())
134getApproval :: D.Doc -> Task_ e Bool
136 do ask <- R.asks _ask
144silently :: Task_ e a -> Task_ e a
146 do runner <- getSilentRunner
147 result <- liftIO (runner task)
148 either throw return result
151getSilentRunner :: Task_ x (Task_ e a -> IO (Either e a))
154 let silentEnv = env { _tell = \_ -> return () }
155 return $ \task -> R.runReaderT (runExceptT task) silentEnv
162workerChan :: Chan (Either e a) -> Task_ e a -> Task_ x ()
163workerChan chan task =
166 liftIO $ _worker env $
167 do result <- R.runReaderT (runExceptT task) env
168 writeChan chan result
171initPool :: Int -> IO (IO () -> IO ())
175 replicateM_ size $ forkIO $ forever $
178 return $ writeChan chan
185runHttp :: (Http.Manager -> (Progress.Progress -> IO ()) -> IO (Either Exit.Exit a)) -> Task a
187 do (Env _ _ manager tell _) <- R.ask
188 result <- liftIO $ fetcher manager tell
189 either throwError return result
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