diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-10-24 00:41:56 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-10-24 11:43:35 +0530 |
| commit | a3cc21ebb749c1e5071d857990c6aaed0d182840 (patch) | |
| tree | 00352062f5f2b0cf8741fc3231e6034a535db00f /lib/Daffm/Action/Commands.hs | |
| parent | b687795db6d57188d6f7d65437f0a8dc0f9a89a4 (diff) | |
| download | daffm-a3cc21ebb749c1e5071d857990c6aaed0d182840.tar.gz daffm-a3cc21ebb749c1e5071d857990c6aaed0d182840.zip | |
Add move command and gj gk keys
Diffstat (limited to 'lib/Daffm/Action/Commands.hs')
| -rw-r--r-- | lib/Daffm/Action/Commands.hs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/Daffm/Action/Commands.hs b/lib/Daffm/Action/Commands.hs index a6a55e6..669ff3c 100644 --- a/lib/Daffm/Action/Commands.hs +++ b/lib/Daffm/Action/Commands.hs @@ -4,9 +4,10 @@ module Daffm.Action.Commands where import qualified Brick as M +import qualified Brick.Widgets.List as L import Control.Monad (forM_) import Control.Monad.IO.Class (MonadIO (liftIO)) -import Control.Monad.State (modify) +import Control.Monad.State (gets, modify) import Daffm.Action.Cmdline import Daffm.Action.Core import Daffm.Keymap (parseKeySequence) @@ -27,8 +28,9 @@ runCmdline = do evaluateCommand cmd parseCommand :: Text.Text -> Maybe Command -parseCommand (Text.splitAt 2 -> ("!!", cmd)) = Just $ CmdShell True cmd -parseCommand (Text.splitAt 1 -> ("!", cmd)) = Just $ CmdShell False cmd +parseCommand (Text.stripPrefix "!!" -> Just cmd) = Just $ CmdShell True cmd +parseCommand (Text.stripPrefix "!" -> Just cmd) = Just $ CmdShell False cmd +parseCommand (Text.stripPrefix "/" -> Just term) = Just $ CmdSearch $ trim term parseCommand cmd = mkCmd . splitCmdArgs $ trimStart cmd where splitCmdArgs = second trimStart . Text.break isSpace @@ -37,7 +39,7 @@ parseCommand cmd = mkCmd . splitCmdArgs $ trimStart cmd ("quit", _) -> Just CmdQuit ("shell!", cmd') -> Just $ CmdShell True cmd' ("shell", cmd') -> Just $ CmdShell False cmd' - ("command-shell", cmd') -> Just $ CmdCommandShell cmd' + ("eval", cmd') -> Just $ CmdCommandShell cmd' ("back", _) -> Just CmdGoBack ("open", _) -> Just CmdOpenSelection ("reload", _) -> Just CmdReload @@ -51,6 +53,10 @@ parseCommand cmd = mkCmd . splitCmdArgs $ trimStart cmd ("search", term) -> Just $ CmdSearch $ trim term ("search-next", _) -> Just $ CmdSearchNext 1 ("search-prev", _) -> Just $ CmdSearchNext (-1) + ("move", Text.stripPrefix "$" -> Just _) -> Just $ CmdMove MoveToEnd + ("move", Text.stripPrefix "+" -> Just inc) -> Just . CmdMove . MoveDown . read $ Text.unpack inc + ("move", Text.stripPrefix "-" -> Just inc) -> Just . CmdMove . MoveUp . read $ Text.unpack inc + ("move", pos) -> Just . CmdMove . MoveTo . read $ Text.unpack pos ("map", Text.break isSpace -> (keysraw, cmdraw)) -> do keys <- parseKeySequence keysraw cmd' <- parseCommand $ trimStart cmdraw @@ -95,7 +101,18 @@ processCommand CmdGoBack = goBackToParentDir processCommand (CmdChain chain) = forM_ chain processCommand processCommand (CmdSearch term) = setSearchTerm term >> applySearch >> nextSearchMatch processCommand (CmdSearchNext change) = updateSearchIndex (+ change) >> nextSearchMatch -processCommand (CmdKeymapSet keys command) = modify $ \s -> s {stateKeyMap = Map.insert keys command $ stateKeyMap s} +processCommand (CmdKeymapSet keys command) = + modify $ \st -> st {stateKeyMap = Map.insert keys command $ stateKeyMap st} +processCommand (CmdMove move) = moveCursor $ toUpdater move + where + toUpdater MoveToEnd = L.listMoveToEnd + toUpdater (MoveTo pos) = L.listMoveTo pos + toUpdater (MoveUp inc) = L.listMoveBy $ - inc + toUpdater (MoveDown inc) = L.listMoveBy inc + moveCursor :: (L.List FocusTarget FileInfo -> L.List FocusTarget FileInfo) -> AppEvent () + moveCursor updater = do + files <- gets $ updater . stateFiles + modify $ \st -> st {stateFiles = files} processCommand CmdNoop = pure () evaluateCommand :: Text.Text -> AppEvent () |
