packages feed

ghc-debug-brick-0.1.0.0: src/Common.hs

{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DeriveFunctor #-}
module Common where

import qualified Brick.Types as T
import Lens.Micro
import Namespace

type Handler' s k =
  s
  -> T.BrickEvent Name ()
  -> T.EventM Name (T.Next k)

type Handler s = Handler' s s


-- | liftHandler lifts a handler which only operates on its own state into
-- a larger state. It won't work if the handler needs to modify something
-- from a larger scope.
liftHandler
  :: ASetter s s a a -- The mode to modify
  -> c        -- Inner state
  -> (c -> a) -- How to inject the new state
  -> Handler c -- Handler for inner state
  -> Handler s
liftHandler l c i h st ev = do
  let update s = set l (i s) st
  fmap update <$> h c ev

-- Missing instance from brick
deriving instance Functor (T.BrickEvent n)