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/Daffm/Action | |
| parent | a16933476187a349d619ab29f73dbcae81c8cb24 (diff) | |
| download | daffm-0c3b673e1614677a20f0b0b22af8bd017228b5e0.tar.gz daffm-0c3b673e1614677a20f0b0b22af8bd017228b5e0.zip | |
Add basic selection-add/remove commands
Diffstat (limited to 'lib/Daffm/Action')
| -rw-r--r-- | lib/Daffm/Action/Commands.hs | 20 | ||||
| -rw-r--r-- | lib/Daffm/Action/Core.hs | 8 |
2 files changed, 20 insertions, 8 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} |
