From 2b72c64cb3a896c4c54a5959609a44e240cefc93 Mon Sep 17 00:00:00 2001 From: pingu Date: Mon, 16 Oct 2023 18:47:09 +0200 Subject: [PATCH] This is so ugly --- app/Main.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/Main.hs b/app/Main.hs index e20ad1c..81a0c9f 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -76,6 +76,20 @@ attributeMap = const $ attrMap defAttr select :: Widget () -> Widget () select = withAttr (attrName "selected") +unitSize :: Integer -> String +unitSize s + | fromInteger s / (k2^(3 :: Int)) >= 1 / 2 = + show (f $ fromInteger s / (k2^(3 :: Int))) ++ " GB" + | fromInteger s / (k2^(2 :: Int)) >= 1 / 2 = + show (f $ fromInteger s / (k2^(2 :: Int))) ++ " MB" + | fromInteger s / k2 >= 1 / 2 = + show (f $ fromInteger s / k2 ) ++ " KB" + | otherwise = + show s ++ " B" + where k2 = 1024 :: Double + f :: Double -> Double + f q = fromInteger (truncate $ q * 100) / 100 + browse :: AppS -> Widget () browse s = str "Path" <+> padLeft Max (str "Size") <=> @@ -88,7 +102,7 @@ widgetCons s w@(f,_) ws = pathWidget w pathWidget :: (FilePath, Integer) -> Widget () -pathWidget (f, s) = str (show f) <+> padLeft Max (str (show s)) +pathWidget (f, s) = str (show f) <+> padLeft Max (str (unitSize s)) sizeDir :: AppS -> IO AppS sizeDir s = do