summary history branches tags files
commit:1580c041ea37bf71696016626eb41127355d2983
author:avh4
committer:avh4
date:Sun Jan 22 16:38:08 2023 -0800
parents:40454c68ea6d30e61eb16414677d5bf378bc4f80
Add progress bar
diff --git a/shell.nix b/shell.nix
line changes: +8/-2
index 4894011..6a601a6
--- a/shell.nix
+++ b/shell.nix
@@ -6,8 +6,14 @@ let
 
 in pkgs.mkShell {
   nativeBuildInputs = [
-    (haskellPackages.ghcWithPackages
-      (p: with p; [ aeson dir-traverse relude typed-process ]))
+    (haskellPackages.ghcWithPackages (p:
+      with p; [
+        aeson
+        dir-traverse
+        relude
+        terminal-progress-bar
+        typed-process
+      ]))
     haskellPackages.ghcid
     haskellPackages.haskell-language-server
 

diff --git a/sizer.hs b/sizer.hs
line changes: +11/-2
index c88470f..42b8b5b
--- a/sizer.hs
+++ b/sizer.hs
@@ -7,16 +7,25 @@ import Data.Aeson (ToJSON(..), FromJSON(..), Value(..), (.:), (.=), object)
 import Data.Aeson.Types (prependFailure, typeMismatch)
 import Data.Text (Text)
 import GHC.Base (quotInt)
-import Relude (catMaybes, foldMapM)
+import Relude (catMaybes, foldMapM, stderr)
 import System.Directory (doesDirectoryExist, listDirectory, pathIsSymbolicLink)
+import System.IO (stderr, hPutStrLn)
 import System.Posix.Files qualified as Posix
 import System.Process.Typed (readProcess_, proc)
+import System.ProgressBar (hNewProgressBar)
+import System.ProgressBar qualified as ProgressBar
 
 main :: IO ()
 main = do
   gcrootPaths <- findRoots "/nix/var/nix/gcroots"
-  gcroots <- catMaybes <$> mapM collectGcroot gcrootPaths
+  hPutStrLn stderr "Scanning gcroots..."
+  pb <- hNewProgressBar stderr ProgressBar.defStyle 10 (ProgressBar.Progress 0 (length gcrootPaths) ())
+  gcroots <- catMaybes <$> mapM (collectAndLog pb) gcrootPaths
   mapM_ printGcroot gcroots
+  where
+    collectAndLog pb root =
+      collectGcroot root
+        <* ProgressBar.incProgress pb 1
 
 findRoots :: FilePath -> IO [FilePath]
 findRoots path = do