diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-10-08 10:22:41 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-10-08 13:10:40 +0530 |
| commit | e173e1f105e72e06c6a3206b9b94f4f1da63b00f (patch) | |
| tree | a1bd14e1da4deedf80a1837ab4f79650a43f47e5 /lib/Daffm/Action | |
| parent | a9189b183b96634a6af335b447f9aa44263ac304 (diff) | |
| download | daffm-e173e1f105e72e06c6a3206b9b94f4f1da63b00f.tar.gz daffm-e173e1f105e72e06c6a3206b9b94f4f1da63b00f.zip | |
Add map command for creating keymaps
Diffstat (limited to 'lib/Daffm/Action')
| -rw-r--r-- | lib/Daffm/Action/Commands.hs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Daffm/Action/Commands.hs b/lib/Daffm/Action/Commands.hs index 35262df..a6a55e6 100644 --- a/lib/Daffm/Action/Commands.hs +++ b/lib/Daffm/Action/Commands.hs @@ -6,12 +6,15 @@ module Daffm.Action.Commands where import qualified Brick as M import Control.Monad (forM_) import Control.Monad.IO.Class (MonadIO (liftIO)) +import Control.Monad.State (modify) import Daffm.Action.Cmdline import Daffm.Action.Core +import Daffm.Keymap (parseKeySequence) import Daffm.Types import Daffm.Utils (trim, trimStart) import Data.Bifunctor (Bifunctor (second)) import Data.Char (isSpace) +import qualified Data.Map as Map import Data.Maybe (fromMaybe) import qualified Data.Text as Text import qualified Data.Text.IO as Text @@ -48,6 +51,10 @@ parseCommand cmd = mkCmd . splitCmdArgs $ trimStart cmd ("search", term) -> Just $ CmdSearch $ trim term ("search-next", _) -> Just $ CmdSearchNext 1 ("search-prev", _) -> Just $ CmdSearchNext (-1) + ("map", Text.break isSpace -> (keysraw, cmdraw)) -> do + keys <- parseKeySequence keysraw + cmd' <- parseCommand $ trimStart cmdraw + pure $ CmdKeymapSet keys cmd' _ -> Nothing readCommandLines' :: Text.Text -> IO [Text.Text] @@ -88,6 +95,7 @@ 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 CmdNoop = pure () evaluateCommand :: Text.Text -> AppEvent () |
