{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Brick.Types
(
Widget(..)
, Location(..)
, locL
, TerminalLocation(..)
, CursorLocation(..)
, cursorLocationL
, cursorLocationNameL
, Viewport(..)
, ViewportType(..)
, vpSize
, vpTop
, vpLeft
, vpContentSize
, VScrollBarOrientation(..)
, HScrollBarOrientation(..)
, ScrollbarRenderer(..)
, ClickableScrollbarElement(..)
, EventM
, BrickEvent(..)
, nestEventM
, nestEventM'
, RenderM
, getContext
, Context(ctxAttrName, availWidth, availHeight, windowWidth, windowHeight, ctxBorderStyle, ctxAttrMap, ctxDynBorders)
, attrL
, availWidthL
, availHeightL
, windowWidthL
, windowHeightL
, ctxVScrollBarOrientationL
, ctxVScrollBarRendererL
, ctxHScrollBarOrientationL
, ctxHScrollBarRendererL
, ctxAttrMapL
, ctxAttrNameL
, ctxBorderStyleL
, ctxDynBordersL
, Result(..)
, emptyResult
, lookupAttrName
, Extent(..)
, imageL
, cursorsL
, visibilityRequestsL
, extentsL
, VisibilityRequest(..)
, vrPositionL
, vrSizeL
, suffixLenses
, suffixLensesWith
, bordersL
, DynBorder(..)
, dbStyleL, dbAttrL, dbSegmentsL
, BorderSegment(..)
, bsAcceptL, bsOfferL, bsDrawL
, Edges(..)
, eTopL, eBottomL, eRightL, eLeftL
, Size(..)
, Direction(..)
, RenderState
, get
, gets
, put
, modify
, zoom
)
where
import Lens.Micro (_1, _2, to, (^.))
import Lens.Micro.Type (Getting)
import Lens.Micro.Mtl (zoom)
#if !MIN_VERSION_base(4,13,0)
import Control.Monad.Fail (MonadFail)
#endif
import Control.Monad.State.Strict
import Control.Monad.Reader
import Graphics.Vty (Attr)
import Brick.Types.TH
import Brick.Types.Internal
import Brick.Types.EventM
import Brick.AttrMap (AttrName, attrMapLookup)
nestEventM' :: a
-> EventM n a b
-> EventM n s a
nestEventM' :: forall a n b s. a -> EventM n a b -> EventM n s a
nestEventM' a
s EventM n a b
act = forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a n b s. a -> EventM n a b -> EventM n s (a, b)
nestEventM a
s EventM n a b
act
nestEventM :: a
-> EventM n a b
-> EventM n s (a, b)
nestEventM :: forall a n b s. a -> EventM n a b -> EventM n s (a, b)
nestEventM a
s' EventM n a b
act = do
EventRO n
ro <- forall n s a.
ReaderT (EventRO n) (StateT s (StateT (EventState n) IO)) a
-> EventM n s a
EventM forall r (m :: * -> *). MonadReader r m => m r
ask
EventState n
es <- forall n s a.
ReaderT (EventRO n) (StateT s (StateT (EventState n) IO)) a
-> EventM n s a
EventM forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall s (m :: * -> *). MonadState s m => m s
get
VtyContext
vtyCtx <- forall n s. EventM n s VtyContext
getVtyContext
let stInner :: EventState n
stInner = ES { nextAction :: NextAction
nextAction = NextAction
Continue
, esScrollRequests :: [(n, ScrollRequest)]
esScrollRequests = forall n. EventState n -> [(n, ScrollRequest)]
esScrollRequests EventState n
es
, cacheInvalidateRequests :: Set (CacheInvalidateRequest n)
cacheInvalidateRequests = forall n. EventState n -> Set (CacheInvalidateRequest n)
cacheInvalidateRequests EventState n
es
, requestedVisibleNames :: Set n
requestedVisibleNames = forall n. EventState n -> Set n
requestedVisibleNames EventState n
es
, vtyContext :: VtyContext
vtyContext = VtyContext
vtyCtx
}
((b
actResult, a
newSt), EventState n
stInnerFinal) <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT (forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT (forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (forall n s a.
EventM n s a
-> ReaderT (EventRO n) (StateT s (StateT (EventState n) IO)) a
runEventM EventM n a b
act) EventRO n
ro) a
s') EventState n
stInner
forall n s a.
ReaderT (EventRO n) (StateT s (StateT (EventState n) IO)) a
-> EventM n s a
EventM forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$
\EventState n
st -> EventState n
st { nextAction :: NextAction
nextAction = forall n. EventState n -> NextAction
nextAction EventState n
stInnerFinal
, esScrollRequests :: [(n, ScrollRequest)]
esScrollRequests = forall n. EventState n -> [(n, ScrollRequest)]
esScrollRequests EventState n
stInnerFinal
, cacheInvalidateRequests :: Set (CacheInvalidateRequest n)
cacheInvalidateRequests = forall n. EventState n -> Set (CacheInvalidateRequest n)
cacheInvalidateRequests EventState n
stInnerFinal
, requestedVisibleNames :: Set n
requestedVisibleNames = forall n. EventState n -> Set n
requestedVisibleNames EventState n
stInnerFinal
, vtyContext :: VtyContext
vtyContext = forall n. EventState n -> VtyContext
vtyContext EventState n
stInnerFinal
}
forall (m :: * -> *) a. Monad m => a -> m a
return (a
newSt, b
actResult)
attrL :: forall r n. Getting r (Context n) Attr
attrL :: forall r n. Getting r (Context n) Attr
attrL = forall s a. (s -> a) -> SimpleGetter s a
to (\Context n
c -> AttrName -> AttrMap -> Attr
attrMapLookup (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) AttrName
ctxAttrNameL) (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) AttrMap
ctxAttrMapL))
instance TerminalLocation (CursorLocation n) where
locationColumnL :: Lens' (CursorLocation n) Int
locationColumnL = forall n. Lens' (CursorLocation n) Location
cursorLocationLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field1 s t a b => Lens s t a b
_1
locationColumn :: CursorLocation n -> Int
locationColumn = forall a. TerminalLocation a => a -> Int
locationColumn forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. CursorLocation n -> Location
cursorLocation
locationRowL :: Lens' (CursorLocation n) Int
locationRowL = forall n. Lens' (CursorLocation n) Location
cursorLocationLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field2 s t a b => Lens s t a b
_2
locationRow :: CursorLocation n -> Int
locationRow = forall a. TerminalLocation a => a -> Int
locationRow forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. CursorLocation n -> Location
cursorLocation
lookupAttrName :: AttrName -> RenderM n Attr
lookupAttrName :: forall n. AttrName -> RenderM n Attr
lookupAttrName AttrName
n = do
Context n
c <- forall n. RenderM n (Context n)
getContext
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ AttrName -> AttrMap -> Attr
attrMapLookup AttrName
n (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) AttrMap
ctxAttrMapL)