brick-0.18: A declarative terminal user interface library

Safe Haskell | None
Language | Haskell2010

Brick.Types

Contents

- The Widget type
- Location types and lenses
- Viewports
- Event-handling types
- Rendering infrastructure
  - The rendering context
  - Rendering results
  - Rendering result lenses
  - Visibility requests
- Making lenses
- Miscellaneous
- 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
- data CursorLocation n = CursorLocation {
  - cursorLocation :: !Location
  - cursorLocationName :: !(Maybe n)
  }
- 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
  }
- data ViewportType
  - = Vertical
  - | Horizontal
  - | Both
- vpSize :: Lens' Viewport DisplayRegion
- vpTop :: Lens' Viewport Int
- vpLeft :: Lens' Viewport Int
- newtype EventM n a = EventM {
  - runEventM :: ReaderT (EventRO n) (StateT (EventState n) IO) a
  }
- data Next a
- data BrickEvent n e
  - = VtyEvent Event
  - | AppEvent e
  - | MouseDown n Button [Modifier] Location
  - | MouseUp n (Maybe Button) Location
- handleEventLensed :: a -> Lens' a b -> (e -> b -> EventM n b) -> e -> EventM n a
- type RenderM n a = ReaderT Context (State (RenderState n)) a
- getContext :: RenderM n Context
- data Context
- attrL :: forall r. Getting r Context Attr
- availWidthL :: Lens' Context Int
- availHeightL :: Lens' Context Int
- ctxAttrMapL :: Lens' Context AttrMap
- ctxAttrNameL :: Lens' Context AttrName
- ctxBorderStyleL :: Lens' Context BorderStyle
- data Result n = Result {
  - image :: Image
  - cursors :: [CursorLocation n]
  - visibilityRequests :: [VisibilityRequest]
  - extents :: [Extent n]
  }
- emptyResult :: Result n
- lookupAttrName :: AttrName -> RenderM n Attr
- data Extent n = Extent {
  - extentName :: n
  - extentUpperLeft :: Location
  - extentSize :: (Int, Int)
  - extentOffset :: Location
  }
- 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
- data Size
  - = Fixed
  - | Greedy
- data Padding
  - = Pad Int
  - | Max
- data Direction
  - = Up
  - | Down

# 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

Eq Location Source # |
Methods (==) :: Location -> Location -> Bool # (/=) :: Location -> Location -> Bool #
Show Location Source # |
Methods showsPrec :: Int -> Location -> ShowS # show :: Location -> String # showList :: [Location] -> ShowS #
Monoid Location Source # |
Methods mempty :: Location # mappend :: Location -> Location -> Location # mconcat :: [Location] -> Location #
TerminalLocation Location Source # |
Methods locationColumnL :: Lens' Location Int Source # locationColumn :: Location -> Int Source # locationRowL :: Lens' Location Int Source # locationRow :: Location -> Int Source #
Field1 Location Location Int Int Source # |
Methods _1 :: Lens Location Location Int Int #
Field2 Location Location Int Int Source # |
Methods _2 :: Lens Location Location Int Int #

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

class TerminalLocation a where Source #

The class of types that behave like terminal locations.

Minimal complete definition

locationColumnL, locationColumn, locationRowL, locationRow

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

TerminalLocation Location Source # |
Methods locationColumnL :: Lens' Location Int Source # locationColumn :: Location -> Int Source # locationRowL :: Lens' Location Int Source # locationRow :: Location -> 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

Instances

Show n => Show (CursorLocation n) Source # |
Methods showsPrec :: Int -> CursorLocation n -> ShowS # show :: CursorLocation n -> String # showList :: [CursorLocation n] -> ShowS #

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.

Instances

Show Viewport Source # |
Methods showsPrec :: Int -> Viewport -> ShowS # show :: Viewport -> String # showList :: [Viewport] -> ShowS #

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

Eq ViewportType Source # |
Methods (==) :: ViewportType -> ViewportType -> Bool # (/=) :: ViewportType -> ViewportType -> Bool #
Show ViewportType Source # |
Methods showsPrec :: Int -> ViewportType -> ShowS # show :: ViewportType -> String # showList :: [ViewportType] -> ShowS #

vpSize :: Lens' Viewport DisplayRegion Source #

vpTop :: Lens' Viewport Int Source #

vpLeft :: Lens' Viewport Int Source #

# Event-handling types

newtype EventM n a Source #

The monad in which event handlers run. Although it may be tempting to dig into the reader value yourself, just use `lookupViewport`.

Constructors

EventM |

Fields

- runEventM :: ReaderT (EventRO n) (StateT (EventState n) IO) a

Instances

