Reverse sort

This commit is contained in:
pingu 2023-10-14 13:49:13 +02:00
parent 966744f709
commit 0e788c443d

View File

@ -1,14 +1,17 @@
module Main where module Main where
import System.Posix.Directory ( getWorkingDirectory ) import System.Posix.Directory ( getWorkingDirectory )
import System.Directory import System.Directory ( pathIsSymbolicLink
( pathIsSymbolicLink, doesFileExist, getFileSize, doesDirectoryExist ) , doesFileExist
import Data.Functor ( (<&>) ) , getFileSize
import Control.Monad ( filterM ) , doesDirectoryExist )
import System.Directory.Extra ( listContents ) import Data.Functor ( (<&>) )
import Brick import Control.Monad ( filterM )
import Graphics.Vty import System.Directory.Extra ( listContents )
import Data.List.Extra import Brick
import Graphics.Vty
import Data.List.Extra
import qualified Data.Ord
listNonSymFiles :: FilePath -> IO [FilePath] listNonSymFiles :: FilePath -> IO [FilePath]
listNonSymFiles dir = filterM (fmap not . pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir listNonSymFiles dir = filterM (fmap not . pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir
@ -21,7 +24,7 @@ getSizeSubpaths x = do
sub <- listNonSymDirectories x sub <- listNonSymDirectories x
subby <- mapM (\y -> (y,) . sum . map snd <$> getSizeSubpaths y) sub subby <- mapM (\y -> (y,) . sum . map snd <$> getSizeSubpaths y) sub
local <- listNonSymFiles x >>= (\y -> mapM getFileSize y <&> zip y) local <- listNonSymFiles x >>= (\y -> mapM getFileSize y <&> zip y)
pure $ local ++ subby pure $ sortOn (Data.Ord.Down . snd) $ local ++ subby
data AppS = AppS data AppS = AppS
{ {