1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Progress.Terminal
9import Control.Concurrent (forkIO)
10import Control.Concurrent.Chan (Chan, newChan, readChan)
11import Control.Concurrent.MVar (newEmptyMVar, putMVar)
12import qualified System.Info as System
13import System.IO (hFlush, hPutStr, stdout)
14import qualified Elm.Package as Pkg
15import Elm.Package (Name, Version)
17import qualified Deps.Diff as Diff
18import Reporting.Doc ((<>), (<+>))
19import qualified Reporting.Doc as D
20import qualified Reporting.Exit as Exit
21import qualified Reporting.Exit.Help as Help
22import Reporting.Progress (Msg(..), Progress(..), Outcome(..), PublishPhase(..), BumpPhase(..))
23import qualified Reporting.Progress as Progress
24import qualified Reporting.Progress.Bar as Bar
31create :: IO Progress.Reporter
35 _ <- forkIO (loop chan (State 0 0 0) >>= putMVar mvar)
36 return (Progress.makeReporter chan mvar)
55loop :: Chan Msg -> State -> IO ()
57 do msg <- readChan chan
66 loopHelp chan progress state
69loopHelp :: Chan Msg -> Progress -> State -> IO ()
70loopHelp chan progress state@(State total good bad) =
77 do putStrLn "Dependencies loaded from local cache."
84 do putStrLn "Starting downloads...\n"
87 DownloadPkgStart _name _version ->
90 DownloadPkgEnd name version outcome ->
91 do Help.toStdout (makeBullet name version outcome)
105 BuildDepsStart size ->
106 do hPutStr stdout "Verifying dependencies..."
108 loop chan (State size 0 0)
112 let msg = "\rBuilding dependencies (" ++ show n ++ "/" ++ show total ++ ")"
115 loop chan (State total n 0)
118 do putStrLn "\rDependencies ready! "
119 loop chan (State 0 0 0)
125 loop chan (State size 0 0)
127 CompileFileStart _ ->
130 CompileFileEnd _ Good ->
131 do hPutStr stdout $ Bar.render (good + 1) bad total
133 loop chan (State total (good + 1) bad)
135 CompileFileEnd _ Bad ->
136 do hPutStr stdout $ Bar.render good (bad + 1) total
138 loop chan (State total good (bad + 1))
145 (0, 1) -> "Success! Compiled 1 module."
146 (0, n) -> "Success! Compiled " ++ show n ++ " modules."
147 (1, _) -> "Detected errors in 1 module."
148 (n, _) -> "Detected errors in " ++ show n ++ " modules."
150 do hPutStr stdout $ Bar.clear
152 loop chan (State 0 0 0)
157 PublishStart name version maybePublishedVersions ->
158 case maybePublishedVersions of
160 do putStrLn newPackageOverview
161 putStrLn "I will now verify that everything is in order..."
166 do putStrLn $ unwords [ "Verifying", Pkg.toString name, Pkg.versionToString version, "..." ]
170 PublishCheckBump version bumpPhase ->
171 do Help.toStdout $ bumpPhaseToChecklistDoc version bumpPhase
175 PublishProgress phase status ->
176 do Help.toStdout $ toChecklistDoc status (toChecklistMessages phase)
181 do putStrLn "Success!"
187 UnableToLoadLatestPackages ->
189 Help.toStdout $ D.dullyellow "WARNING:" <+> "I normally check <https://package.elm-lang.org> for new packages\n"
190 putStrLn "here, but my request failed. Are you offline? I will try to continue anyway.\n"
198makeBullet :: Name -> Version -> Outcome -> D.Doc
199makeBullet name version outcome =
201 nm = D.fromText (Pkg.toText name)
202 vsn = D.fromText (Pkg.versionToText version)
209 D.indent 2 $ bullet <+> nm <+> vsn <> "\n"
215 if System.os == "mingw32" then "+" else "●"
221 if System.os == "mingw32" then "X" else "✗"
227 if System.os == "mingw32" then "-" else "→"
231-- OVERVIEW OF VERSIONING
234newPackageOverview :: String
237 [ "This package has never been published before. Here's how things work:"
239 , " - Versions all have exactly three parts: MAJOR.MINOR.PATCH"
241 , " - All packages start with initial version " ++ Pkg.versionToString Pkg.initialVersion
243 , " - Versions are incremented based on how the API changes:"
245 , " PATCH = the API is the same, no risk of breaking code"
246 , " MINOR = values have been added, existing values are unchanged"
247 , " MAJOR = existing values have been changed or removed"
249 , " - I will bump versions for you, automatically enforcing these rules"
258toChecklistDoc :: Maybe Outcome -> ChecklistMessages -> D.Doc
259toChecklistDoc status (ChecklistMessages waiting success failure) =
262 message ++ replicate (length waiting - length message) ' '
266 " " <> waitingMark <+> D.fromString waiting
269 "\r " <> goodMark <+> D.fromString (padded success ++ "\n")
272 "\r " <> badMark <+> D.fromString (padded failure ++ "\n\n")
275data ChecklistMessages =
283toChecklistMessages :: PublishPhase -> ChecklistMessages
284toChecklistMessages phase =
288 "Looking for README.md"
290 "Problem with your README.md"
294 "Looking for LICENSE"
296 "Problem with your LICENSE"
300 ("Is version " ++ Pkg.versionToString version ++ " tagged on GitHub?")
301 ("Version " ++ Pkg.versionToString version ++ " is tagged on GitHub")
302 ("Version " ++ Pkg.versionToString version ++ " is not tagged on GitHub!")
306 "Downloading code from GitHub..."
307 "Code downloaded successfully from GitHub"
308 "Could not download code from GitHub!"
312 "Building downloaded code and generated docs..."
313 "Downloaded code compiles successfully / docs generated\n"
314 "Cannot compile downloaded code!"
318 "Checking for uncommitted changes..."
319 "No uncommitted changes in local code"
320 "Your local code is different than the code tagged on GitHub"
327bumpPhaseToChecklistDoc :: Pkg.Version -> BumpPhase -> D.Doc
328bumpPhaseToChecklistDoc version bumpPhase =
332 ("Checking semantic versioning rules. Is " ++ Pkg.versionToString version ++ " correct?")
334 ("Version " ++ Pkg.versionToString version ++ " is not correct!")
339 toChecklistDoc Nothing $ mkMsgs ""
342 toChecklistDoc (Just Good) $ mkMsgs $
343 "All packages start at version " ++ Pkg.versionToString Pkg.initialVersion
345 GoodBump old magnitude ->
346 toChecklistDoc (Just Good) $ mkMsgs $
347 toCheckVersionSuccessMessage old version magnitude
350 toChecklistDoc (Just Bad) $ mkMsgs ""
353toCheckVersionSuccessMessage :: Pkg.Version -> Pkg.Version -> Diff.Magnitude -> String
354toCheckVersionSuccessMessage oldVersion newVersion magnitude =
356 old = Pkg.versionToString oldVersion
357 new = Pkg.versionToString newVersion
358 mag = Diff.magnitudeToString magnitude
360 "Version number " ++ new ++ " verified (" ++ mag ++ " change, " ++ old ++ " => " ++ new ++ ")"
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