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