module Matterhorn.KeybindingConsistency
( ensureKeybindingConsistency
)
where
import Prelude ()
import Matterhorn.Prelude
import Brick.Keybindings
import qualified Data.Text as T
import Matterhorn.Types
ensureKeybindingConsistency :: KeyConfig KeyEvent
-> [(T.Text, [MHKeyEventHandler])]
-> Either String ()
ensureKeybindingConsistency :: KeyConfig KeyEvent
-> [(Text, [MHKeyEventHandler])] -> Either String ()
ensureKeybindingConsistency KeyConfig KeyEvent
kc [(Text, [MHKeyEventHandler])]
modeMaps = do
[(Text, [MHKeyEventHandler])]
-> ((Text, [MHKeyEventHandler]) -> Either String ())
-> Either String ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [(Text, [MHKeyEventHandler])]
modeMaps (((Text, [MHKeyEventHandler]) -> Either String ())
-> Either String ())
-> ((Text, [MHKeyEventHandler]) -> Either String ())
-> Either String ()
forall a b. (a -> b) -> a -> b
$ \(Text
mode, [MHKeyEventHandler]
handlers) -> do
case KeyConfig KeyEvent
-> [MHKeyEventHandler]
-> Either
[(Binding, [KeyHandler KeyEvent MH])] (KeyDispatcher KeyEvent MH)
forall k (m :: * -> *).
Ord k =>
KeyConfig k
-> [KeyEventHandler k m]
-> Either [(Binding, [KeyHandler k m])] (KeyDispatcher k m)
keyDispatcher KeyConfig KeyEvent
kc [MHKeyEventHandler]
handlers of
Left [(Binding, [KeyHandler KeyEvent MH])]
conflicts ->
String -> Either String ()
forall a b. a -> Either a b
Left (String -> Either String ()) -> String -> Either String ()
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$
Text
"Key binding conflict in '" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
mode Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"' mode:\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
KeyConfig KeyEvent -> [(Binding, [KeyHandler KeyEvent MH])] -> Text
forall k (m :: * -> *).
Ord k =>
KeyConfig k -> [(Binding, [KeyHandler k m])] -> Text
bindingConflictMessage KeyConfig KeyEvent
kc [(Binding, [KeyHandler KeyEvent MH])]
conflicts
Right {} -> () -> Either String ()
forall a. a -> Either String a
forall (m :: * -> *) a. Monad m => a -> m a
return ()