brick-1.9: A declarative terminal user interface library

Safe Haskell | Safe-Inferred
Language | Haskell2010

Brick.Types

Contents

- The Widget type
- Location types and lenses
- Viewports
- Event-handling types and functions
- Rendering infrastructure
  - The rendering context
  - Rendering results
  - Rendering result lenses
  - Visibility requests
- Making lenses
- Dynamic borders
- Miscellaneous
- Renderer internals (for benchmarking)
- Re-exports for convenience
- Orphan instances

Description

Basic types used by this library.

Synopsis

- data Widget n = Widget {
  - hSize :: Size
  - vSize :: Size
  - render :: RenderM n (Result n)
  }
- data Location = Location {
  - loc :: (Int, Int)
  }
- locL :: Lens' Location (Int, Int)
- class TerminalLocation a where
  - locationColumnL :: Lens' a Int
  - locationColumn :: a -> Int
  - locationRowL :: Lens' a Int
  - locationRow :: a -> Int
- data CursorLocation n = CursorLocation {
  - cursorLocation :: !Location
  - cursorLocationName :: !(Maybe n)
  - cursorLocationVisible :: !Bool
  }
- cursorLocationL :: forall n. Lens' (CursorLocation n) Location
- cursorLocationNameL :: forall n n. Lens (CursorLocation n) (CursorLocation n) (Maybe n) (Maybe n)
- data Viewport = VP {
  - _vpLeft :: Int
  - _vpTop :: Int
  - _vpSize :: DisplayRegion
  - _vpContentSize :: DisplayRegion
  }
- data ViewportType
  - = Vertical
  - | Horizontal
  - | Both
- vpSize :: Lens' Viewport DisplayRegion
- vpTop :: Lens' Viewport Int
- vpLeft :: Lens' Viewport Int
- vpContentSize :: Lens' Viewport DisplayRegion
- data VScrollBarOrientation
  - = OnLeft
  - | OnRight
- data HScrollBarOrientation
  - = OnBottom
  - | OnTop
- data ScrollbarRenderer n = ScrollbarRenderer {
  - renderScrollbar :: Widget n
  - renderScrollbarTrough :: Widget n
  - renderScrollbarHandleBefore :: Widget n
  - renderScrollbarHandleAfter :: Widget n
  }
- data ClickableScrollbarElement
  - = SBHandleBefore
  - | SBHandleAfter
  - | SBBar
  - | SBTroughBefore
  - | SBTroughAfter
- data EventM n s a
- data BrickEvent n e
  - = VtyEvent Event
  - | AppEvent e
  - | MouseDown n Button [Modifier] Location
  - | MouseUp n (Maybe Button) Location
- nestEventM :: a -> EventM n a b -> EventM n s (a, b)
- nestEventM' :: a -> EventM n a b -> EventM n s a
- type RenderM n a = ReaderT (Context n) (State (RenderState n)) a
- getContext :: RenderM n (Context n)
- data Context n
- attrL :: forall r n. Getting r (Context n) Attr
- availWidthL :: forall n. Lens' (Context n) Int
- availHeightL :: forall n. Lens' (Context n) Int
- windowWidthL :: forall n. Lens' (Context n) Int
- windowHeightL :: forall n. Lens' (Context n) Int
- ctxVScrollBarOrientationL :: forall n. Lens' (Context n) (Maybe VScrollBarOrientation)
- ctxVScrollBarRendererL :: forall n. Lens' (Context n) (Maybe (ScrollbarRenderer n))
- ctxHScrollBarOrientationL :: forall n. Lens' (Context n) (Maybe HScrollBarOrientation)
- ctxHScrollBarRendererL :: forall n. Lens' (Context n) (Maybe (ScrollbarRenderer n))
- ctxAttrMapL :: forall n. Lens' (Context n) AttrMap
- ctxAttrNameL :: forall n. Lens' (Context n) AttrName
- ctxBorderStyleL :: forall n. Lens' (Context n) BorderStyle
- ctxDynBordersL :: forall n. Lens' (Context n) Bool
- data Result n = Result {
  - image :: !Image
  - cursors :: ![CursorLocation n]
  - visibilityRequests :: ![VisibilityRequest]
  - extents :: ![Extent n]
  - borders :: !(BorderMap DynBorder)
  }
- emptyResult :: Result n
- lookupAttrName :: AttrName -> RenderM n Attr
- data Extent n = Extent {
  - extentName :: !n
  - extentUpperLeft :: !Location
  - extentSize :: !(Int, Int)
  }
- imageL :: forall n. Lens' (Result n) Image
- cursorsL :: forall n. Lens' (Result n) [CursorLocation n]
- visibilityRequestsL :: forall n. Lens' (Result n) [VisibilityRequest]
- extentsL :: forall n. Lens' (Result n) [Extent n]
- data VisibilityRequest = VR {
  - vrPosition :: Location
  - vrSize :: DisplayRegion
  }
- vrPositionL :: Lens' VisibilityRequest Location
- vrSizeL :: Lens' VisibilityRequest DisplayRegion
- suffixLenses :: Name -> DecsQ
- suffixLensesWith :: String -> LensRules -> Name -> DecsQ
- bordersL :: forall n. Lens' (Result n) (BorderMap DynBorder)
- data DynBorder = DynBorder {
  - dbStyle :: BorderStyle
  - dbAttr :: Attr
  - dbSegments :: Edges BorderSegment
  }
- dbStyleL :: Lens' DynBorder BorderStyle
- dbAttrL :: Lens' DynBorder Attr
- dbSegmentsL :: Lens' DynBorder (Edges BorderSegment)
- data BorderSegment = BorderSegment {
  - bsAccept :: Bool
  - bsOffer :: Bool
  - bsDraw :: Bool
  }
- bsAcceptL :: Lens' BorderSegment Bool
- bsOfferL :: Lens' BorderSegment Bool
- bsDrawL :: Lens' BorderSegment Bool
- data Edges a = Edges {
  - eTop, eBottom, eLeft, eRight :: a
  }
