aboutsummaryrefslogtreecommitdiff
path: root/src/Rahm/Desktop/Keys/KeyFeed.hs
diff options
context:
space:
mode:
authorJosh Rahm <rahm@josher.dev>2026-04-28 17:31:57 -0600
committerJosh Rahm <rahm@josher.dev>2026-04-28 17:31:57 -0600
commit9e1175f878e4a4b24a9486e969d96a9df1fec34c (patch)
tree1b6b3175d296bf9bff83706ca2187c8e7a0f9497 /src/Rahm/Desktop/Keys/KeyFeed.hs
parentb173b7ddac441e9d6649b22029d08d4be7aa8431 (diff)
downloadrde-9e1175f878e4a4b24a9486e969d96a9df1fec34c.tar.gz
rde-9e1175f878e4a4b24a9486e969d96a9df1fec34c.tar.bz2
rde-9e1175f878e4a4b24a9486e969d96a9df1fec34c.zip
[feat] properly color the borders when swapping windows.
Diffstat (limited to 'src/Rahm/Desktop/Keys/KeyFeed.hs')
-rw-r--r--src/Rahm/Desktop/Keys/KeyFeed.hs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/Rahm/Desktop/Keys/KeyFeed.hs b/src/Rahm/Desktop/Keys/KeyFeed.hs
index 46a2520..5b00af9 100644
--- a/src/Rahm/Desktop/Keys/KeyFeed.hs
+++ b/src/Rahm/Desktop/Keys/KeyFeed.hs
@@ -4,7 +4,7 @@
module Rahm.Desktop.Keys.KeyFeed where
import Control.Monad (void, when)
-import Control.Monad.State (MonadTrans (lift), StateT, evalStateT, modify')
+import Control.Monad.State (MonadTrans (lift), StateT (..), evalStateT, modify')
import Control.Monad.Trans.Maybe (MaybeT (MaybeT, runMaybeT))
import Data.List.Safe (head, last)
import Linear.V (reifyDim)
@@ -28,7 +28,24 @@ newtype KeyFeed a = KeyFeed (StateT KeyStream (MaybeT X) a)
deriving (Functor, Applicative, Monad)
instance Xish KeyFeed where
- liftFromX = liftXToFeed
+ liftFromX = KeyFeed . lift . lift
+
+ finallyX (KeyFeed mt) (KeyFeed err) =
+ KeyFeed $ do
+ r <- recover mt
+ case r of
+ Nothing -> do
+ err
+ let (KeyFeed r) = feedFail in r
+ Just a -> err >> pure a
+ where
+ recover fn = StateT $ \s -> MaybeT $ do
+ r <- runMaybeT (runStateT fn s)
+ pure $
+ Just $
+ case r of
+ Nothing -> (Nothing, s)
+ Just (a, s') -> (Just a, s')
-- Executes a KeyFeed, returning a MaybeT of the result
runKeyFeed :: KeyFeed a -> MaybeT X a