diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-10-03 20:21:31 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-10-03 21:10:34 +0530 |
| commit | b1f56e140e6166c06a5b1f0a02aa4bc0953d6eb3 (patch) | |
| tree | 0be94058cb050c1571e0d21f806433def5d3ad49 /lib/Daffm/Action/Core.hs | |
| parent | 4d669ba5d5858e47b8d5723aae89b75481a2df2f (diff) | |
| download | daffm-b1f56e140e6166c06a5b1f0a02aa4bc0953d6eb3.tar.gz daffm-b1f56e140e6166c06a5b1f0a02aa4bc0953d6eb3.zip | |
Add delete command + minor refactors
Diffstat (limited to '')
| -rw-r--r-- | lib/Daffm/Action/Core.hs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/Daffm/Action/Core.hs b/lib/Daffm/Action/Core.hs index 9fed688..d18bda9 100644 --- a/lib/Daffm/Action/Core.hs +++ b/lib/Daffm/Action/Core.hs @@ -1,12 +1,13 @@ {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} {-# HLINT ignore "Use for_" #-} +{-# HLINT ignore "Use <=<" #-} module Daffm.Action.Core where import Brick (suspendAndResume') import qualified Brick.Widgets.List as L import Control.Monad.State (MonadIO (liftIO), MonadState, get, gets, modify, put) -import Daffm.State (loadDirInAppState, toggleFileSelection) +import Daffm.State import Daffm.Types (AppEvent, AppState (..), FileInfo (..), FileType (..)) import qualified Data.Set as Set import System.Directory (getHomeDirectory) @@ -16,32 +17,34 @@ import System.Process (callProcess) modifyM :: (MonadState s m) => (s -> m s) -> m () modifyM f = get >>= f >>= put +loadDir :: FilePath -> FilePath -> AppEvent () +loadDir dir parentDir = do + modifyM (liftIO . (>>= filterInvalidSelections) . loadDirToState dir parentDir) + reloadDir :: AppEvent () reloadDir = do AppState {stateCwd, stateParentDir} <- get - modifyM (liftIO . loadDirInAppState stateCwd stateParentDir) + loadDir stateCwd stateParentDir goBackToParentDir :: AppEvent () goBackToParentDir = do dir <- gets stateParentDir - modifyM (liftIO . loadDirInAppState dir (takeDirectory dir)) + loadDir dir (takeDirectory dir) goHome :: AppEvent () goHome = do dir <- liftIO getHomeDirectory - modifyM (liftIO . loadDirInAppState dir (takeDirectory dir)) + loadDir dir (takeDirectory dir) openSelectedFile :: AppEvent () openSelectedFile = do - fileM <- currentFile - case fileM of + currentFile >>= \case Just file -> openFile file Nothing -> pure () openFile :: FileInfo -> AppEvent () openFile (FileInfo {filePath, fileType = Directory}) = do - (AppState {stateCwd}) <- get - modifyM (liftIO . loadDirInAppState filePath stateCwd) + gets stateCwd >>= loadDir filePath openFile (FileInfo {filePath, fileType}) = do suspendAndResume' $ do putStrLn $ "Opening " <> show fileType <> ": " <> filePath @@ -53,8 +56,7 @@ currentFile = do toggleCurrentFileSelection :: AppEvent () toggleCurrentFileSelection = do - fileM <- currentFile - case fileM of + currentFile >>= \case Just file -> modify $ toggleFileSelection (filePath file) Nothing -> pure () moveCurrent 1 |