- eTopL :: forall a. Lens' (Edges a) a
- eBottomL :: forall a. Lens' (Edges a) a
- eRightL :: forall a. Lens' (Edges a) a
- eLeftL :: forall a. Lens' (Edges a) a
- data Size
  - = Fixed
  - | Greedy
- data Direction
  - = Up
  - | Down
- data RenderState n
- get :: MonadState s m => m s
- gets :: MonadState s m => (s -> a) -> m a
- put :: MonadState s m => s -> m ()
- modify :: MonadState s m => (s -> s) -> m ()
- zoom :: Zoom m n s t => LensLike' (Zoomed m c) t s -> m c -> n c

# The Widget type

data Widget n Source #

The type of widgets.

Constructors

Widget |

Fields

- hSize :: Size

  This widget's horizontal growth policy

- vSize :: Size

  This widget's vertical growth policy

- render :: RenderM n (Result n)

  This widget's rendering function

# Location types and lenses

data Location Source #

A terminal screen location.

Constructors

Location |

Fields

- loc :: (Int, Int)

  (Column, Row)

#### Instances

Instances details

Monoid Location Source # |
Instance details Defined in Brick.Types.Common Methods mempty :: Location Source # mappend :: Location -> Location -> Location Source # mconcat :: [Location] -> Location Source #
Semigroup Location Source # |
Instance details Defined in Brick.Types.Common Methods (<>) :: Location -> Location -> Location Source # sconcat :: NonEmpty Location -> Location Source # stimes :: Integral b => b -> Location -> Location Source #
Generic Location Source # |
Instance details Defined in Brick.Types.Common Associated Types type Rep Location :: Type -> Type Source # Methods from :: Location -> Rep Location x Source # to :: Rep Location x -> Location Source #
Read Location Source # |
Instance details Defined in Brick.Types.Common Methods readsPrec :: Int -> ReadS Location Source # readList :: ReadS [Location] Source # readPrec :: ReadPrec Location Source # readListPrec :: ReadPrec [Location] Source #
Show Location Source # |
Instance details Defined in Brick.Types.Common Methods showsPrec :: Int -> Location -> ShowS Source # show :: Location -> String Source # showList :: [Location] -> ShowS Source #
TerminalLocation Location Source # |
Instance details Defined in Brick.Types.Internal Methods locationColumnL :: Lens' Location Int Source # locationColumn :: Location -> Int Source # locationRowL :: Lens' Location Int Source # locationRow :: Location -> Int Source #
NFData Location Source # |
Instance details Defined in Brick.Types.Common Methods rnf :: Location -> () Source #
Eq Location Source # |
Instance details Defined in Brick.Types.Common Methods (==) :: Location -> Location -> Bool Source # (/=) :: Location -> Location -> Bool Source #
Ord Location Source # |
Instance details Defined in Brick.Types.Common Methods compare :: Location -> Location -> Ordering Source # (<) :: Location -> Location -> Bool Source # (<=) :: Location -> Location -> Bool Source # (>) :: Location -> Location -> Bool Source # (>=) :: Location -> Location -> Bool Source # max :: Location -> Location -> Location Source # min :: Location -> Location -> Location Source #
Field1 Location Location Int Int Source # |
Instance details Defined in Brick.Types.Common Methods _1 :: Lens Location Location Int Int Source #
Field2 Location Location Int Int Source # |
Instance details Defined in Brick.Types.Common Methods _2 :: Lens Location Location Int Int Source #
type Rep Location Source # |
Instance details Defined in Brick.Types.Common type Rep Location = D1 ('MetaData "Location" "Brick.Types.Common" "brick-1.9-B374GEMQshy4UvqHBN1VYr" 'False) (C1 ('MetaCons "Location" 'PrefixI 'True) (S1 ('MetaSel ('Just "loc") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Int, Int))))

locL :: Lens' Location (Int, Int) Source #

class TerminalLocation a where Source #

The class of types that behave like terminal locations.

Methods

locationColumnL :: Lens' a Int Source #

Get the column out of the value

locationColumn :: a -> Int Source #

locationRowL :: Lens' a Int Source #

Get the row out of the value

locationRow :: a -> Int Source #

#### Instances

Instances details

TerminalLocation Location Source # |
Instance details Defined in Brick.Types.Internal Methods locationColumnL :: Lens' Location Int Source # locationColumn :: Location -> Int Source # locationRowL :: Lens' Location Int Source # locationRow :: Location -> Int Source #
TerminalLocation (CursorLocation n) Source # |
Instance details Defined in Brick.Types Methods locationColumnL :: Lens' (CursorLocation n) Int Source # locationColumn :: CursorLocation n -> Int Source # locationRowL :: Lens' (CursorLocation n) Int Source # locationRow :: CursorLocation n -> Int Source #

data CursorLocation n Source #

A cursor location. These are returned by the rendering process.

Constructors

CursorLocation |

Fields

- cursorLocation :: !Location

  The location

- cursorLocationName :: !(Maybe n)

  The name of the widget associated with the location

- cursorLocationVisible :: !Bool

  Whether the cursor should actually be visible

#### Instances

Instances details

Generic (CursorLocation n) Source # |
Instance details Defined in Brick.Types.Internal Associated Types type Rep (CursorLocation n) :: Type -> Type Source # Methods from :: CursorLocation n -> Rep (CursorLocation n) x Source # to :: Rep (CursorLocation n) x -> CursorLocation n Source #
Read n => Read (CursorLocation n) Source # |
Instance details Defined in Brick.Types.Internal Methods readsPrec :: Int -> ReadS (CursorLocation n) Source # readList :: ReadS [CursorLocation n] Source # readPrec :: ReadPrec (CursorLocation n) Source # readListPrec :: ReadPrec [CursorLocation n] Source #
Show n => Show (CursorLocation n) Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> CursorLocation n -> ShowS Source # show :: CursorLocation n -> String Source # showList :: [CursorLocation n] -> ShowS Source #
TerminalLocation (CursorLocation n) Source # |
Instance details Defined in Brick.Types Methods locationColumnL :: Lens' (CursorLocation n) Int Source # locationColumn :: CursorLocation n -> Int Source # locationRowL :: Lens' (CursorLocation n) Int Source # locationRow :: CursorLocation n -> Int Source #
NFData n => NFData (CursorLocation n) Source # |
Instance details Defined in Brick.Types.Internal Methods rnf :: CursorLocation n -> () Source #
type Rep (CursorLocation n) Source # |

Instance details

Defined in Brick.Types.Internal

type Rep (CursorLocation n) = D1 ('MetaData "CursorLocation" "Brick.Types.Internal" "brick-1.9-B374GEMQshy4UvqHBN1VYr" 'False) (C1 ('MetaCons "CursorLocation" 'PrefixI 'True) (S1 ('MetaSel ('Just "cursorLocation") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Location) :*: (S1 ('MetaSel ('Just "cursorLocationName") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe n)) :*: S1 ('MetaSel ('Just "cursorLocationVisible") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))))

cursorLocationL :: forall n. Lens' (CursorLocation n) Location Source #

cursorLocationNameL :: forall n n. Lens (CursorLocation n) (CursorLocation n) (Maybe n) (Maybe n) Source #

# Viewports

data Viewport Source #

Describes the state of a viewport as it appears as its most recent rendering.

Constructors

VP |

Fields

- _vpLeft :: Int

  The column offset of left side of the viewport.

- _vpTop :: Int

  The row offset of the top of the viewport.

- _vpSize :: DisplayRegion

  The size of the viewport.

- _vpContentSize :: DisplayRegion

  The size of the contents of the viewport.

#### Instances

Instances details

Generic Viewport Source # |
Instance details Defined in Brick.Types.Internal Associated Types type Rep Viewport :: Type -> Type Source # Methods from :: Viewport -> Rep Viewport x Source # to :: Rep Viewport x -> Viewport Source #
Read Viewport Source # |
Instance details Defined in Brick.Types.Internal Methods readsPrec :: Int -> ReadS Viewport Source # readList :: ReadS [Viewport] Source # readPrec :: ReadPrec Viewport Source # readListPrec :: ReadPrec [Viewport] Source #
Show Viewport Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> Viewport -> ShowS Source # show :: Viewport -> String Source # showList :: [Viewport] -> ShowS Source #
NFData Viewport Source # |
Instance details Defined in Brick.Types.Internal Methods rnf :: Viewport -> () Source #
type Rep Viewport Source # |

Instance details

Defined in Brick.Types.Internal

type Rep Viewport = D1 ('MetaData "Viewport" "Brick.Types.Internal" "brick-1.9-B374GEMQshy4UvqHBN1VYr" 'False) (C1 ('MetaCons "VP" 'PrefixI 'True) ((S1 ('MetaSel ('Just "_vpLeft") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "_vpTop") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "_vpSize") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DisplayRegion) :*: S1 ('MetaSel ('Just "_vpContentSize") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DisplayRegion))))

data ViewportType Source #

The type of viewports that indicates the direction(s) in which a viewport is scrollable.

Constructors

Vertical | Viewports of this type are scrollable only vertically.
Horizontal | Viewports of this type are scrollable only horizontally.
Both | Viewports of this type are scrollable vertically and horizontally.

#### Instances

Instances details

Show ViewportType Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> ViewportType -> ShowS Source # show :: ViewportType -> String Source # showList :: [ViewportType] -> ShowS Source #
Eq ViewportType Source # |
Instance details Defined in Brick.Types.Internal Methods (==) :: ViewportType -> ViewportType -> Bool Source # (/=) :: ViewportType -> ViewportType -> Bool Source #

vpSize :: Lens' Viewport DisplayRegion Source #

vpTop :: Lens' Viewport Int Source #

vpLeft :: Lens' Viewport Int Source #

vpContentSize :: Lens' Viewport DisplayRegion Source #

data VScrollBarOrientation Source #

Orientations for vertical scroll bars.

Constructors

OnLeft |
OnRight |

#### Instances

Instances details

Show VScrollBarOrientation Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> VScrollBarOrientation -> ShowS Source # show :: VScrollBarOrientation -> String Source # showList :: [VScrollBarOrientation] -> ShowS Source #
Eq VScrollBarOrientation Source # |
Instance details Defined in Brick.Types.Internal Methods (==) :: VScrollBarOrientation -> VScrollBarOrientation -> Bool Source # (/=) :: VScrollBarOrientation -> VScrollBarOrientation -> Bool Source #

data HScrollBarOrientation Source #

Orientations for horizontal scroll bars.

Constructors

OnBottom |
OnTop |

#### Instances

Instances details

Show HScrollBarOrientation Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> HScrollBarOrientation -> ShowS Source # show :: HScrollBarOrientation -> String Source # showList :: [HScrollBarOrientation] -> ShowS Source #
Eq HScrollBarOrientation Source # |
Instance details Defined in Brick.Types.Internal Methods (==) :: HScrollBarOrientation -> HScrollBarOrientation -> Bool Source # (/=) :: HScrollBarOrientation -> HScrollBarOrientation -> Bool Source #

data ScrollbarRenderer n Source #

A scroll bar renderer.

Constructors

ScrollbarRenderer |

Fields

- renderScrollbar :: Widget n

  How to render the body of the scroll bar. This should provide a widget that expands in whatever direction(s) this renderer will be used for. So, for example, if this was used to render vertical scroll bars, this widget would need to be one that expands vertically such as `fill`. The same goes for the trough widget.

- renderScrollbarTrough :: Widget n

  How to render the "trough" of the scroll bar (the area to either side of the scroll bar body). This should expand as described in the documentation for the scroll bar field.

- renderScrollbarHandleBefore :: Widget n

  How to render the handle that appears at the top or left of the scrollbar. The result should be at most one row high for horizontal handles and one column wide for vertical handles.

- renderScrollbarHandleAfter :: Widget n

  How to render the handle that appears at the bottom or right of the scrollbar. The result should be at most one row high for horizontal handles and one column wide for vertical handles.

data ClickableScrollbarElement Source #

Clickable elements of a scroll bar.

Constructors

SBHandleBefore | The handle at the beginning (left/top) of the scroll bar.
SBHandleAfter | The handle at the end (right/bottom) of the scroll bar.
SBBar | The scroll bar itself.
SBTroughBefore | The trough before the scroll bar.
SBTroughAfter | The trough after the scroll bar.

#### Instances

Instances details

Show ClickableScrollbarElement Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> ClickableScrollbarElement -> ShowS Source # show :: ClickableScrollbarElement -> String Source # showList :: [ClickableScrollbarElement] -> ShowS Source #
Eq ClickableScrollbarElement Source # |
Instance details Defined in Brick.Types.Internal Methods (==) :: ClickableScrollbarElement -> ClickableScrollbarElement -> Bool Source # (/=) :: ClickableScrollbarElement -> ClickableScrollbarElement -> Bool Source #
Ord ClickableScrollbarElement Source # |

Instance details

Defined in Brick.Types.Internal

Methods

compare :: ClickableScrollbarElement -> ClickableScrollbarElement -> Ordering Source #

(<) :: ClickableScrollbarElement -> ClickableScrollbarElement -> Bool Source #

(<=) :: ClickableScrollbarElement -> ClickableScrollbarElement -> Bool Source #

(>) :: ClickableScrollbarElement -> ClickableScrollbarElement -> Bool Source #

(>=) :: ClickableScrollbarElement -> ClickableScrollbarElement -> Bool Source #

max :: ClickableScrollbarElement -> ClickableScrollbarElement -> ClickableScrollbarElement Source #

min :: ClickableScrollbarElement -> ClickableScrollbarElement -> ClickableScrollbarElement Source #

# Event-handling types and functions

data EventM n s a Source #

The monad in which event handlers run.

#### Instances

Instances details

MonadState s (EventM n s) Source # |
Instance details Defined in Brick.Types.EventM Methods get :: EventM n s s Source # put :: s -> EventM n s () Source # state :: (s -> (a, s)) -> EventM n s a Source #
MonadIO (EventM n s) Source # |
Instance details Defined in Brick.Types.EventM Methods liftIO :: IO a -> EventM n s a Source #
Applicative (EventM n s) Source # |
Instance details Defined in Brick.Types.EventM Methods pure :: a -> EventM n s a Source # (<*>) :: EventM n s (a -> b) -> EventM n s a -> EventM n s b Source # liftA2 :: (a -> b -> c) -> EventM n s a -> EventM n s b -> EventM n s c Source # (*>) :: EventM n s a -> EventM n s b -> EventM n s b Source # (<*) :: EventM n s a -> EventM n s b -> EventM n s a Source #
Functor (EventM n s) Source # |
Instance details Defined in Brick.Types.EventM Methods fmap :: (a -> b) -> EventM n s a -> EventM n s b Source # (<$) :: a -> EventM n s b -> EventM n s a Source #
Monad (EventM n s) Source # |
Instance details Defined in Brick.Types.EventM Methods (>>=) :: EventM n s a -> (a -> EventM n s b) -> EventM n s b Source # (>>) :: EventM n s a -> EventM n s b -> EventM n s b Source # return :: a -> EventM n s a Source #
MonadCatch (EventM n s) Source # |
Instance details Defined in Brick.Types.EventM Methods catch :: Exception e => EventM n s a -> (e -> EventM n s a) -> EventM n s a Source #
MonadMask (EventM n s) Source # |
Instance details Defined in Brick.Types.EventM Methods mask :: ((forall a. EventM n s a -> EventM n s a) -> EventM n s b) -> EventM n s b Source # uninterruptibleMask :: ((forall a. EventM n s a -> EventM n s a) -> EventM n s b) -> EventM n s b Source # generalBracket :: EventM n s a -> (a -> ExitCase b -> EventM n s c) -> (a -> EventM n s b) -> EventM n s (b, c) Source #
MonadThrow (EventM n s) Source # |
Instance details Defined in Brick.Types.EventM Methods throwM :: Exception e => e -> EventM n s a Source #
Zoom (EventM n s) (EventM n t) s t Source # |
Instance details Defined in Brick.Types.EventM Methods zoom :: LensLike' (Zoomed (EventM n s) c) t s -> EventM n s c -> EventM n t c Source #
type Zoomed (EventM n s) Source # |
Instance details Defined in Brick.Types.EventM type Zoomed (EventM n s)

data BrickEvent n e Source #

The type of events.

Constructors

VtyEvent Event | The event was a Vty event.
AppEvent e | The event was an application event.
MouseDown n Button [Modifier] Location | A mouse-down event on the specified region was received. The `n` value is the resource name of the clicked widget (see `clickable`).
MouseUp n (Maybe Button) Location | A mouse-up event on the specified region was received. The `n` value is the resource name of the clicked widget (see `clickable`).

#### Instances

Instances details

(Show e, Show n) => Show (BrickEvent n e) Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> BrickEvent n e -> ShowS Source # show :: BrickEvent n e -> String Source # showList :: [BrickEvent n e] -> ShowS Source #
(Eq e, Eq n) => Eq (BrickEvent n e) Source # |
Instance details Defined in Brick.Types.Internal Methods (==) :: BrickEvent n e -> BrickEvent n e -> Bool Source # (/=) :: BrickEvent n e -> BrickEvent n e -> Bool Source #
(Ord e, Ord n) => Ord (BrickEvent n e) Source # |

Instance details

Defined in Brick.Types.Internal

Methods

compare :: BrickEvent n e -> BrickEvent n e -> Ordering Source #

(<) :: BrickEvent n e -> BrickEvent n e -> Bool Source #

(<=) :: BrickEvent n e -> BrickEvent n e -> Bool Source #

(>) :: BrickEvent n e -> BrickEvent n e -> Bool Source #

(>=) :: BrickEvent n e -> BrickEvent n e -> Bool Source #

max :: BrickEvent n e -> BrickEvent n e -> BrickEvent n e Source #

min :: BrickEvent n e -> BrickEvent n e -> BrickEvent n e Source #

nestEventM Source #

Arguments

:: a | The initial state to use in the nested action.
-> EventM n a b | The action to run.
-> EventM n s (a, b) |

Given a state value and an `EventM` that mutates that state, run the specified action and return both the resulting modified state and the result of the action itself.

nestEventM' Source #

Arguments

:: a | The initial state to use in the nested action.
-> EventM n a b | The action to run.
-> EventM n s a |

Given a state value and an `EventM` that mutates that state, run the specified action and return resulting modified state.

# Rendering infrastructure

type RenderM n a = ReaderT (Context n) (State (RenderState n)) a Source #

The type of the rendering monad. This monad is used by the library's rendering routines to manage rendering state and communicate rendering parameters to widgets' rendering functions.

getContext :: RenderM n (Context n) Source #

Get the current rendering context.

## The rendering context

data Context n Source #

The rendering context. This tells widgets how to render: how much space they have in which to render, which attribute they should use to render, which bordering style should be used, and the attribute map available for rendering.

attrL :: forall r n. Getting r (Context n) Attr Source #

The rendering context's current drawing attribute.

availWidthL :: forall n. Lens' (Context n) Int Source #

availHeightL :: forall n. Lens' (Context n) Int Source #

windowWidthL :: forall n. Lens' (Context n) Int Source #

windowHeightL :: forall n. Lens' (Context n) Int Source #

ctxVScrollBarOrientationL :: forall n. Lens' (Context n) (Maybe VScrollBarOrientation) Source #

ctxVScrollBarRendererL :: forall n. Lens' (Context n) (Maybe (ScrollbarRenderer n)) Source #

ctxHScrollBarOrientationL :: forall n. Lens' (Context n) (Maybe HScrollBarOrientation) Source #

ctxHScrollBarRendererL :: forall n. Lens' (Context n) (Maybe (ScrollbarRenderer n)) Source #

ctxAttrMapL :: forall n. Lens' (Context n) AttrMap Source #

ctxAttrNameL :: forall n. Lens' (Context n) AttrName Source #

ctxBorderStyleL :: forall n. Lens' (Context n) BorderStyle Source #

ctxDynBordersL :: forall n. Lens' (Context n) Bool Source #

## Rendering results

data Result n Source #

The type of result returned by a widget's rendering function. The result provides the image, cursor positions, and visibility requests that resulted from the rendering process.

Constructors

Result |

Fields

- image :: !Image

  The final rendered image for a widget

- cursors :: ![CursorLocation n]

  The list of reported cursor positions for the application to choose from

- visibilityRequests :: ![VisibilityRequest]

  The list of visibility requests made by widgets rendered while rendering this one (used by viewports)

- extents :: ![Extent n]
- borders :: !(BorderMap DynBorder)

  Places where we may rewrite the edge of the image when placing this widget next to another one.

#### Instances

Instances details

Generic (Result n) Source # |
Instance details Defined in Brick.Types.Internal Associated Types type Rep (Result n) :: Type -> Type Source # Methods from :: Result n -> Rep (Result n) x Source # to :: Rep (Result n) x -> Result n Source #
Read n => Read (Result n) Source # |
Instance details Defined in Brick.Types.Internal Methods readsPrec :: Int -> ReadS (Result n) Source # readList :: ReadS [Result n] Source # readPrec :: ReadPrec (Result n) Source # readListPrec :: ReadPrec [Result n] Source #
Show n => Show (Result n) Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> Result n -> ShowS Source # show :: Result n -> String Source # showList :: [Result n] -> ShowS Source #
NFData n => NFData (Result n) Source # |
Instance details Defined in Brick.Types.Internal Methods rnf :: Result n -> () Source #
type Rep (Result n) Source # |

Instance details

Defined in Brick.Types.Internal

type Rep (Result n) = D1 ('MetaData "Result" "Brick.Types.Internal" "brick-1.9-B374GEMQshy4UvqHBN1VYr" 'False) (C1 ('MetaCons "Result" 'PrefixI 'True) ((S1 ('MetaSel ('Just "image") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Image) :*: S1 ('MetaSel ('Just "cursors") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [CursorLocation n])) :*: (S1 ('MetaSel ('Just "visibilityRequests") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [VisibilityRequest]) :*: (S1 ('MetaSel ('Just "extents") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Extent n]) :*: S1 ('MetaSel ('Just "borders") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (BorderMap DynBorder))))))

emptyResult :: Result n Source #

lookupAttrName :: AttrName -> RenderM n Attr Source #

Given an attribute name, obtain the attribute for the attribute name by consulting the context's attribute map.

data Extent n Source #

An extent of a named area: its size, location, and origin.

Constructors

Extent |

Fields

- extentName :: !n
- extentUpperLeft :: !Location
- extentSize :: !(Int, Int)

#### Instances

Instances details

Generic (Extent n) Source # |
Instance details Defined in Brick.Types.Internal Associated Types type Rep (Extent n) :: Type -> Type Source # Methods from :: Extent n -> Rep (Extent n) x Source # to :: Rep (Extent n) x -> Extent n Source #
Read n => Read (Extent n) Source # |
Instance details Defined in Brick.Types.Internal Methods readsPrec :: Int -> ReadS (Extent n) Source # readList :: ReadS [Extent n] Source # readPrec :: ReadPrec (Extent n) Source # readListPrec :: ReadPrec [Extent n] Source #
Show n => Show (Extent n) Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> Extent n -> ShowS Source # show :: Extent n -> String Source # showList :: [Extent n] -> ShowS Source #
NFData n => NFData (Extent n) Source # |
Instance details Defined in Brick.Types.Internal Methods rnf :: Extent n -> () Source #
type Rep (Extent n) Source # |

Instance details

Defined in Brick.Types.Internal

type Rep (Extent n) = D1 ('MetaData "Extent" "Brick.Types.Internal" "brick-1.9-B374GEMQshy4UvqHBN1VYr" 'False) (C1 ('MetaCons "Extent" 'PrefixI 'True) (S1 ('MetaSel ('Just "extentName") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 n) :*: (S1 ('MetaSel ('Just "extentUpperLeft") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Location) :*: S1 ('MetaSel ('Just "extentSize") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Int, Int)))))

## Rendering result lenses

imageL :: forall n. Lens' (Result n) Image Source #

cursorsL :: forall n. Lens' (Result n) [CursorLocation n] Source #

visibilityRequestsL :: forall n. Lens' (Result n) [VisibilityRequest] Source #

extentsL :: forall n. Lens' (Result n) [Extent n] Source #

## Visibility requests

data VisibilityRequest Source #

Constructors

VR |

Fields

- vrPosition :: Location
- vrSize :: DisplayRegion

#### Instances

Instances details

Generic VisibilityRequest Source # |
Instance details Defined in Brick.Types.Internal Associated Types type Rep VisibilityRequest :: Type -> Type Source # Methods from :: VisibilityRequest -> Rep VisibilityRequest x Source # to :: Rep VisibilityRequest x -> VisibilityRequest Source #
Read VisibilityRequest Source # |
Instance details Defined in Brick.Types.Internal Methods readsPrec :: Int -> ReadS VisibilityRequest Source # readList :: ReadS [VisibilityRequest] Source # readPrec :: ReadPrec VisibilityRequest Source # readListPrec :: ReadPrec [VisibilityRequest] Source #
Show VisibilityRequest Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> VisibilityRequest -> ShowS Source # show :: VisibilityRequest -> String Source # showList :: [VisibilityRequest] -> ShowS Source #
NFData VisibilityRequest Source # |
Instance details Defined in Brick.Types.Internal Methods rnf :: VisibilityRequest -> () Source #
Eq VisibilityRequest Source # |
Instance details Defined in Brick.Types.Internal Methods (==) :: VisibilityRequest -> VisibilityRequest -> Bool Source # (/=) :: VisibilityRequest -> VisibilityRequest -> Bool Source #
type Rep VisibilityRequest Source # |

Instance details

Defined in Brick.Types.Internal

type Rep VisibilityRequest = D1 ('MetaData "VisibilityRequest" "Brick.Types.Internal" "brick-1.9-B374GEMQshy4UvqHBN1VYr" 'False) (C1 ('MetaCons "VR" 'PrefixI 'True) (S1 ('MetaSel ('Just "vrPosition") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Location) :*: S1 ('MetaSel ('Just "vrSize") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DisplayRegion)))

vrPositionL :: Lens' VisibilityRequest Location Source #

vrSizeL :: Lens' VisibilityRequest DisplayRegion Source #

# Making lenses

suffixLenses :: Name -> DecsQ Source #

A template haskell function to build lenses for a record type. This function differs from the `makeLenses` function in that it does not require the record fields to be prefixed with underscores and it adds an L suffix to lens names to make it clear that they are lenses.

suffixLensesWith :: String -> LensRules -> Name -> DecsQ Source #

A more general version of `suffixLenses` that allows customization of the lens-building rules and allows customization of the suffix.

# Dynamic borders

bordersL :: forall n. Lens' (Result n) (BorderMap DynBorder) Source #

data DynBorder Source #

Information about how to redraw a dynamic border character when it abuts another dynamic border character.

Constructors

DynBorder |

Fields

- dbStyle :: BorderStyle

  The `Char`s to use when redrawing the border. Also used to filter connections: only dynamic borders with equal `BorderStyle`s will connect to each other.

- dbAttr :: Attr

  What `Attr` to use to redraw the border character. Also used to filter connections: only dynamic borders with equal `Attr`s will connect to each other.

- dbSegments :: Edges BorderSegment

#### Instances

Instances details

Generic DynBorder Source # |
Instance details Defined in Brick.Types.Internal Associated Types type Rep DynBorder :: Type -> Type Source # Methods from :: DynBorder -> Rep DynBorder x Source # to :: Rep DynBorder x -> DynBorder Source #
Read DynBorder Source # |
Instance details Defined in Brick.Types.Internal Methods readsPrec :: Int -> ReadS DynBorder Source # readList :: ReadS [DynBorder] Source # readPrec :: ReadPrec DynBorder Source # readListPrec :: ReadPrec [DynBorder] Source #
Show DynBorder Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> DynBorder -> ShowS Source # show :: DynBorder -> String Source # showList :: [DynBorder] -> ShowS Source #
NFData DynBorder Source # |
Instance details Defined in Brick.Types.Internal Methods rnf :: DynBorder -> () Source #
Eq DynBorder Source # |
Instance details Defined in Brick.Types.Internal Methods (==) :: DynBorder -> DynBorder -> Bool Source # (/=) :: DynBorder -> DynBorder -> Bool Source #
type Rep DynBorder Source # |

Instance details

Defined in Brick.Types.Internal

type Rep DynBorder = D1 ('MetaData "DynBorder" "Brick.Types.Internal" "brick-1.9-B374GEMQshy4UvqHBN1VYr" 'False) (C1 ('MetaCons "DynBorder" 'PrefixI 'True) (S1 ('MetaSel ('Just "dbStyle") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BorderStyle) :*: (S1 ('MetaSel ('Just "dbAttr") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Attr) :*: S1 ('MetaSel ('Just "dbSegments") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Edges BorderSegment)))))

dbStyleL :: Lens' DynBorder BorderStyle Source #

dbAttrL :: Lens' DynBorder Attr Source #

dbSegmentsL :: Lens' DynBorder (Edges BorderSegment) Source #

data BorderSegment Source #

A border character has four segments, one extending in each direction (horizontally and vertically) from the center of the character.

Constructors

BorderSegment |

Fields

- bsAccept :: Bool

  Would this segment be willing to be drawn if a neighbor wanted to connect to it?

- bsOffer :: Bool

  Does this segment want to connect to its neighbor?

- bsDraw :: Bool

  Should this segment be represented visually?

#### Instances

Instances details

Generic BorderSegment Source # |
Instance details Defined in Brick.Types.Internal Associated Types type Rep BorderSegment :: Type -> Type Source # Methods from :: BorderSegment -> Rep BorderSegment x Source # to :: Rep BorderSegment x -> BorderSegment Source #
Read BorderSegment Source # |
Instance details Defined in Brick.Types.Internal Methods readsPrec :: Int -> ReadS BorderSegment Source # readList :: ReadS [BorderSegment] Source # readPrec :: ReadPrec BorderSegment Source # readListPrec :: ReadPrec [BorderSegment] Source #
Show BorderSegment Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> BorderSegment -> ShowS Source # show :: BorderSegment -> String Source # showList :: [BorderSegment] -> ShowS Source #
NFData BorderSegment Source # |
Instance details Defined in Brick.Types.Internal Methods rnf :: BorderSegment -> () Source #
Eq BorderSegment Source # |
Instance details Defined in Brick.Types.Internal Methods (==) :: BorderSegment -> BorderSegment -> Bool Source # (/=) :: BorderSegment -> BorderSegment -> Bool Source #
Ord BorderSegment Source # |

Instance details

Defined in Brick.Types.Internal

Methods

compare :: BorderSegment -> BorderSegment -> Ordering Source #

(<) :: BorderSegment -> BorderSegment -> Bool Source #

(<=) :: BorderSegment -> BorderSegment -> Bool Source #

(>) :: BorderSegment -> BorderSegment -> Bool Source #

(>=) :: BorderSegment -> BorderSegment -> Bool Source #

max :: BorderSegment -> BorderSegment -> BorderSegment Source #

min :: BorderSegment -> BorderSegment -> BorderSegment Source #

type Rep BorderSegment Source # |

Instance details

Defined in Brick.Types.Internal

type Rep BorderSegment = D1 ('MetaData "BorderSegment" "Brick.Types.Internal" "brick-1.9-B374GEMQshy4UvqHBN1VYr" 'False) (C1 ('MetaCons "BorderSegment" 'PrefixI 'True) (S1 ('MetaSel ('Just "bsAccept") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: (S1 ('MetaSel ('Just "bsOffer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "bsDraw") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))))

bsAcceptL :: Lens' BorderSegment Bool Source #

bsOfferL :: Lens' BorderSegment Bool Source #

bsDrawL :: Lens' BorderSegment Bool Source #

data Edges a Source #

Constructors

Edges |

Fields

- eTop, eBottom, eLeft, eRight :: a

#### Instances

Instances details

Applicative Edges Source # |
Instance details Defined in Brick.Types.Common Methods pure :: a -> Edges a Source # (<*>) :: Edges (a -> b) -> Edges a -> Edges b Source # liftA2 :: (a -> b -> c) -> Edges a -> Edges b -> Edges c Source # (*>) :: Edges a -> Edges b -> Edges b Source # (<*) :: Edges a -> Edges b -> Edges a Source #
Functor Edges Source # |
Instance details Defined in Brick.Types.Common Methods fmap :: (a -> b) -> Edges a -> Edges b Source # (<$) :: a -> Edges b -> Edges a Source #
Monad Edges Source # |
Instance details Defined in Brick.Types.Common Methods (>>=) :: Edges a -> (a -> Edges b) -> Edges b Source # (>>) :: Edges a -> Edges b -> Edges b Source # return :: a -> Edges a Source #
Generic (Edges a) Source # |
Instance details Defined in Brick.Types.Common Associated Types type Rep (Edges a) :: Type -> Type Source # Methods from :: Edges a -> Rep (Edges a) x Source # to :: Rep (Edges a) x -> Edges a Source #
Read a => Read (Edges a) Source # |
Instance details Defined in Brick.Types.Common Methods readsPrec :: Int -> ReadS (Edges a) Source # readList :: ReadS [Edges a] Source # readPrec :: ReadPrec (Edges a) Source # readListPrec :: ReadPrec [Edges a] Source #
Show a => Show (Edges a) Source # |
Instance details Defined in Brick.Types.Common Methods showsPrec :: Int -> Edges a -> ShowS Source # show :: Edges a -> String Source # showList :: [Edges a] -> ShowS Source #
NFData a => NFData (Edges a) Source # |
Instance details Defined in Brick.Types.Common Methods rnf :: Edges a -> () Source #
Eq a => Eq (Edges a) Source # |
Instance details Defined in Brick.Types.Common Methods (==) :: Edges a -> Edges a -> Bool Source # (/=) :: Edges a -> Edges a -> Bool Source #
Ord a => Ord (Edges a) Source # |
Instance details Defined in Brick.Types.Common Methods compare :: Edges a -> Edges a -> Ordering Source # (<) :: Edges a -> Edges a -> Bool Source # (<=) :: Edges a -> Edges a -> Bool Source # (>) :: Edges a -> Edges a -> Bool Source # (>=) :: Edges a -> Edges a -> Bool Source # max :: Edges a -> Edges a -> Edges a Source # min :: Edges a -> Edges a -> Edges a Source #
type Rep (Edges a) Source # |

Instance details

Defined in Brick.Types.Common

type Rep (Edges a) = D1 ('MetaData "Edges" "Brick.Types.Common" "brick-1.9-B374GEMQshy4UvqHBN1VYr" 'False) (C1 ('MetaCons "Edges" 'PrefixI 'True) ((S1 ('MetaSel ('Just "eTop") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "eBottom") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :*: (S1 ('MetaSel ('Just "eLeft") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "eRight") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a))))

eTopL :: forall a. Lens' (Edges a) a Source #

eBottomL :: forall a. Lens' (Edges a) a Source #

eRightL :: forall a. Lens' (Edges a) a Source #

eLeftL :: forall a. Lens' (Edges a) a Source #

# Miscellaneous

data Size Source #

Widget size policies. These policies communicate how a widget uses space when being rendered. These policies influence rendering order and space allocation in the box layout algorithm for `hBox` and `vBox`.

Constructors

Fixed | Widgets advertising this size policy should take up the same amount of space no matter how much they are given, i.e. their size depends on their contents alone rather than on the size of the rendering area.
Greedy | Widgets advertising this size policy must take up all the space they are given.

#### Instances

Instances details

Show Size Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> Size -> ShowS Source # show :: Size -> String Source # showList :: [Size] -> ShowS Source #
Eq Size Source # |
Instance details Defined in Brick.Types.Internal Methods (==) :: Size -> Size -> Bool Source # (/=) :: Size -> Size -> Bool Source #
Ord Size Source # |
Instance details Defined in Brick.Types.Internal Methods compare :: Size -> Size -> Ordering Source # (<) :: Size -> Size -> Bool Source # (<=) :: Size -> Size -> Bool Source # (>) :: Size -> Size -> Bool Source # (>=) :: Size -> Size -> Bool Source # max :: Size -> Size -> Size Source # min :: Size -> Size -> Size Source #

data Direction Source #

Scrolling direction.

Constructors

Up | Up/left
Down | Down/right

#### Instances

Instances details

Generic Direction Source # |
Instance details Defined in Brick.Types.Internal Associated Types type Rep Direction :: Type -> Type Source # Methods from :: Direction -> Rep Direction x Source # to :: Rep Direction x -> Direction Source #
Read Direction Source # |
Instance details Defined in Brick.Types.Internal Methods readsPrec :: Int -> ReadS Direction Source # readList :: ReadS [Direction] Source # readPrec :: ReadPrec Direction Source # readListPrec :: ReadPrec [Direction] Source #
Show Direction Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> Direction -> ShowS Source # show :: Direction -> String Source # showList :: [Direction] -> ShowS Source #
NFData Direction Source # |
Instance details Defined in Brick.Types.Internal Methods rnf :: Direction -> () Source #
Eq Direction Source # |
Instance details Defined in Brick.Types.Internal Methods (==) :: Direction -> Direction -> Bool Source # (/=) :: Direction -> Direction -> Bool Source #
type Rep Direction Source # |
Instance details Defined in Brick.Types.Internal type Rep Direction = D1 ('MetaData "Direction" "Brick.Types.Internal" "brick-1.9-B374GEMQshy4UvqHBN1VYr" 'False) (C1 ('MetaCons "Up" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Down" 'PrefixI 'False) (U1 :: Type -> Type))

# Renderer internals (for benchmarking)

data RenderState n Source #

#### Instances

Instances details

Generic (RenderState n) Source # |
Instance details Defined in Brick.Types.Internal Associated Types type Rep (RenderState n) :: Type -> Type Source # Methods from :: RenderState n -> Rep (RenderState n) x Source # to :: Rep (RenderState n) x -> RenderState n Source #
(Ord n, Read n) => Read (RenderState n) Source # |
Instance details Defined in Brick.Types.Internal Methods readsPrec :: Int -> ReadS (RenderState n) Source # readList :: ReadS [RenderState n] Source # readPrec :: ReadPrec (RenderState n) Source # readListPrec :: ReadPrec [RenderState n] Source #
Show n => Show (RenderState n) Source # |
Instance details Defined in Brick.Types.Internal Methods showsPrec :: Int -> RenderState n -> ShowS Source # show :: RenderState n -> String Source # showList :: [RenderState n] -> ShowS Source #
NFData n => NFData (RenderState n) Source # |
Instance details Defined in Brick.Types.Internal Methods rnf :: RenderState n -> () Source #
type Rep (RenderState n) Source # |
Instance details Defined in Brick.Types.Internal type Rep (RenderState n)

# Re-exports for convenience

get :: MonadState s m => m s Source #

Return the state from the internals of the monad.

gets :: MonadState s m => (s -> a) -> m a Source #

Gets specific component of the state, using a projection function supplied.

put :: MonadState s m => s -> m () Source #

Replace the state inside the monad.

modify :: MonadState s m => (s -> s) -> m () Source #

Monadic state transformer.

Maps an old state to a new state inside a state monad. The old state is thrown away.

         Main> :t modify ((+1) :: Int -> Int)
         modify (...) :: (MonadState Int a) => a ()

This says that `modify (+1)` acts over any Monad that is a member of the `MonadState` class, with an `Int` state.

zoom :: Zoom m n s t => LensLike' (Zoomed m c) t s -> m c -> n c infixr 2 Source #

When you're in a state monad, this function lets you operate on a part of your state. For instance, if your state was a record containing a `position` field, after zooming `position` would become your whole state (and when you modify it, the bigger structure would be modified as well).

(Your `State` / `StateT` or `RWS` / `RWST` can be anywhere in the stack, but you can't use `zoom` with arbitrary `MonadState` because it doesn't provide any methods to change the type of the state. See this issue for details.)

For the sake of the example, let's define some types first:

    data Position = Position {
      _x, _y :: Int }

    data Player = Player {
      _position :: Position,
      ... }

    data Game = Game {
      _player :: Player,
      _obstacles :: [Position],
      ... }

    concat <$> mapM makeLenses [''Position, ''Player, ''Game]

Now, here's an action that moves the player north-east:

    moveNE :: State Game ()
    moveNE = do
      player.position.x += 1
      player.position.y += 1

With `zoom`, you can use `player.position` to focus just on a part of the state:

    moveNE :: State Game ()
    moveNE = do
      zoom (player.position) $ do
        x += 1
        y += 1

You can just as well use it for retrieving things out of the state:

    getCoords :: State Game (Int, Int)
    getCoords = zoom (player.position) ((,) <$> use x <*> use y)

Or more explicitly:

    getCoords = zoom (player.position) $ do
      x' <- use x
      y' <- use y
      return (x', y')

When you pass a traversal to `zoom`, it'll work as a loop. For instance, here we move all obstacles:

    moveObstaclesNE :: State Game ()
    moveObstaclesNE = do
      zoom (obstacles.each) $ do
        x += 1
        y += 1

If the action returns a result, all results would be combined with `<>` – the same way they're combined when `^.` is passed a traversal. In this example, `moveObstaclesNE` returns a list of old coordinates of obstacles in addition to moving them:

    moveObstaclesNE = do
      xys <- zoom (obstacles.each) $ do
        -- Get old coordinates.
        x' <- use x
        y' <- use y
        -- Update them.
        x .= x' + 1
        y .= y' + 1
        -- Return a single-element list with old coordinates.
        return [(x', y')]
      ...

Finally, you might need to write your own instances of `Zoom` if you use `newtype`d transformers in your monad stack. This can be done as follows:

    import Lens.Micro.Mtl.Internal

    type instance Zoomed (MyStateT s m) = Zoomed (StateT s m)

    instance Monad m => Zoom (MyStateT s m) (MyStateT t m) s t where
        zoom l (MyStateT m) = MyStateT (zoom l m)

# Orphan instances

TerminalLocation (CursorLocation n) Source # |
Instance details Methods locationColumnL :: Lens' (CursorLocation n) Int Source # locationColumn :: CursorLocation n -> Int Source # locationRowL :: Lens' (CursorLocation n) Int Source # locationRow :: CursorLocation n -> Int Source #