1module Reporting.Progress.Terminal
8import Control.Concurrent (forkIO)
9import Control.Concurrent.Chan (Chan, newChan, readChan)
10import Control.Concurrent.MVar (newEmptyMVar, putMVar)
11import qualified System.Info as System
12import System.IO (hFlush, hPutStr, stdout)
13import Text.PrettyPrint.ANSI.Leijen ((<>), (<+>))
14import qualified Text.PrettyPrint.ANSI.Leijen as P
15import qualified Elm.Package as Pkg
16import Elm.Package (Name, Version)
18import qualified Deps.Diff as Diff
19import qualified Reporting.Exit as Exit
20import qualified Reporting.Exit.Help as Help
21import Reporting.Progress (Msg(..), Progress(..), Outcome(..), PublishPhase(..), BumpPhase(..))
22import qualified Reporting.Progress as Progress
23import qualified Reporting.Progress.Bar as Bar
30create :: IO Progress.Reporter
34 _ <- forkIO (loop chan (State 0 0 0) >>= putMVar mvar)
35 return (Progress.makeReporter chan mvar)
54loop :: Chan Msg -> State -> IO ()
56 do msg <- readChan chan
65 loopHelp chan progress state
68loopHelp :: Chan Msg -> Progress -> State -> IO ()
69loopHelp chan progress state@(State total good bad) =
76 do putStrLn "Dependencies loaded from local cache."
83 do putStrLn "Starting downloads...\n"
86 DownloadPkgStart _name _version ->
89 DownloadPkgEnd name version outcome ->
90 do Help.toStdout (makeBullet name version outcome)
104 BuildDepsStart size ->
105 do hPutStr stdout "Verifying dependencies..."
107 loop chan (State size 0 0)
111 let msg = "\rBuilding dependencies (" ++ show n ++ "/" ++ show total ++ ")"
114 loop chan (State total n 0)
117 do putStrLn "\rDependencies ready! "
118 loop chan (State 0 0 0)
124 loop chan (State size 0 0)
126 CompileFileStart _ ->
129 CompileFileEnd _ Good ->
130 do hPutStr stdout $ Bar.render (good + 1) bad total
132 loop chan (State total (good + 1) bad)
134 CompileFileEnd _ Bad ->
135 do hPutStr stdout $ Bar.render good (bad + 1) total
137 loop chan (State total good (bad + 1))
144 (0, 1) -> "Success! Compiled 1 module."
145 (0, n) -> "Success! Compiled " ++ show n ++ " modules."
146 (1, _) -> "Detected errors in 1 module."
147 (n, _) -> "Detected errors in " ++ show n ++ " modules."
149 do hPutStr stdout $ Bar.clear
151 loop chan (State 0 0 0)
156 PublishStart name version maybePublishedVersions ->
157 case maybePublishedVersions of
159 do putStrLn newPackageOverview
160 putStrLn "I will now verify that everything is in order..."
165 do putStrLn $ unwords [ "Verifying", Pkg.toString name, Pkg.versionToString version, "..." ]
169 PublishCheckBump version bumpPhase ->
170 do Help.toStdout $ bumpPhaseToChecklistDoc version bumpPhase
174 PublishProgress phase status ->
175 do Help.toStdout $ toChecklistDoc status (toChecklistMessages phase)
180 do putStrLn "Success!"
186 UnableToLoadLatestPackages ->
188 Help.toStdout $ P.dullyellow (P.text "WARNING:") <+> P.text "I normally check <https://package.elm-lang.org> for new packages\n"
189 putStrLn "here, but my request failed. Are you offline? I will try to continue anyway.\n"
197makeBullet :: Name -> Version -> Outcome -> P.Doc
198makeBullet name version outcome =
201 P.text (Pkg.toString name)
204 P.text (Pkg.versionToString version)
211 P.indent 2 $ bullet <+> nm <+> vsn <> P.text "\n"
217 if System.os == "mingw32" then "+" else "●"
223 if System.os == "mingw32" then "X" else "✗"
228 P.dullyellow $ P.text $
229 if System.os == "mingw32" then "-" else "→"
233-- OVERVIEW OF VERSIONING
236newPackageOverview :: String
239 [ "This package has never been published before. Here's how things work:"
241 , " - Versions all have exactly three parts: MAJOR.MINOR.PATCH"
243 , " - All packages start with initial version " ++ Pkg.versionToString Pkg.initialVersion
245 , " - Versions are incremented based on how the API changes:"
247 , " PATCH = the API is the same, no risk of breaking code"
248 , " MINOR = values have been added, existing values are unchanged"
249 , " MAJOR = existing values have been changed or removed"
251 , " - I will bump versions for you, automatically enforcing these rules"
260toChecklistDoc :: Maybe Outcome -> ChecklistMessages -> P.Doc
261toChecklistDoc status (ChecklistMessages waiting success failure) =
264 message ++ replicate (length waiting - length message) ' '
268 P.text " " <> waitingMark <+> P.text waiting
271 P.text "\r " <> goodMark <+> P.text (padded success ++ "\n")
274 P.text "\r " <> badMark <+> P.text (padded failure ++ "\n\n")
277data ChecklistMessages =
285toChecklistMessages :: PublishPhase -> ChecklistMessages
286toChecklistMessages phase =
290 "Looking for README.md"
292 "Problem with your README.md"
296 "Looking for LICENSE"
298 "Problem with your LICENSE"
302 ("Is version " ++ Pkg.versionToString version ++ " tagged on GitHub?")
303 ("Version " ++ Pkg.versionToString version ++ " is tagged on GitHub")
304 ("Version " ++ Pkg.versionToString version ++ " is not tagged on GitHub!")
308 "Downloading code from GitHub..."
309 "Code downloaded successfully from GitHub"
310 "Could not download code from GitHub!"
314 "Building downloaded code and generated docs..."
315 "Downloaded code compiles successfully / docs generated\n"
316 "Cannot compile downloaded code!"
320 "Checking for uncommitted changes..."
321 "No uncommitted changes in local code"
322 "Your local code is different than the code tagged on GitHub"
329bumpPhaseToChecklistDoc :: Pkg.Version -> BumpPhase -> P.Doc
330bumpPhaseToChecklistDoc version bumpPhase =
334 ("Checking semantic versioning rules. Is " ++ Pkg.versionToString version ++ " correct?")
336 ("Version " ++ Pkg.versionToString version ++ " is not correct!")
341 toChecklistDoc Nothing $ mkMsgs ""
344 toChecklistDoc (Just Good) $ mkMsgs $
345 "All packages start at version " ++ Pkg.versionToString Pkg.initialVersion
347 GoodBump old magnitude ->
348 toChecklistDoc (Just Good) $ mkMsgs $
349 toCheckVersionSuccessMessage old version magnitude
352 toChecklistDoc (Just Bad) $ mkMsgs ""
355toCheckVersionSuccessMessage :: Pkg.Version -> Pkg.Version -> Diff.Magnitude -> String
356toCheckVersionSuccessMessage oldVersion newVersion magnitude =
358 old = Pkg.versionToString oldVersion
359 new = Pkg.versionToString newVersion
360 mag = Diff.magnitudeToString magnitude
362 "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