diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-11-10 23:28:05 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-11-10 23:28:05 +0530 |
| commit | 0c3b673e1614677a20f0b0b22af8bd017228b5e0 (patch) | |
| tree | 95200787fc13997d0b50e9d9e20d8d8beb2537df /lib | |
| parent | a16933476187a349d619ab29f73dbcae81c8cb24 (diff) | |
| download | daffm-0c3b673e1614677a20f0b0b22af8bd017228b5e0.tar.gz daffm-0c3b673e1614677a20f0b0b22af8bd017228b5e0.zip | |
Add basic selection-add/remove commands
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Daffm/Action/Commands.hs | 20 | ||||
| -rw-r--r-- | lib/Daffm/Action/Core.hs | 8 | ||||
| -rw-r--r-- | lib/Daffm/Configuration.hs | 10 | ||||
| -rw-r--r-- | lib/Daffm/State.hs | 2 | ||||
| -rw-r--r-- | lib/Daffm/Types.hs | 9 |
5 files changed, 31 insertions, 18 deletions
diff --git a/lib/Daffm/Action/Commands.hs b/lib/Daffm/Action/Commands.hs index a963191..9a90f93 100644 --- a/lib/Daffm/Action/Commands.hs +++ b/lib/Daffm/Action/Commands.hs @@ -42,15 +42,17 @@ parseCommand cmd = mkCmd . splitCmdArgs $ trimStart cmd ("shell", cmd') -> Just $ CmdShell False cmd' ("eval", cmd') -> Just $ CmdCommandShell cmd' ("back", _) -> Just CmdGoBack - ("open", _) -> Just CmdOpenSelection + ("open", _) -> Just CmdSelectionOpen ("reload", _) -> Just CmdReload ("cd", dir) -> Just $ CmdChangeDir dir ("noop", _) -> Just CmdNoop ("cmdline-enter", _) -> Just CmdEnterCmdline ("cmdline-leave", _) -> Just CmdLeaveCmdline ("cmdline-set", txt) -> Just $ CmdSetCmdline txt - ("selection-toggle", _) -> Just CmdToggleSelection - ("selection-clear", _) -> Just CmdClearSelection + ("selection-toggle", _) -> Just CmdSelectionToggle + ("selection-clear", _) -> Just CmdSelectionClear + ("selection-add", file) -> Just $ CmdSelectionAdd file + ("selection-remove", file) -> Just $ CmdSelectionRemove file ("search", term) -> Just $ CmdSearch $ trim term ("search-next", _) -> Just $ CmdSearchNext 1 ("search-prev", _) -> Just $ CmdSearchNext (-1) @@ -98,11 +100,13 @@ processCommand (CmdSetCmdline txt) args = enterCmdline >> cmdSubstitutions (argSubst args txt) >>= setCmdlineText processCommand CmdEnterCmdline _args = enterCmdline processCommand CmdLeaveCmdline _args = leaveCmdline -processCommand CmdOpenSelection _args = openSelectedFile +processCommand CmdSelectionOpen _args = openSelectedFile processCommand (CmdChangeDir dir) args = cmdSubstitutions (argSubst args dir) >>= changeDir processCommand CmdReload _args = reloadDir -processCommand CmdToggleSelection _args = toggleCurrentFileSelection -processCommand CmdClearSelection _args = clearFileSelections +processCommand CmdSelectionToggle _args = toggleCurrentFileSelection +processCommand CmdSelectionClear _args = clearFileSelections +processCommand (CmdSelectionAdd file) _args = addFileSelection $ trim file -- TODO: Subst +processCommand (CmdSelectionRemove file) _args = removeFileSelection $ trim file -- TODO: Subst processCommand CmdGoBack _ = goBackToParentDir processCommand (CmdChain chain) args = forM_ chain (`processCommand` args) processCommand (CmdSearch term) _ = setSearchTerm term >> applySearch >> nextSearchMatch @@ -123,12 +127,12 @@ processCommand (CmdCustom cmd args) _ = do myCmd <- gets $ Map.lookup cmd . stateCustomCommands case myCmd of Just command -> processCommand command args - Nothing -> modify (\st -> st { stateMessage = Just $ "Invalid command " <> cmd }) + Nothing -> modify (\st -> st {stateMessage = Just $ "Invalid command " <> cmd}) processCommand CmdNoop _ = pure () evaluateCommand :: Text.Text -> AppEvent () evaluateCommand cmdtxt = do - modify (\st -> st { stateMessage = Nothing }) + modify (\st -> st {stateMessage = Nothing}) case parseCommand cmdtxt of Just cmd -> processCommand cmd "" Nothing -> pure () diff --git a/lib/Daffm/Action/Core.hs b/lib/Daffm/Action/Core.hs index 85f861a..ba50638 100644 --- a/lib/Daffm/Action/Core.hs +++ b/lib/Daffm/Action/Core.hs @@ -99,6 +99,14 @@ toggleCurrentFileSelection = do Nothing -> pure () moveCurrent 1 +addFileSelection :: FilePathText -> AppEvent () +addFileSelection path = do + modify $ \st -> st {stateFileSelections = Set.insert path . stateFileSelections $ st} + +removeFileSelection :: FilePathText -> AppEvent () +removeFileSelection path = do + modify $ \st -> st {stateFileSelections = Set.delete path . stateFileSelections $ st} + clearFileSelections :: AppEvent () clearFileSelections = modify $ \st -> st {stateFileSelections = Set.empty} diff --git a/lib/Daffm/Configuration.hs b/lib/Daffm/Configuration.hs index ee8f88e..e0ed5ad 100644 --- a/lib/Daffm/Configuration.hs +++ b/lib/Daffm/Configuration.hs @@ -40,13 +40,13 @@ defaultKeymaps = ([K.KChar 'n'], CmdSearchNext 1), ([K.KChar 'N'], CmdSearchNext (-1)), ([K.KChar ':'], CmdEnterCmdline), - ([K.KChar 'l'], CmdOpenSelection), + ([K.KChar 'l'], CmdSelectionOpen), ([K.KChar 'h'], CmdGoBack), - ([K.KEnter], CmdOpenSelection), + ([K.KEnter], CmdSelectionOpen), ([K.KBS], CmdGoBack), - ([K.KChar 'v'], CmdToggleSelection), - ([K.KChar '\t'], CmdToggleSelection), - ([K.KChar 'C'], CmdClearSelection), + ([K.KChar 'v'], CmdSelectionToggle), + ([K.KChar '\t'], CmdSelectionToggle), + ([K.KChar 'C'], CmdSelectionClear), ([K.KChar '~'], CmdChangeDir "~"), ([K.KChar '$'], CmdShell False "$SHELL"), ([K.KChar 'g', K.KChar 'x'], CmdShell False "!xdg-open % >/dev/null 2>&1"), diff --git a/lib/Daffm/State.hs b/lib/Daffm/State.hs index 902b6c6..1334327 100644 --- a/lib/Daffm/State.hs +++ b/lib/Daffm/State.hs @@ -17,7 +17,7 @@ import qualified Data.Set as Set import qualified Data.Text as Text import qualified Data.Text.Zipper.Generic as Zipper import qualified Data.Vector as Vec -import System.Directory (doesDirectoryExist, doesPathExist, getCurrentDirectory, getHomeDirectory, getPermissions, getSymbolicLinkTarget, listDirectory, makeAbsolute, readable, setCurrentDirectory) +import System.Directory (doesPathExist, getCurrentDirectory, getHomeDirectory, getPermissions, getSymbolicLinkTarget, listDirectory, makeAbsolute, readable, setCurrentDirectory) import System.FilePath (joinPath, takeDirectory) import System.PosixCompat (fileExist) import qualified System.PosixCompat as Posix diff --git a/lib/Daffm/Types.hs b/lib/Daffm/Types.hs index a26b0ef..0b22816 100644 --- a/lib/Daffm/Types.hs +++ b/lib/Daffm/Types.hs @@ -74,11 +74,13 @@ data Command | CmdSetCmdline Text.Text | CmdEnterCmdline | CmdLeaveCmdline - | CmdOpenSelection + | CmdSelectionOpen | CmdChangeDir Text.Text | CmdReload - | CmdToggleSelection - | CmdClearSelection + | CmdSelectionToggle + | CmdSelectionAdd Text.Text + | CmdSelectionRemove Text.Text + | CmdSelectionClear | CmdGoBack | CmdChain [Command] | CmdSearch Text.Text @@ -117,4 +119,3 @@ data Args = Args argsHelp :: Bool } deriving (Show) - |
