aboutsummaryrefslogtreecommitdiff
path: root/lib/Daffm/Configuration.hs
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-10-05 20:21:13 +0530
committerAkshay Nair <phenax5@gmail.com>2025-10-08 13:05:32 +0530
commit8cc1763237f9f12d25cf00735ce63c5655877899 (patch)
tree2ac9e6cd021327b6eb30ab7305e24aec68df3ab3 /lib/Daffm/Configuration.hs
parent0979d4e678514a8e0cdcbe1fbb174667c5361c8a (diff)
downloaddaffm-8cc1763237f9f12d25cf00735ce63c5655877899.tar.gz
daffm-8cc1763237f9f12d25cf00735ce63c5655877899.zip
Add CmdChain to run commands sequentially in keys
Diffstat (limited to 'lib/Daffm/Configuration.hs')
-rw-r--r--lib/Daffm/Configuration.hs12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/Daffm/Configuration.hs b/lib/Daffm/Configuration.hs
index 494d2a4..d3691cd 100644
--- a/lib/Daffm/Configuration.hs
+++ b/lib/Daffm/Configuration.hs
@@ -1,12 +1,13 @@
module Daffm.Configuration where
+import Control.Applicative ((<|>))
import Control.Arrow (ArrowChoice (left))
import Control.Exception (throwIO)
import qualified Control.Exception as IO
import Daffm.Action.Commands (parseCommand)
import Daffm.Keymap (parseKeySequence)
import Daffm.Types
-import Data.Bifunctor (Bifunctor (bimap))
+import Data.Bifunctor (Bifunctor (first))
import qualified Data.Map as Map
import Data.Maybe (fromMaybe)
import qualified Data.Text as Text
@@ -25,7 +26,7 @@ getDefaultConfigFilePath "" = do
pure $ joinPath [dir, "config.toml"]
getDefaultConfigFilePath name = do
dir <- getConfigDir
- pure $ joinPath [dir, "config" <> name <> ".toml"]
+ pure $ joinPath [dir, "config." <> name <> ".toml"]
resolveConfigPath :: Maybe String -> IO FilePath
resolveConfigPath Nothing = getDefaultConfigFilePath ""
@@ -59,8 +60,11 @@ configurationCodec =
keymapCodec :: Toml.Key -> Toml.TomlCodec Keymap
keymapCodec = Toml.dimap (const Map.empty) toKeymap . keymapRawCodec
where
- keymapRawCodec = Toml.tableMap Toml._KeyText Toml.text
- toKeymap = Map.fromList . map (bimap toKeys toCmd) . Map.toList
+ keymapRawCodec = Toml.tableMap Toml._KeyText commandCodec
+ toKeymap = Map.fromList . map (first toKeys) . Map.toList
toKeys = fromMaybe [] . parseKeySequence . stripQuotes
toCmd = fromMaybe CmdNoop . parseCommand
stripQuotes txt = fromMaybe txt (Text.stripPrefix "\"" txt >>= Text.stripSuffix "\"")
+ commandCodec k = cmdCodec k <|> cmdChainCodec k
+ cmdCodec = Toml.dimap (const "") toCmd . Toml.text
+ cmdChainCodec = Toml.dimap (const []) (CmdChain . map toCmd) . Toml.arrayOf Toml._Text