1{-# OPTIONS_GHC -Wall #-}
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 Text.PrettyPrint.ANSI.Leijen ((<>), (<+>))
15import qualified Text.PrettyPrint.ANSI.Leijen as P
16import qualified Elm.Package as Pkg
17import Elm.Package (Name, Version)
19import qualified Deps.Diff as Diff
20import qualified Reporting.Error2 as Error
21import qualified Reporting.Error.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 $ P.dullyellow (P.text "WARNING:") <+> P.text "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 -> P.Doc
199makeBullet name version outcome =
202 P.text (Pkg.toString name)
205 P.text (Pkg.versionToString version)
212 P.indent 2 $ bullet <+> nm <+> vsn <> P.text "\n"
218 if System.os == "mingw32" then "+" else "●"
224 if System.os == "mingw32" then "X" else "✗"
229 P.dullyellow $ P.text $
230 if System.os == "mingw32" then "-" else "→"
234-- OVERVIEW OF VERSIONING
237newPackageOverview :: String
240 [ "This package has never been published before. Here's how things work:"
242 , " - Versions all have exactly three parts: MAJOR.MINOR.PATCH"
244 , " - All packages start with initial version " ++ Pkg.versionToString Pkg.initialVersion
246 , " - Versions are incremented based on how the API changes:"
248 , " PATCH = the API is the same, no risk of breaking code"
249 , " MINOR = values have been added, existing values are unchanged"
250 , " MAJOR = existing values have been changed or removed"
252 , " - I will bump versions for you, automatically enforcing these rules"
261toChecklistDoc :: Maybe Outcome -> ChecklistMessages -> P.Doc
262toChecklistDoc status (ChecklistMessages waiting success failure) =
265 message ++ replicate (length waiting - length message) ' '
269 P.text " " <> waitingMark <+> P.text waiting
272 P.text "\r " <> goodMark <+> P.text (padded success ++ "\n")
275 P.text "\r " <> badMark <+> P.text (padded failure ++ "\n\n")
278data ChecklistMessages =
286toChecklistMessages :: PublishPhase -> ChecklistMessages
287toChecklistMessages phase =
291 "Looking for README.md"
293 "Problem with your README.md"
297 "Looking for LICENSE"
299 "Problem with your LICENSE"
303 ("Is version " ++ Pkg.versionToString version ++ " tagged on GitHub?")
304 ("Version " ++ Pkg.versionToString version ++ " is tagged on GitHub")
305 ("Version " ++ Pkg.versionToString version ++ " is not tagged on GitHub!")
309 "Downloading code from GitHub..."
310 "Code downloaded successfully from GitHub"
311 "Could not download code from GitHub!"
315 "Building downloaded code and generated docs..."
316 "Downloaded code compiles successfully / docs generated\n"
317 "Cannot compile downloaded code!"
321 "Checking for uncommitted changes..."
322 "No uncommitted changes in local code"
323 "Your local code is different than the code tagged on GitHub"
330bumpPhaseToChecklistDoc :: Pkg.Version -> BumpPhase -> P.Doc
331bumpPhaseToChecklistDoc version bumpPhase =
335 ("Checking semantic versioning rules. Is " ++ Pkg.versionToString version ++ " correct?")
337 ("Version " ++ Pkg.versionToString version ++ " is not correct!")
342 toChecklistDoc Nothing $ mkMsgs ""
345 toChecklistDoc (Just Good) $ mkMsgs $
346 "All packages start at version " ++ Pkg.versionToString Pkg.initialVersion
348 GoodBump old magnitude ->
349 toChecklistDoc (Just Good) $ mkMsgs $
350 toCheckVersionSuccessMessage old version magnitude
353 toChecklistDoc (Just Bad) $ mkMsgs ""
356toCheckVersionSuccessMessage :: Pkg.Version -> Pkg.Version -> Diff.Magnitude -> String
357toCheckVersionSuccessMessage oldVersion newVersion magnitude =
359 old = Pkg.versionToString oldVersion
360 new = Pkg.versionToString newVersion
361 mag = Diff.magnitudeToString magnitude
363 "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