Monad (EventM n) Source # |
Methods (>>=) :: EventM n a -> (a -> EventM n b) -> EventM n b # (>>) :: EventM n a -> EventM n b -> EventM n b # return :: a -> EventM n a # fail :: String -> EventM n a #
Functor (EventM n) Source # |
Methods fmap :: (a -> b) -> EventM n a -> EventM n b # (<$) :: a -> EventM n b -> EventM n a #
Applicative (EventM n) Source # |
Methods pure :: a -> EventM n a # (<*>) :: EventM n (a -> b) -> EventM n a -> EventM n b # (*>) :: EventM n a -> EventM n b -> EventM n b # (<*) :: EventM n a -> EventM n b -> EventM n a #
MonadIO (EventM n) Source # |
Methods liftIO :: IO a -> EventM n a #

data Next a Source #

The type of actions to take upon completion of an event handler.

Instances

Functor Next Source # |
Methods fmap :: (a -> b) -> Next a -> Next b # (<$) :: a -> Next b -> Next a #

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.
MouseUp n (Maybe Button) Location | A mouse-up event on the specified region was received.

Instances

(Eq n, Eq e) => Eq (BrickEvent n e) Source # |
Methods (==) :: BrickEvent n e -> BrickEvent n e -> Bool # (/=) :: BrickEvent n e -> BrickEvent n e -> Bool #
(Show n, Show e) => Show (BrickEvent n e) Source # |
Methods showsPrec :: Int -> BrickEvent n e -> ShowS # show :: BrickEvent n e -> String # showList :: [BrickEvent n e] -> ShowS #

handleEventLensed Source #

Arguments

:: a | The state value.
-> Lens' a b | The lens to use to extract and store the target of the event.
-> (e -> b -> EventM n b) | The event handler.
-> e | The event to handle.
-> EventM n a |

A convenience function for handling events intended for values that are targets of lenses in your application state. This function obtains the target value of the specified lens, invokes `handleEvent` on it, and stores the resulting transformed value back in the state using the lens.

# Rendering infrastructure

type RenderM n a = ReaderT Context (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 Source #

Get the current rendering context.

## The rendering context

data Context 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.

Instances

Show Context Source # |
Methods showsPrec :: Int -> Context -> ShowS # show :: Context -> String # showList :: [Context] -> ShowS #

attrL :: forall r. Getting r Context Attr Source #

The rendering context's current drawing attribute.

availWidthL :: Lens' Context Int Source #

availHeightL :: Lens' Context Int Source #

ctxAttrMapL :: Lens' Context AttrMap Source #

ctxAttrNameL :: Lens' Context AttrName Source #

ctxBorderStyleL :: Lens' Context BorderStyle 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]

Instances

Show n => Show (Result n) Source # |
Methods showsPrec :: Int -> Result n -> ShowS # show :: Result n -> String # showList :: [Result n] -> ShowS #

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)
- extentOffset :: Location

Instances

Show n => Show (Extent n) Source # |
Methods showsPrec :: Int -> Extent n -> ShowS # show :: Extent n -> String # showList :: [Extent n] -> ShowS #

## 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

Eq VisibilityRequest Source # |
Methods (==) :: VisibilityRequest -> VisibilityRequest -> Bool # (/=) :: VisibilityRequest -> VisibilityRequest -> Bool #
Show VisibilityRequest Source # |
Methods showsPrec :: Int -> VisibilityRequest -> ShowS # show :: VisibilityRequest -> String # showList :: [VisibilityRequest] -> ShowS #

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.

# Miscellaneous

data Size Source #

Widget growth policies. These policies communicate to layout algorithms how a widget uses space when being rendered. These policies influence rendering order and space allocation in the box layout algorithm.

Constructors

Fixed | Fixed widgets take up the same amount of space no matter how much they are given (non-greedy).
Greedy | Greedy widgets take up all the space they are given.

Instances

Eq Size Source # |
Methods (==) :: Size -> Size -> Bool # (/=) :: Size -> Size -> Bool #
Ord Size Source # |
Methods compare :: Size -> Size -> Ordering # (<) :: Size -> Size -> Bool # (<=) :: Size -> Size -> Bool # (>) :: Size -> Size -> Bool # (>=) :: Size -> Size -> Bool # max :: Size -> Size -> Size # min :: Size -> Size -> Size #
Show Size Source # |
Methods showsPrec :: Int -> Size -> ShowS # show :: Size -> String # showList :: [Size] -> ShowS #

data Padding Source #

The type of padding.

Constructors

Pad Int | Pad by the specified number of rows or columns.
Max | Pad up to the number of available rows or columns.

data Direction Source #

Scrolling direction.

Constructors

Up | Up/left
Down | Down/right

Instances

Eq Direction Source # |
Methods (==) :: Direction -> Direction -> Bool # (/=) :: Direction -> Direction -> Bool #
Show Direction Source # |
Methods showsPrec :: Int -> Direction -> ShowS # show :: Direction -> String # showList :: [Direction] -> ShowS #

# Orphan instances

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