Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- twoColumnText :: Int -> Text -> Text -> Widget n
- columns :: (a -> Widget n) -> [AttrName] -> [Int] -> [a] -> Widget n
- searchWidget :: (Ord n, Show n) => Bool -> Text -> Editor Text n -> Widget n
- searchWidgetAux :: (Ord n, Show n) => Bool -> Text -> Editor Text n -> Widget n -> Widget n
- headingAndBody :: Text -> Text -> Widget n
- listWithHighlights :: (Foldable f, Ord n, Show n) => Text -> (a -> f Text) -> Bool -> List n a -> Widget n
- columnsListWithHighlights :: (Foldable f, Ord n, Show n) => Text -> (a -> [f Text]) -> [AttrName] -> [Int] -> Bool -> List n a -> Widget n
- theMain :: Ord n => App b e n -> BChan e -> b -> IO b
- data Event
- = EvKey Key [Modifier]
- | EvMouseDown Int Int Button [Modifier]
- | EvMouseUp Int Int (Maybe Button)
- | EvResize Int Int
- | EvPaste ByteString
- | EvLostFocus
- | EvGainedFocus
- data Attr
- markup :: (Eq a, GetAttr a) => Markup a -> Widget n
- (@?) :: Text -> AttrName -> Markup AttrName
- class GetAttr a
- toText :: Eq a => Markup a -> Text
- data Markup a
- listSelectedElement :: forall (t :: Type -> Type) n e. (Splittable t, Foldable t) => GenericList n t e -> Maybe (Int, e)
- listReplace :: (Foldable t, Splittable t) => t e -> Maybe Int -> GenericList n t e -> GenericList n t e
- renderListWithIndex :: forall (t :: Type -> Type) n e. (Traversable t, Splittable t, Ord n, Show n) => (Int -> Bool -> e -> Widget n) -> Bool -> GenericList n t e -> Widget n
- renderList :: forall (t :: Type -> Type) n e. (Traversable t, Splittable t, Ord n, Show n) => (Bool -> e -> Widget n) -> Bool -> GenericList n t e -> Widget n
- list :: Foldable t => n -> t e -> Int -> GenericList n t e
- listSelectedAttr :: AttrName
- listAttr :: AttrName
- handleListEventVi :: forall (t :: Type -> Type) n e. (Foldable t, Splittable t, Ord n) => (Event -> GenericList n t e -> EventM n (GenericList n t e)) -> Event -> GenericList n t e -> EventM n (GenericList n t e)
- handleListEvent :: forall (t :: Type -> Type) n e. (Foldable t, Splittable t, Ord n) => Event -> GenericList n t e -> EventM n (GenericList n t e)
- listSelectedL :: forall n (t :: Type -> Type) e. Lens' (GenericList n t e) (Maybe Int)
- type List n e = GenericList n Vector e
- data GenericList n (t :: Type -> Type) e
- suspendAndResume :: IO s -> EventM n (Next s)
- halt :: s -> EventM n (Next s)
- continue :: s -> EventM n (Next s)
- viewportScroll :: n -> ViewportScroll n
- showCursorNamed :: Eq n => n -> [CursorLocation n] -> Maybe (CursorLocation n)
- showFirstCursor :: s -> [CursorLocation n] -> Maybe (CursorLocation n)
- neverShowCursor :: s -> [CursorLocation n] -> Maybe (CursorLocation n)
- resetRenderState :: RenderState n -> RenderState n
- getRenderState :: EventM n (RenderState n)
- invalidateCache :: Ord n => EventM n ()
- invalidateCacheEntry :: Ord n => n -> EventM n ()
- getVtyHandle :: EventM n Vty
- findClickedExtents :: (Int, Int) -> EventM n [Extent n]
- lookupExtent :: Eq n => n -> EventM n (Maybe (Extent n))
- clickedExtent :: (Int, Int) -> Extent n -> Bool
- lookupViewport :: Ord n => n -> EventM n (Maybe Viewport)
- customMainWithVty :: Ord n => Vty -> IO Vty -> Maybe (BChan e) -> App s e n -> s -> IO (s, Vty)
- customMain :: Ord n => Vty -> IO Vty -> Maybe (BChan e) -> App s e n -> s -> IO s
- resizeOrQuit :: s -> BrickEvent n e -> EventM n (Next s)
- simpleApp :: Widget n -> App s e n
- simpleMain :: Ord n => Widget n -> IO ()
- defaultMain :: Ord n => App s e n -> s -> IO s
- data App s e n = App {
- appDraw :: s -> [Widget n]
- appChooseCursor :: s -> [CursorLocation n] -> Maybe (CursorLocation n)
- appHandleEvent :: s -> BrickEvent n e -> EventM n (Next s)
- appStartEvent :: s -> EventM n s
- appAttrMap :: s -> AttrMap
- data ViewportScroll n
- vBorder :: Widget n
- hBorder :: Widget n
- border :: Widget n -> Widget n
- borderAttr :: AttrName
- center :: Widget n -> Widget n
- vCenter :: Widget n -> Widget n
- renderEditor :: (Ord n, Show n, Monoid t, TextWidth t, GenericTextZipper t) => ([t] -> Widget n) -> Bool -> Editor t n -> Widget n
- getEditContents :: Monoid t => Editor t n -> [t]
- applyEdit :: (TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
- editor :: GenericTextZipper a => n -> Maybe Int -> a -> Editor a n
- editorText :: n -> Maybe Int -> Text -> Editor Text n
- handleEditorEvent :: (DecodeUtf8 t, Eq t, Monoid t) => Event -> Editor t n -> EventM n (Editor t n)
- data Editor t n
- (<=>) :: Widget n -> Widget n -> Widget n
- (<+>) :: Widget n -> Widget n -> Widget n
- visibleRegion :: Location -> DisplayRegion -> Widget n -> Widget n
- visible :: Widget n -> Widget n
- unsafeLookupViewport :: Ord n => n -> RenderM n (Maybe Viewport)
- viewport :: (Ord n, Show n) => n -> ViewportType -> Widget n -> Widget n
- cached :: Ord n => n -> Widget n -> Widget n
- showCursor :: n -> Location -> Widget n -> Widget n
- cropBottomTo :: Int -> Widget n -> Widget n
- cropBottomBy :: Int -> Widget n -> Widget n
- cropTopTo :: Int -> Widget n -> Widget n
- cropTopBy :: Int -> Widget n -> Widget n
- cropRightTo :: Int -> Widget n -> Widget n
- cropRightBy :: Int -> Widget n -> Widget n
- cropLeftTo :: Int -> Widget n -> Widget n
- cropLeftBy :: Int -> Widget n -> Widget n
- translateBy :: Location -> Widget n -> Widget n
- raw :: Image -> Widget n
- overrideAttr :: AttrName -> AttrName -> Widget n -> Widget n
- forceAttr :: AttrName -> Widget n -> Widget n
- updateAttrMap :: (AttrMap -> AttrMap) -> Widget n -> Widget n
- withDefAttr :: AttrName -> Widget n -> Widget n
- modifyDefAttr :: (Attr -> Attr) -> Widget n -> Widget n
- withAttr :: AttrName -> Widget n -> Widget n
- setAvailableSize :: (Int, Int) -> Widget n -> Widget n
- vLimitPercent :: Int -> Widget n -> Widget n
- vLimit :: Int -> Widget n -> Widget n
- hLimitPercent :: Int -> Widget n -> Widget n
- hLimit :: Int -> Widget n -> Widget n
- hBox :: [Widget n] -> Widget n
- vBox :: [Widget n] -> Widget n
- fill :: Char -> Widget n
- padAll :: Int -> Widget n -> Widget n
- padTopBottom :: Int -> Widget n -> Widget n
- padLeftRight :: Int -> Widget n -> Widget n
- padBottom :: Padding -> Widget n -> Widget n
- padTop :: Padding -> Widget n -> Widget n
- padRight :: Padding -> Widget n -> Widget n
- padLeft :: Padding -> Widget n -> Widget n
- hyperlink :: Text -> Widget n -> Widget n
- txt :: Text -> Widget n
- str :: String -> Widget n
- txtWrapWith :: WrapSettings -> Text -> Widget n
- txtWrap :: Text -> Widget n
- strWrapWith :: WrapSettings -> String -> Widget n
- strWrap :: String -> Widget n
- clickable :: n -> Widget n -> Widget n
- reportExtent :: n -> Widget n -> Widget n
- addResultOffset :: Location -> Result n -> Result n
- emptyWidget :: Widget n
- freezeBorders :: Widget n -> Widget n
- separateBorders :: Widget n -> Widget n
- joinBorders :: Widget n -> Widget n
- withBorderStyle :: BorderStyle -> Widget n -> Widget n
- class TextWidth a where
- class Named a n where
- getName :: a -> n
- cropToContext :: Widget n -> Widget n
- renderFinal :: AttrMap -> [Widget n] -> DisplayRegion -> ([CursorLocation n] -> Maybe (CursorLocation n)) -> RenderState n -> (RenderState n, Picture, Maybe (CursorLocation n), [Extent n])
- lookupAttrName :: AttrName -> RenderM n Attr
- attrL :: Getting r Context Attr
- windowWidthL :: Lens' Context Int
- windowHeightL :: Lens' Context Int
- ctxDynBordersL :: Lens' Context Bool
- ctxBorderStyleL :: Lens' Context BorderStyle
- ctxAttrNameL :: Lens' Context AttrName
- ctxAttrMapL :: Lens' Context AttrMap
- availWidthL :: Lens' Context Int
- availHeightL :: Lens' Context Int
- getContext :: RenderM n Context
- handleEventLensed :: a -> Lens' a b -> (e -> b -> EventM n b) -> e -> EventM n a
- data Padding
- newtype EventM n a = EventM {}
- data Size
- data Widget n = Widget {}
- type RenderM n a = ReaderT Context (State (RenderState n)) a
- clOffset :: CursorLocation n -> Location -> CursorLocation n
- bg :: Color -> Attr
- fg :: Color -> Attr
- on :: Color -> Color -> Attr
- clamp :: Ord a => a -> a -> a -> a
- vpTop :: Lens' Viewport Int
- vpSize :: Lens' Viewport DisplayRegion
- vpLeft :: Lens' Viewport Int
- cursorLocationNameL :: Lens (CursorLocation n1) (CursorLocation n2) (Maybe n1) (Maybe n2)
- cursorLocationL :: Lens' (CursorLocation n) Location
- vrSizeL :: Lens' VisibilityRequest DisplayRegion
- vrPositionL :: Lens' VisibilityRequest Location
- emptyResult :: Result n
- visibilityRequestsL :: Lens' (Result n) [VisibilityRequest]
- imageL :: Lens' (Result n) Image
- extentsL :: Lens' (Result n) [Extent n]
- cursorsL :: Lens' (Result n) [CursorLocation n]
- bordersL :: Lens' (Result n) (BorderMap DynBorder)
- data BrickEvent n e
- data RenderState n
- data Context
- dbStyleL :: Lens' DynBorder BorderStyle
- dbSegmentsL :: Lens' DynBorder (Edges BorderSegment)
- dbAttrL :: Lens' DynBorder Attr
- data Result n = Result {
- image :: Image
- cursors :: [CursorLocation n]
- visibilityRequests :: [VisibilityRequest]
- extents :: [Extent n]
- borders :: BorderMap DynBorder
- bsOfferL :: Lens' BorderSegment Bool
- bsDrawL :: Lens' BorderSegment Bool
- bsAcceptL :: Lens' BorderSegment Bool
- data DynBorder = DynBorder {}
- data VisibilityRequest = VR {}
- data Viewport = VP {}
- data ViewportType
- = Vertical
- | Horizontal
- | Both
- data Extent n = Extent {
- extentName :: n
- extentUpperLeft :: Location
- extentSize :: (Int, Int)
- data Next a
- data Direction
- 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)
- data BorderSegment = BorderSegment {}
- unicodeRounded :: BorderStyle
- unicodeBold :: BorderStyle
- unicode :: BorderStyle
- ascii :: BorderStyle
- borderStyleFromChar :: Char -> BorderStyle
- defaultBorderStyle :: BorderStyle
- data BorderStyle = BorderStyle {
- bsCornerTL :: Char
- bsCornerTR :: Char
- bsCornerBR :: Char
- bsCornerBL :: Char
- bsIntersectFull :: Char
- bsIntersectL :: Char
- bsIntersectR :: Char
- bsIntersectT :: Char
- bsIntersectB :: Char
- bsHorizontal :: Char
- bsVertical :: Char
- eTopL :: Lens' (Edges a) a
- eRightL :: Lens' (Edges a) a
- eLeftL :: Lens' (Edges a) a
- eBottomL :: Lens' (Edges a) a
- locL :: Lens' Location (Int, Int)
- data Edges a = Edges {}
- data Location = Location {}
- suffixLenses :: Name -> DecsQ
- writeBChan :: BChan a -> a -> IO ()
- newBChan :: Int -> IO (BChan a)
- data BChan a
- mapAttrNames :: [(AttrName, AttrName)] -> AttrMap -> AttrMap
- mapAttrName :: AttrName -> AttrName -> AttrMap -> AttrMap
- applyAttrMappings :: [(AttrName, Attr)] -> AttrMap -> AttrMap
- getDefaultAttr :: AttrMap -> Attr
- setDefaultAttr :: Attr -> AttrMap -> AttrMap
- attrMapLookup :: AttrName -> AttrMap -> Attr
- mergeWithDefault :: Attr -> AttrMap -> Attr
- forceAttrMap :: Attr -> AttrMap
- attrMap :: Attr -> [(AttrName, Attr)] -> AttrMap
- attrNameComponents :: AttrName -> [String]
- attrName :: String -> AttrName
- data AttrName
- data AttrMap
- (^.) :: s -> Getting a s a -> a
- (?~) :: ASetter s t a (Maybe b) -> b -> s -> t
- set :: ASetter s t a b -> b -> s -> t
- (.~) :: ASetter s t a b -> b -> s -> t
- over :: ASetter s t a b -> (a -> b) -> s -> t
- (%~) :: ASetter s t a b -> (a -> b) -> s -> t
- _1 :: Field1 s t a b => Lens s t a b
- _2 :: Field2 s t a b => Lens s t a b
- _3 :: Field3 s t a b => Lens s t a b
- type ASetter' s a = ASetter s s a a
- makeLenses :: Name -> DecsQ
- mkVty :: Config -> IO Vty
- standardIOConfig :: IO Config
- defaultConfig :: Config
- data Key
- data Modifier
- data Button
- = BLeft
- | BMiddle
- | BRight
- | BScrollUp
- | BScrollDown
- type ClassifyMap = [(String, Event)]
- defAttr :: Attr
- withStyle :: Attr -> Style -> Attr
- bold :: Style
- brightMagenta :: Color
- brightBlue :: Color
- white :: Color
- cyan :: Color
- magenta :: Color
- blue :: Color
- green :: Color
- black :: Color
Documentation
searchWidgetAux :: (Ord n, Show n) => Bool -> Text -> Editor Text n -> Widget n -> Widget n Source #
listWithHighlights :: (Foldable f, Ord n, Show n) => Text -> (a -> f Text) -> Bool -> List n a -> Widget n Source #
columnsListWithHighlights :: (Foldable f, Ord n, Show n) => Text -> (a -> [f Text]) -> [AttrName] -> [Int] -> Bool -> List n a -> Widget n Source #
Events.
EvKey Key [Modifier] | A keyboard key was pressed with the specified modifiers. |
EvMouseDown Int Int Button [Modifier] | A mouse button was pressed at the specified column and row. Any modifiers available in the event are also provided. |
EvMouseUp Int Int (Maybe Button) | A mouse button was released at the specified column and row. Some terminals report only that a button was released without specifying which one; in that case, Nothing is provided. Otherwise Just the button released is included in the event. |
EvResize Int Int | If read from |
EvPaste ByteString | A paste event occurs when a bracketed paste input sequence is received. For terminals that support bracketed paste mode, these events will be triggered on a paste event. Terminals that do not support bracketed pastes will send the paste contents as ordinary input (which is probably bad, so beware!) Note that the data is provided in raw form and you'll have to decode (e.g. as UTF-8) if that's what your application expects. |
EvLostFocus | The terminal running the application lost input focus. |
EvGainedFocus | The terminal running the application gained input focus. |
Instances
A display attribute defines the Color and Style of all the characters rendered after the attribute is applied.
At most 256 colors, picked from a 240 and 16 color palette, are possible for the background and foreground. The 240 colors and 16 colors are points in different palettes. See Color for more information.
Instances
Eq Attr | |
Read Attr | |
Show Attr | |
Generic Attr | |
Semigroup Attr | |
Monoid Attr | |
GetAttr Attr | |
NFData Attr | |
Defined in Graphics.Vty.Attributes | |
type Rep Attr | |
Defined in Graphics.Vty.Attributes type Rep Attr = D1 ('MetaData "Attr" "Graphics.Vty.Attributes" "vty-5.33-d400eec211b41e58acc410b10d79ca4624828bcbf5f0eb291b0c1dd87f602843" 'False) (C1 ('MetaCons "Attr" 'PrefixI 'True) ((S1 ('MetaSel ('Just "attrStyle") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (MaybeDefault Style)) :*: S1 ('MetaSel ('Just "attrForeColor") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (MaybeDefault Color))) :*: (S1 ('MetaSel ('Just "attrBackColor") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (MaybeDefault Color)) :*: S1 ('MetaSel ('Just "attrURL") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (MaybeDefault Text))))) |
(@?) :: Text -> AttrName -> Markup AttrName #
Build a piece of markup from text with an assigned attribute name.
When the markup is rendered, the attribute name will be looked up in
the rendering context's AttrMap
to determine the attribute to use
for this piece of text.
A type class for types that provide access to an attribute in the rendering monad. You probably won't need to instance this.
Markup with metadata type a
assigned to each character.
listSelectedElement :: forall (t :: Type -> Type) n e. (Splittable t, Foldable t) => GenericList n t e -> Maybe (Int, e) #
listReplace :: (Foldable t, Splittable t) => t e -> Maybe Int -> GenericList n t e -> GenericList n t e #
Replace the contents of a list with a new set of elements and
update the new selected index. If the list is empty, empty selection
is used instead. Otherwise, if the specified selected index (via
Just
) is not in the list bounds, zero is used instead.
Complexity: same as splitAt
for the container type.
:: forall (t :: Type -> Type) n e. (Traversable t, Splittable t, Ord n, Show n) | |
=> (Int -> Bool -> e -> Widget n) | Rendering function, taking index, and True for the selected element |
-> Bool | Whether the list has focus |
-> GenericList n t e | The List to be rendered |
-> Widget n | rendered widget |
Like renderList
, except the render function is also provided with
the index of each element.
Has the same evaluation characteristics as renderList
.
:: forall (t :: Type -> Type) n e. (Traversable t, Splittable t, Ord n, Show n) | |
=> (Bool -> e -> Widget n) | Rendering function, True for the selected element |
-> Bool | Whether the list has focus |
-> GenericList n t e | The List to be rendered |
-> Widget n | rendered widget |
Render a list using the specified item drawing function.
Evaluates the underlying container up to, and a bit beyond, the
selected element. The exact amount depends on available height
for drawing and listItemHeight
. At most, it will evaluate up to
element (i + h + 1)
where i
is the selected index and h
is the
available height.
Note that this function renders the list with the listAttr
as
the default attribute and then uses listSelectedAttr
as the
default attribute for the selected item if the list is not focused
or listSelectedFocusedAttr
otherwise. This is provided as a
convenience so that the item rendering function doesn't have to be
concerned with attributes, but if those attributes are undesirable
for your purposes, forceAttr
can always be used by the item
rendering function to ensure that another attribute is used instead.
:: Foldable t | |
=> n | The list name (must be unique) |
-> t e | The initial list contents |
-> Int | The list item height in rows (all list item widgets must be this high). |
-> GenericList n t e |
Construct a list in terms of container t
with element type e
.
listSelectedAttr :: AttrName #
The attribute used only for the currently-selected list item when
the list does not have focus. Extends listAttr
.
:: forall (t :: Type -> Type) n e. (Foldable t, Splittable t, Ord n) | |
=> (Event -> GenericList n t e -> EventM n (GenericList n t e)) | Fallback event handler to use if none of the vi keys match. |
-> Event | |
-> GenericList n t e | |
-> EventM n (GenericList n t e) |
Enable list movement with the vi keys with a fallback handler if
none match. Use handleListEventVi
handleListEvent
in place of
handleListEvent
to add the vi keys bindings to the standard ones.
Movements handled include:
- Up (k)
- Down (j)
- Page Up (Ctrl-b)
- Page Down (Ctrl-f)
- Half Page Up (Ctrl-u)
- Half Page Down (Ctrl-d)
- Go to first element (g)
- Go to last element (G)
handleListEvent :: forall (t :: Type -> Type) n e. (Foldable t, Splittable t, Ord n) => Event -> GenericList n t e -> EventM n (GenericList n t e) #
Handle events for list cursor movement. Events handled are:
- Up (up arrow key)
- Down (down arrow key)
- Page Up (PgUp)
- Page Down (PgDown)
- Go to first element (Home)
- Go to last element (End)
listSelectedL :: forall n (t :: Type -> Type) e. Lens' (GenericList n t e) (Maybe Int) #
type List n e = GenericList n Vector e #
An alias for GenericList
specialized to use a Vector
as its
container type.
data GenericList n (t :: Type -> Type) e #
List state. Lists have a container t
of element type e
that is
the data stored by the list. Internally, Lists handle the following
events by default:
- Up/down arrow keys: move cursor of selected item
- Page up / page down keys: move cursor of selected item by one page at a time (based on the number of items shown)
- Home/end keys: move cursor of selected item to beginning or end of list
The List
type synonym fixes t
to Vector
for compatibility
with previous versions of this library.
For a container type to be usable with GenericList
, it must have
instances of Traversable
and Splittable
. The following functions
impose further constraints:
Instances
suspendAndResume :: IO s -> EventM n (Next s) #
Suspend the event loop, save the terminal state, and run the specified action. When it returns an application state value, restore the terminal state, empty the rendering cache, redraw the application from the new state, and resume the event loop.
Note that any changes made to the terminal's input state are ignored when Brick resumes execution and are not preserved in the final terminal input state after the Brick application returns the terminal to the user.
halt :: s -> EventM n (Next s) #
Halt the event loop and return the specified application state as the final state value.
continue :: s -> EventM n (Next s) #
Continue running the event loop with the specified application state.
viewportScroll :: n -> ViewportScroll n #
Build a viewport scroller for the viewport with the specified name.
showCursorNamed :: Eq n => n -> [CursorLocation n] -> Maybe (CursorLocation n) #
Show the cursor with the specified resource name, if such a cursor location has been reported.
showFirstCursor :: s -> [CursorLocation n] -> Maybe (CursorLocation n) #
Always show the first cursor, if any, returned by the rendering
process. This is a convenience function useful as an
appChooseCursor
value when a simple program has zero or more
widgets that advertise a cursor position.
neverShowCursor :: s -> [CursorLocation n] -> Maybe (CursorLocation n) #
Ignore all requested cursor positions returned by the rendering
process. This is a convenience function useful as an
appChooseCursor
value when a simple application has no need to
position the cursor.
resetRenderState :: RenderState n -> RenderState n #
getRenderState :: EventM n (RenderState n) #
invalidateCache :: Ord n => EventM n () #
Invalidate the entire rendering cache.
invalidateCacheEntry :: Ord n => n -> EventM n () #
Invalidate the rendering cache entry with the specified resource name.
getVtyHandle :: EventM n Vty #
Get the Vty handle currently in use.
findClickedExtents :: (Int, Int) -> EventM n [Extent n] #
Given a mouse click location, return the extents intersected by the click. The returned extents are sorted such that the first extent in the list is the most specific extent and the last extent is the most generic (top-level). So if two extents A and B both intersected the mouse click but A contains B, then they would be returned [B, A].
lookupExtent :: Eq n => n -> EventM n (Maybe (Extent n)) #
Given a resource name, get the most recent rendering extent for the name (if any).
clickedExtent :: (Int, Int) -> Extent n -> Bool #
Did the specified mouse coordinates (column, row) intersect the specified extent?
lookupViewport :: Ord n => n -> EventM n (Maybe Viewport) #
Given a viewport name, get the viewport's size and offset
information from the most recent rendering. Returns Nothing
if
no such state could be found, either because the name was invalid
or because no rendering has occurred (e.g. in an appStartEvent
handler).
:: Ord n | |
=> Vty | The initial Vty handle to use. |
-> IO Vty | An IO action to build a Vty handle. This is used to build a Vty handle whenever the event loop needs to reinitialize the terminal, e.g. on resume after suspension. |
-> Maybe (BChan e) | An event channel for sending custom events to the event
loop (you write to this channel, the event loop reads from
it). Provide |
-> App s e n | The application. |
-> s | The initial application state. |
-> IO (s, Vty) |
Like customMain
, except the last Vty
handle used by the
application is returned without being shut down with shutdown
. This
allows the caller to re-use the Vty
handle for something else, such
as another Brick application.
:: Ord n | |
=> Vty | The initial Vty handle to use. |
-> IO Vty | An IO action to build a Vty handle. This is used to build a Vty handle whenever the event loop needs to reinitialize the terminal, e.g. on resume after suspension. |
-> Maybe (BChan e) | An event channel for sending custom events to the event
loop (you write to this channel, the event loop reads from
it). Provide |
-> App s e n | The application. |
-> s | The initial application state. |
-> IO s |
The custom event loop entry point to use when the simpler ones don't permit enough control. Returns the final application state after the application halts.
Note that this function guarantees that the terminal input state prior to the first Vty initialization is the terminal input state that is restored on shutdown (regardless of exceptions).
resizeOrQuit :: s -> BrickEvent n e -> EventM n (Next s) #
An event-handling function which continues execution of the event
loop only when resize events occur; all other types of events trigger
a halt. This is a convenience function useful as an appHandleEvent
value for simple applications using the Event
type that do not need
to get more sophisticated user input.
simpleApp :: Widget n -> App s e n #
A simple application with reasonable defaults to be overridden as desired:
- Draws only the specified widget
- Quits on any event other than resizes
- Has no start event handler
- Provides no attribute map
- Never shows any cursors
A simple main entry point which takes a widget and renders it. This event loop terminates when the user presses any key, but terminal resize events cause redraws.
The default main entry point which takes an application and an
initial state and returns the final state returned by a halt
operation.
The library application abstraction. Your application's operations
are provided in an App
and then the App
is provided to one of the
various main functions in this module. An application App s e n
is in terms of an application state type s
, an application event
type e
, and a resource name type n
. In the simplest case e
is
unused (left polymorphic or set to ()
), but you may define your own
event type and use customMain
to provide custom events. The state
type s
is the type of application state to be provided by you and
iteratively modified by event handlers. The resource name type n
is the type of names you can assign to rendering resources such as
viewports and cursor locations. Your application must define this
type.
App | |
|
data ViewportScroll n #
A viewport scrolling handle for managing the scroll state of viewports.
borderAttr :: AttrName #
The top-level border attribute name.
center :: Widget n -> Widget n #
Center a widget both vertically and horizontally. Consumes all available vertical and horizontal space.
:: (Ord n, Show n, Monoid t, TextWidth t, GenericTextZipper t) | |
=> ([t] -> Widget n) | The content drawing function |
-> Bool | Whether the editor has focus. It will report a cursor position if and only if it has focus. |
-> Editor t n | The editor. |
-> Widget n |
Turn an editor state value into a widget. This uses the editor's name for its scrollable viewport handle and the name is also used to report mouse events.
getEditContents :: Monoid t => Editor t n -> [t] #
Get the contents of the editor.
:: (TextZipper t -> TextZipper t) | The |
-> Editor t n | |
-> Editor t n |
Apply an editing operation to the editor's contents. Bear in mind that you should only apply zipper operations that operate on the current line; the editor will only ever render the first line of text.
:: GenericTextZipper a | |
=> n | The editor's name (must be unique) |
-> Maybe Int | The limit on the number of lines in the editor ( |
-> a | The initial content |
-> Editor a n |
Construct an editor over String
values
:: n | The editor's name (must be unique) |
-> Maybe Int | The limit on the number of lines in the editor ( |
-> Text | The initial content |
-> Editor Text n |
Construct an editor over Text
values
handleEditorEvent :: (DecodeUtf8 t, Eq t, Monoid t) => Event -> Editor t n -> EventM n (Editor t n) #
Editor state. Editors support the following events by default:
- Ctrl-a: go to beginning of line
- Ctrl-e: go to end of line
- Ctrl-d, Del: delete character at cursor position
- Backspace: delete character prior to cursor position
- Ctrl-k: delete all from cursor to end of line
- Ctrl-u: delete all from cursor to beginning of line
- Arrow keys: move cursor
- Enter: break the current line at the cursor position
- Paste: Bracketed Pastes from the terminal will be pasted, provided the incoming data is UTF-8-encoded.
Vertical box layout: put the specified widgets one above the other
in the specified order. Defers growth policies to the growth policies
of both widgets. This operator is a binary version of vBox
.
Horizontal box layout: put the specified widgets next to each other
in the specified order. Defers growth policies to the growth policies
of both widgets. This operator is a binary version of hBox
.
visibleRegion :: Location -> DisplayRegion -> Widget n -> Widget n #
Similar to visible
, request that a region (with the specified
Location
as its origin and DisplayRegion
as its size) be made
visible when it is rendered inside a viewport. The Location
is
relative to the specified widget's upper-left corner of (0, 0).
This does nothing if not rendered in a viewport.
visible :: Widget n -> Widget n #
Request that the specified widget be made visible when it is
rendered inside a viewport. This permits widgets (whose sizes and
positions cannot be known due to being embedded in arbitrary layouts)
to make a request for a parent viewport to locate them and scroll
enough to put them in view. This, together with viewport
, is what
makes the text editor and list widgets possible without making them
deal with the details of scrolling state management.
This does nothing if not rendered in a viewport.
unsafeLookupViewport :: Ord n => n -> RenderM n (Maybe Viewport) #
Given a name, obtain the viewport for that name by consulting the viewport map in the rendering monad. NOTE! Some care must be taken when calling this function, since it only returns useful values after the viewport in question has been rendered. If you call this function during rendering before a viewport has been rendered, you may get nothing or you may get a stale version of the viewport. This is because viewports are updated during rendering and the one you are interested in may not have been rendered yet. So if you want to use this, be sure you know what you are doing.
:: (Ord n, Show n) | |
=> n | The name of the viewport (must be unique and stable for reliable behavior) |
-> ViewportType | The type of viewport (indicates the permitted scrolling direction) |
-> Widget n | The widget to be rendered in the scrollable viewport |
-> Widget n |
Render the specified widget in a named viewport with the
specified type. This permits widgets to be scrolled without being
scrolling-aware. To make the most use of viewports, the specified
widget should use the visible
combinator to make a "visibility
request". This viewport combinator will then translate the resulting
rendering to make the requested region visible. In addition, the
EventM
monad provides primitives to scroll viewports
created by this function if visible
is not what you want.
If a viewport receives more than one visibility request, then the
visibility requests are merged with the inner visibility request
taking preference. If a viewport receives more than one scrolling
request from EventM
, all are honored in the order in
which they are received.
Some caution should be advised when using this function. The viewport renders its contents anew each time the viewport is drawn; in many cases this is prohibitively expensive, and viewports should not be used to display large contents for scrolling. This function is best used when the contents are not too large OR when the contents are large and render-cacheable.
cached :: Ord n => n -> Widget n -> Widget n #
If the specified resource name has an entry in the rendering cache, use the rendered version from the cache. If not, render the specified widget and update the cache with the result.
To ensure that mouse events are emitted correctly for cached widgets, in addition to the rendered widget, we also cache (the names of) any clickable extents that were rendered and restore that when utilizing the cache.
See also invalidateCacheEntry
.
showCursor :: n -> Location -> Widget n -> Widget n #
When rendering the specified widget, also register a cursor positioning request using the specified name and location.
cropBottomTo :: Int -> Widget n -> Widget n #
Crop the specified widget to the specified size from the bottom. Defers to the cropped widget for growth policy.
cropBottomBy :: Int -> Widget n -> Widget n #
Crop the specified widget on the bottom by the specified number of rows. Defers to the cropped widget for growth policy.
cropTopTo :: Int -> Widget n -> Widget n #
Crop the specified widget to the specified size from the top. Defers to the cropped widget for growth policy.
cropTopBy :: Int -> Widget n -> Widget n #
Crop the specified widget on the top by the specified number of rows. Defers to the cropped widget for growth policy.
cropRightTo :: Int -> Widget n -> Widget n #
Crop the specified widget to the specified size from the right. Defers to the cropped widget for growth policy.
cropRightBy :: Int -> Widget n -> Widget n #
Crop the specified widget on the right by the specified number of columns. Defers to the cropped widget for growth policy.
cropLeftTo :: Int -> Widget n -> Widget n #
Crop the specified widget to the specified size from the left. Defers to the cropped widget for growth policy.
cropLeftBy :: Int -> Widget n -> Widget n #
Crop the specified widget on the left by the specified number of columns. Defers to the cropped widget for growth policy.
translateBy :: Location -> Widget n -> Widget n #
Translate the specified widget by the specified offset amount. Defers to the translated widget for growth policy.
overrideAttr :: AttrName -> AttrName -> Widget n -> Widget n #
Override the lookup of targetName
to return the attribute value
associated with fromName
when rendering the specified widget.
See also mapAttrName
.
forceAttr :: AttrName -> Widget n -> Widget n #
When rendering the specified widget, force all attribute lookups
in the attribute map to use the value currently assigned to the
specified attribute name. This means that the attribute lookups will
behave as if they all used the name specified here. That further
means that the resolved attribute will still inherit from its parent
entry in the attribute map as would normally be the case. If you
want to have more control over the resulting attribute, consider
modifyDefAttr
.
updateAttrMap :: (AttrMap -> AttrMap) -> Widget n -> Widget n #
When rendering the specified widget, update the attribute map with the specified transformation.
withDefAttr :: AttrName -> Widget n -> Widget n #
Update the attribute map while rendering the specified widget: set its new default attribute to the one that we get by looking up the specified attribute name in the map.
modifyDefAttr :: (Attr -> Attr) -> Widget n -> Widget n #
Update the attribute map while rendering the specified widget: set its new default attribute to the one that we get by looking up the specified attribute name in the map and then modifying it with the specified function.
withAttr :: AttrName -> Widget n -> Widget n #
When drawing the specified widget, set the current attribute used
for drawing to the one with the specified name. Note that the widget
may use further calls to withAttr
to override this; if you really
want to prevent that, use forceAttr
. Attributes used this way still
get merged hierarchically and still fall back to the attribute map's
default attribute. If you want to change the default attribute, use
withDefAttr
.
setAvailableSize :: (Int, Int) -> Widget n -> Widget n #
Set the rendering context height and width for this widget. This is useful for relaxing the rendering size constraints on e.g. layer widgets where cropping to the screen size is undesirable.
vLimitPercent :: Int -> Widget n -> Widget n #
Limit the space available to the specified widget to the specified percentage of available height, as a value between 0 and 100 inclusive. Values outside the valid range will be clamped to the range endpoints. This is important for constraining the vertical growth of otherwise-greedy widgets. This is non-greedy vertically and defers to the limited widget horizontally.
vLimit :: Int -> Widget n -> Widget n #
Limit the space available to the specified widget to the specified number of rows. This is important for constraining the vertical growth of otherwise-greedy widgets. This is non-greedy vertically and defers to the limited widget horizontally.
hLimitPercent :: Int -> Widget n -> Widget n #
Limit the space available to the specified widget to the specified percentage of available width, as a value between 0 and 100 inclusive. Values outside the valid range will be clamped to the range endpoints. This is important for constraining the horizontal growth of otherwise-greedy widgets. This is non-greedy horizontally and defers to the limited widget vertically.
hLimit :: Int -> Widget n -> Widget n #
Limit the space available to the specified widget to the specified number of columns. This is important for constraining the horizontal growth of otherwise-greedy widgets. This is non-greedy horizontally and defers to the limited widget vertically.
hBox :: [Widget n] -> Widget n #
Horizontal box layout: put the specified widgets next to each other in the specified order (leftmost first). Defers growth policies to the growth policies of the contained widgets (if any are greedy, so is the box).
vBox :: [Widget n] -> Widget n #
Vertical box layout: put the specified widgets one above the other in the specified order (uppermost first). Defers growth policies to the growth policies of the contained widgets (if any are greedy, so is the box).
Fill all available space with the specified character. Grows both horizontally and vertically.
padAll :: Int -> Widget n -> Widget n #
Pad a widget on all sides. Defers to the padded widget for growth policy.
padTopBottom :: Int -> Widget n -> Widget n #
Pad a widget on the top and bottom. Defers to the padded widget for growth policy.
padLeftRight :: Int -> Widget n -> Widget n #
Pad a widget on the left and right. Defers to the padded widget for growth policy.
padBottom :: Padding -> Widget n -> Widget n #
Pad the specified widget on the bottom. If max padding is used, this grows greedily vertically; otherwise it defers to the padded widget.
padTop :: Padding -> Widget n -> Widget n #
Pad the specified widget on the top. If max padding is used, this grows greedily vertically; otherwise it defers to the padded widget.
padRight :: Padding -> Widget n -> Widget n #
Pad the specified widget on the right. If max padding is used, this grows greedily horizontally; otherwise it defers to the padded widget.
padLeft :: Padding -> Widget n -> Widget n #
Pad the specified widget on the left. If max padding is used, this grows greedily horizontally; otherwise it defers to the padded widget.
hyperlink :: Text -> Widget n -> Widget n #
Hyperlink the given widget to the specified URL. Not all terminal emulators support this. In those that don't, this should have no discernible effect.
Build a widget from a Text
value. Behaves the same as str
when the input contains multiple lines.
The input string must not contain tab characters. If it does, interface corruption will result since the terminal will likely render it as taking up more than a single column. The caller should replace tabs with the appropriate number of spaces as desired. The input text should not contain escape sequences or carriage returns.
Build a widget from a String
. Breaks newlines up and space-pads
short lines out to the length of the longest line.
The input string must not contain tab characters. If it does, interface corruption will result since the terminal will likely render it as taking up more than a single column. The caller should replace tabs with the appropriate number of spaces as desired. The input string should not contain escape sequences or carriage returns.
txtWrapWith :: WrapSettings -> Text -> Widget n #
Make a widget from text, but wrap the words in the input's lines at the available width using the specified wrapping settings. The input text should not contain escape sequences or carriage returns.
Unlike txt
, this is greedy horizontally.
Make a widget from text, but wrap the words in the input's lines at the available width using the default wrapping settings. The input text should not contain escape sequences or carriage returns.
Unlike txt
, this is greedy horizontally.
strWrapWith :: WrapSettings -> String -> Widget n #
Make a widget from a string, but wrap the words in the input's lines at the available width using the specified wrapping settings. The input string should not contain escape sequences or carriage returns.
Unlike str
, this is greedy horizontally.
strWrap :: String -> Widget n #
Make a widget from a string, but wrap the words in the input's lines at the available width using the default wrapping settings. The input string should not contain escape sequences or carriage returns.
Unlike str
, this is greedy horizontally.
reportExtent :: n -> Widget n -> Widget n #
Render the specified widget and record its rendering extent using
the specified name (see also lookupExtent
).
addResultOffset :: Location -> Result n -> Result n #
Add an offset to all cursor locations, visbility requests, and extents in the specified rendering result. This function is critical for maintaining correctness in the rendering results as they are processed successively by box layouts and other wrapping combinators, since calls to this function result in converting from widget-local coordinates to (ultimately) terminal-global ones so they can be used by other combinators. You should call this any time you render something and then translate it or otherwise offset it from its original origin.
emptyWidget :: Widget n #
The empty widget.
freezeBorders :: Widget n -> Widget n #
After the specified widget has been rendered, freeze its borders. A
frozen border will not be affected by neighbors, nor will it affect
neighbors. Compared to separateBorders
, freezeBorders
will not
affect whether borders connect internally to a widget (whereas
separateBorders
prevents them from connecting).
Frozen borders cannot be thawed.
separateBorders :: Widget n -> Widget n #
When rendering the specified widget, use static borders. This may be marginally faster, but will introduce a small gap between neighboring orthogonal borders.
This is the default for backwards compatibility.
joinBorders :: Widget n -> Widget n #
When rendering the specified widget, create borders that respond dynamically to their neighbors to form seamless connections.
withBorderStyle :: BorderStyle -> Widget n -> Widget n #
When rendering the specified widget, use the specified border style for any border rendering.
The class of types that store interface element names.
Instances
Named (Editor t n) n | |
Defined in Brick.Widgets.Edit | |
Named (GenericList n t e) n | |
Defined in Brick.Widgets.List getName :: GenericList n t e -> n # |
cropToContext :: Widget n -> Widget n #
After rendering the specified widget, crop its result image to the dimensions in the rendering context.
renderFinal :: AttrMap -> [Widget n] -> DisplayRegion -> ([CursorLocation n] -> Maybe (CursorLocation n)) -> RenderState n -> (RenderState n, Picture, Maybe (CursorLocation n), [Extent n]) #
lookupAttrName :: AttrName -> RenderM n Attr #
Given an attribute name, obtain the attribute for the attribute name by consulting the context's attribute map.
windowWidthL :: Lens' Context Int #
availWidthL :: Lens' Context Int #
availHeightL :: Lens' Context Int #
getContext :: RenderM n Context #
Get the current rendering context.
:: 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.
The type of padding.
The monad in which event handlers run. Although it may be tempting
to dig into the reader value yourself, just use
lookupViewport
.
Instances
Monad (EventM n) | |
Functor (EventM n) | |
MonadFail (EventM n) | |
Defined in Brick.Types | |
Applicative (EventM n) | |
MonadIO (EventM n) | |
Defined in Brick.Types | |
MonadThrow (EventM n) | |
Defined in Brick.Types | |
MonadCatch (EventM n) | |
MonadMask (EventM n) | |
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
.
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. |
The type of widgets.
type RenderM n a = ReaderT Context (State (RenderState n)) a #
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.
clOffset :: CursorLocation n -> Location -> CursorLocation n #
Add a Location
offset to the specified CursorLocation
.
Create an attribute from the specified background color (the background color is the "default").
Create an attribute from the specified foreground color (the background color is the "default").
Build an attribute from a foreground color and a background color. Intended to be used infix.
:: Ord a | |
=> a | The minimum value |
-> a | The maximum value |
-> a | The value to clamp |
-> a |
Given a minimum value and a maximum value, clamp a value to that range (values less than the minimum map to the minimum and values greater than the maximum map to the maximum).
>>>
clamp 1 10 11
10>>>
clamp 1 10 2
2>>>
clamp 5 10 1
5
cursorLocationNameL :: Lens (CursorLocation n1) (CursorLocation n2) (Maybe n1) (Maybe n2) #
cursorLocationL :: Lens' (CursorLocation n) Location #
emptyResult :: Result n #
visibilityRequestsL :: Lens' (Result n) [VisibilityRequest] #
cursorsL :: Lens' (Result n) [CursorLocation n] #
data BrickEvent n e #
The type of events.
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 |
MouseUp n (Maybe Button) Location | A mouse-up event on the specified region was
received. The |
Instances
(Eq e, Eq n) => Eq (BrickEvent n e) | |
Defined in Brick.Types.Internal (==) :: BrickEvent n e -> BrickEvent n e -> Bool # (/=) :: BrickEvent n e -> BrickEvent n e -> Bool # | |
(Ord e, Ord n) => Ord (BrickEvent n e) | |
Defined in Brick.Types.Internal compare :: BrickEvent n e -> BrickEvent n e -> Ordering # (<) :: BrickEvent n e -> BrickEvent n e -> Bool # (<=) :: BrickEvent n e -> BrickEvent n e -> Bool # (>) :: BrickEvent n e -> BrickEvent n e -> Bool # (>=) :: BrickEvent n e -> BrickEvent n e -> Bool # max :: BrickEvent n e -> BrickEvent n e -> BrickEvent n e # min :: BrickEvent n e -> BrickEvent n e -> BrickEvent n e # | |
(Show e, Show n) => Show (BrickEvent n e) | |
Defined in Brick.Types.Internal showsPrec :: Int -> BrickEvent n e -> ShowS # show :: BrickEvent n e -> String # showList :: [BrickEvent n e] -> ShowS # |
data RenderState n #
Instances
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.
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.
Result | |
|
Instances
Read n => Read (Result n) | |
Show n => Show (Result n) | |
Generic (Result n) | |
NFData n => NFData (Result n) | |
Defined in Brick.Types.Internal | |
type Rep (Result n) | |
Defined in Brick.Types.Internal type Rep (Result n) = D1 ('MetaData "Result" "Brick.Types.Internal" "brick-0.62-1e79edf9d5b0299388734a25939a48645b839d61d7654ecff0a3eb424ccc31a7" 'False) (C1 ('MetaCons "Result" 'PrefixI 'True) ((S1 ('MetaSel ('Just "image") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Image) :*: S1 ('MetaSel ('Just "cursors") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [CursorLocation n])) :*: (S1 ('MetaSel ('Just "visibilityRequests") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [VisibilityRequest]) :*: (S1 ('MetaSel ('Just "extents") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Extent n]) :*: S1 ('MetaSel ('Just "borders") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (BorderMap DynBorder)))))) |
Information about how to redraw a dynamic border character when it abuts another dynamic border character.
DynBorder | |
|
Instances
Eq DynBorder | |
Read DynBorder | |
Show DynBorder | |
Generic DynBorder | |
NFData DynBorder | |
Defined in Brick.Types.Internal | |
type Rep DynBorder | |
Defined in Brick.Types.Internal type Rep DynBorder = D1 ('MetaData "DynBorder" "Brick.Types.Internal" "brick-0.62-1e79edf9d5b0299388734a25939a48645b839d61d7654ecff0a3eb424ccc31a7" '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))))) |
data VisibilityRequest #
Instances
Describes the state of a viewport as it appears as its most recent rendering.
Instances
Read Viewport | |
Show Viewport | |
Generic Viewport | |
NFData Viewport | |
Defined in Brick.Types.Internal | |
type Rep Viewport | |
Defined in Brick.Types.Internal type Rep Viewport = D1 ('MetaData "Viewport" "Brick.Types.Internal" "brick-0.62-1e79edf9d5b0299388734a25939a48645b839d61d7654ecff0a3eb424ccc31a7" '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)))) |
data ViewportType #
The type of viewports that indicates the direction(s) in which a viewport is scrollable.
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 | |
Defined in Brick.Types.Internal (==) :: ViewportType -> ViewportType -> Bool # (/=) :: ViewportType -> ViewportType -> Bool # | |
Show ViewportType | |
Defined in Brick.Types.Internal showsPrec :: Int -> ViewportType -> ShowS # show :: ViewportType -> String # showList :: [ViewportType] -> ShowS # |
An extent of a named area: its size, location, and origin.
Extent | |
|
Instances
Read n => Read (Extent n) | |
Show n => Show (Extent n) | |
Generic (Extent n) | |
NFData n => NFData (Extent n) | |
Defined in Brick.Types.Internal | |
type Rep (Extent n) | |
Defined in Brick.Types.Internal type Rep (Extent n) = D1 ('MetaData "Extent" "Brick.Types.Internal" "brick-0.62-1e79edf9d5b0299388734a25939a48645b839d61d7654ecff0a3eb424ccc31a7" 'False) (C1 ('MetaCons "Extent" 'PrefixI 'True) (S1 ('MetaSel ('Just "extentName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 n) :*: (S1 ('MetaSel ('Just "extentUpperLeft") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Location) :*: S1 ('MetaSel ('Just "extentSize") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Int, Int))))) |
The type of actions to take upon completion of an event handler.
Scrolling direction.
class TerminalLocation a where #
The class of types that behave like terminal locations.
locationColumnL :: Lens' a Int #
Get the column out of the value
locationColumn :: a -> Int #
locationRowL :: Lens' a Int #
Get the row out of the value
locationRow :: a -> Int #
Instances
TerminalLocation Location | |
Defined in Brick.Types.Internal locationColumnL :: Lens' Location Int # locationColumn :: Location -> Int # locationRowL :: Lens' Location Int # locationRow :: Location -> Int # |
data CursorLocation n #
A cursor location. These are returned by the rendering process.
CursorLocation | |
|
Instances
data BorderSegment #
A border character has four segments, one extending in each direction (horizontally and vertically) from the center of the character.
Instances
unicodeRounded :: BorderStyle #
A unicode border style with rounded corners.
A unicode border style in a bold typeface.
unicode :: BorderStyle #
A unicode border style with real corner and intersection characters.
ascii :: BorderStyle #
An ASCII border style which will work in any terminal.
borderStyleFromChar :: Char -> BorderStyle #
Make a border style using the specified character everywhere.
data BorderStyle #
A border style for use in any widget that needs to render borders in a consistent style.
BorderStyle | |
|
Instances
Instances
Monad Edges | |
Functor Edges | |
Applicative Edges | |
Eq a => Eq (Edges a) | |
Ord a => Ord (Edges a) | |
Read a => Read (Edges a) | |
Show a => Show (Edges a) | |
Generic (Edges a) | |
NFData a => NFData (Edges a) | |
Defined in Brick.Types.Common | |
type Rep (Edges a) | |
Defined in Brick.Types.Common type Rep (Edges a) = D1 ('MetaData "Edges" "Brick.Types.Common" "brick-0.62-1e79edf9d5b0299388734a25939a48645b839d61d7654ecff0a3eb424ccc31a7" '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)))) |
A terminal screen location.
Instances
Eq Location | |
Ord Location | |
Defined in Brick.Types.Common | |
Read Location | |
Show Location | |
Generic Location | |
Semigroup Location | |
Monoid Location | |
TerminalLocation Location | |
Defined in Brick.Types.Internal locationColumnL :: Lens' Location Int # locationColumn :: Location -> Int # locationRowL :: Lens' Location Int # locationRow :: Location -> Int # | |
NFData Location | |
Defined in Brick.Types.Common | |
Field1 Location Location Int Int | |
Field2 Location Location Int Int | |
type Rep Location | |
Defined in Brick.Types.Common |
suffixLenses :: Name -> DecsQ #
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.
writeBChan :: BChan a -> a -> IO () #
Writes a value to a BChan
; blocks if the channel is full.
Builds and returns a new instance of BChan
.
mapAttrNames :: [(AttrName, AttrName)] -> AttrMap -> AttrMap #
Map several attributes to return the value associated with an
alternate name. Applies mapAttrName
across a list of mappings.
mapAttrName :: AttrName -> AttrName -> AttrMap -> AttrMap #
Update an attribute map such that a lookup of ontoName
returns
the attribute value specified by fromName
. This is useful for
composite widgets with specific attribute names mapping those names
to the sub-widget's expected name when calling that sub-widget's
rendering function. See the ProgressBarDemo for an example usage,
and overrideAttr
for an alternate syntax.
applyAttrMappings :: [(AttrName, Attr)] -> AttrMap -> AttrMap #
Insert a set of attribute mappings to an attribute map.
getDefaultAttr :: AttrMap -> Attr #
Get the default attribute value in an attribute map.
setDefaultAttr :: Attr -> AttrMap -> AttrMap #
Set the default attribute value in an attribute map.
attrMapLookup :: AttrName -> AttrMap -> Attr #
Look up the specified attribute name in the map. Map lookups
proceed as follows. If the attribute map is forcing all lookups to a
specific attribute, that attribute is returned along with its style
settings. If the attribute name is empty, the map's default attribute
is returned. If the attribute name is non-empty, every subsequence of
names from the specified name are used to perform a lookup and the
results are combined as in mergeWithDefault
, with more specific
results taking precedence over less specific ones. As attributes are
merged, styles are also merged. If a more specific attribute name
introduces a style (underline, say) and a less specific attribute
name introduces an additional style (bold, say) then the final result
will include both styles.
For example:
attrMapLookup ("foo" <> "bar") (attrMap a []) == a
attrMapLookup ("foo" <> "bar") (attrMap (bg blue) [("foo" <> "bar", fg red)]) == red `on` blue
attrMapLookup ("foo" <> "bar") (attrMap (bg blue) [("foo" <> "bar", red on
cyan)]) == red `on` cyan
attrMapLookup ("foo" <> "bar") (attrMap (bg blue) [("foo" <> "bar", fg red), ("foo", bg cyan)]) == red `on` cyan
attrMapLookup ("foo" <> "bar") (attrMap (bg blue) [("foo", fg red)]) == red `on` blue
mergeWithDefault :: Attr -> AttrMap -> Attr #
Given an attribute and a map, merge the attribute with the map's default attribute. If the map is forcing all lookups to a specific attribute, the forced attribute is returned without merging it with the one specified here. Otherwise the attribute given here is merged with the attribute map's default attribute in that any aspect of the specified attribute that is not provided falls back to the map default. For example,
mergeWithDefault (fg blue) $ attrMap (bg red) []
returns
blue `on` red
forceAttrMap :: Attr -> AttrMap #
Create an attribute map in which all lookups map to the same attribute.
:: Attr | The map's default attribute to be returned when a name lookup fails, and the attribute that will be merged with successful lookups. |
-> [(AttrName, Attr)] | The map's initial contents. |
-> AttrMap |
Create an attribute map.
attrNameComponents :: AttrName -> [String] #
Get the components of an attribute name.
An attribute name. Attribute names are hierarchical; use mappend
(<>
) to assemble them. Hierarchy in an attribute name is used to
represent increasing levels of specificity in referring to the
attribute you want to use for a visual element, with names to the
left being general and names to the right being more specific. For
example:
"window" <> "border" "window" <> "title" "header" <> "clock" <> "seconds"
Instances
Eq AttrName | |
Ord AttrName | |
Defined in Brick.AttrMap | |
Read AttrName | |
Show AttrName | |
IsString AttrName | |
Defined in Brick.AttrMap fromString :: String -> AttrName # | |
Generic AttrName | |
Semigroup AttrName | |
Monoid AttrName | |
GetAttr AttrName | |
NFData AttrName | |
Defined in Brick.AttrMap | |
type Rep AttrName | |
Defined in Brick.AttrMap type Rep AttrName = D1 ('MetaData "AttrName" "Brick.AttrMap" "brick-0.62-1e79edf9d5b0299388734a25939a48645b839d61d7654ecff0a3eb424ccc31a7" 'False) (C1 ('MetaCons "AttrName" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [String]))) |
Instances
Show AttrMap | |
Generic AttrMap | |
NFData AttrMap | |
Defined in Brick.AttrMap | |
type Rep AttrMap | |
Defined in Brick.AttrMap type Rep AttrMap = D1 ('MetaData "AttrMap" "Brick.AttrMap" "brick-0.62-1e79edf9d5b0299388734a25939a48645b839d61d7654ecff0a3eb424ccc31a7" 'False) (C1 ('MetaCons "AttrMap" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Attr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map AttrName Attr))) :+: C1 ('MetaCons "ForceAttr" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Attr))) |
(^.) :: s -> Getting a s a -> a infixl 8 #
(^.
) applies a getter to a value; in other words, it gets a value out of a structure using a getter (which can be a lens, traversal, fold, etc.).
Getting 1st field of a tuple:
(^.
_1
) :: (a, b) -> a (^.
_1
) =fst
When (^.
) is used with a traversal, it combines all results using the Monoid
instance for the resulting type. For instance, for lists it would be simple concatenation:
>>>
("str","ing") ^. each
"string"
The reason for this is that traversals use Applicative
, and the Applicative
instance for Const
uses monoid concatenation to combine “effects” of Const
.
A non-operator version of (^.
) is called view
, and it's a bit more general than (^.
) (it works in MonadReader
). If you need the general version, you can get it from microlens-mtl; otherwise there's view
available in Lens.Micro.Extras.
over :: ASetter s t a b -> (a -> b) -> s -> t #
Getting fmap
in a roundabout way:
over
mapped
::Functor
f => (a -> b) -> f a -> f bover
mapped
=fmap
Applying a function to both components of a pair:
over
both
:: (a -> b) -> (a, a) -> (b, b)over
both
= \f t -> (f (fst t), f (snd t))
Using
as a replacement for over
_2
second
:
>>>
over _2 show (10,20)
(10,"20")
(%~) :: ASetter s t a b -> (a -> b) -> s -> t infixr 4 #
(%~
) applies a function to the target; an alternative explanation is that it is an inverse of sets
, which turns a setter into an ordinary function.
is the same thing as mapped
%~
reverse
.fmap
reverse
See over
if you want a non-operator synonym.
Negating the 1st element of a pair:
>>>
(1,2) & _1 %~ negate
(-1,2)
Turning all Left
s in a list to upper case:
>>>
(mapped._Left.mapped %~ toUpper) [Left "foo", Right "bar"]
[Left "FOO",Right "bar"]
_1 :: Field1 s t a b => Lens s t a b #
Gives access to the 1st field of a tuple (up to 5-tuples).
Getting the 1st component:
>>>
(1,2,3,4,5) ^. _1
1
Setting the 1st component:
>>>
(1,2,3) & _1 .~ 10
(10,2,3)
Note that this lens is lazy, and can set fields even of undefined
:
>>>
set _1 10 undefined :: (Int, Int)
(10,*** Exception: Prelude.undefined
This is done to avoid violating a lens law stating that you can get back what you put:
>>>
view _1 . set _1 10 $ (undefined :: (Int, Int))
10
The implementation (for 2-tuples) is:
_1
f t = (,)<$>
f (fst
t)<*>
pure
(snd
t)
or, alternatively,
_1
f ~(a,b) = (\a' -> (a',b))<$>
f a
(where ~
means a lazy pattern).
makeLenses :: Name -> DecsQ #
Generate lenses for a data type or a newtype.
To use it, you have to enable Template Haskell first:
{-# LANGUAGE TemplateHaskell #-}
Then, after declaring the datatype (let's say Foo
), add makeLenses ''Foo
on a separate line (if you do it before the type is declared, you'll get a “not in scope” error – see the section at the top of this page):
data Foo = Foo {
_x :: Int,
_y :: Bool }
makeLenses
''Foo
This would generate the following lenses, which can be used to access the fields of Foo
:
x ::Lens'
Foo Int x f foo = (\x' -> foo {_x = x'})<$>
f (_x foo) y ::Lens'
Foo Bool y f foo = (\y' -> foo {_y = y'})<$>
f (_y foo)
(If you don't want a lens to be generated for some field, don't prefix it with “_”.)
If you want to create lenses for many types, you can do it all in one place like this (of course, instead you just can use makeLenses
several times if you feel it would be more readable):
data Foo = ... data Bar = ... data Quux = ...concat
<$>
mapM
makeLenses
[''Foo, ''Bar, ''Quux]
When the data type has type parameters, it's possible for a lens to do a polymorphic update – i.e. change the type of the thing along with changing the type of the field. For instance, with this type
data Foo a = Foo { _x :: a, _y :: Bool }
the following lenses would be generated:
x ::Lens
(Foo a) (Foo b) a b y ::Lens'
(Foo a) Bool
However, when there are several fields using the same type parameter, type-changing updates are no longer possible:
data Foo a = Foo { _x :: a, _y :: a }
generates
x ::Lens'
(Foo a) a y ::Lens'
(Foo a) a
Finally, when the type has several constructors, some of fields may not be always present – for those, a Traversal
is generated instead. For instance, in this example y
can be present or absent:
data FooBar = Foo { _x :: Int, _y :: Bool } | Bar { _x :: Int }
and the following accessors would be generated:
x ::Lens'
FooBar Int y ::Traversal'
FooBar Bool
So, to get _y
, you'd have to either use (^?
) if you're not sure it's there, or (^?!
) if you're absolutely sure (and if you're wrong, you'll get an exception). Setting and updating _y
can be done as usual.
Create a Vty handle. At most one handle should be created at a time for a given terminal device.
The specified configuration is added to the the configuration
loaded by userConfig
with the userConfig
configuration taking
precedence. See Graphics.Vty.Config.
For most applications mkVty defaultConfig
is sufficient.
standardIOConfig :: IO Config #
Configures VTY using defaults suitable for terminals. This function
can raise VtyConfigurationError
.
defaultConfig :: Config #
Representations of non-modifier keys.
- KFun is indexed from 0 to 63. Range of supported FKeys varies by terminal and keyboard.
- KUpLeft, KUpRight, KDownLeft, KDownRight, KCenter support varies by terminal and keyboard.
- Actually, support for most of these but KEsc, KChar, KBS, and KEnter vary by terminal and keyboard.
KEsc | |
KChar Char | |
KBS | |
KEnter | |
KLeft | |
KRight | |
KUp | |
KDown | |
KUpLeft | |
KUpRight | |
KDownLeft | |
KDownRight | |
KCenter | |
KFun Int | |
KBackTab | |
KPrtScr | |
KPause | |
KIns | |
KHome | |
KPageUp | |
KDel | |
KEnd | |
KPageDown | |
KBegin | |
KMenu |
Instances
Modifier keys. Key codes are interpreted such that users are more
likely to have Meta than Alt; for instance on the PC Linux console,
MMeta
will generally correspond to the physical Alt key.
Instances
Eq Modifier | |
Ord Modifier | |
Defined in Graphics.Vty.Input.Events | |
Read Modifier | |
Show Modifier | |
Generic Modifier | |
Parse Modifier | |
Defined in Graphics.Vty.Config parseValue :: Parser Modifier | |
type Rep Modifier | |
Defined in Graphics.Vty.Input.Events type Rep Modifier = D1 ('MetaData "Modifier" "Graphics.Vty.Input.Events" "vty-5.33-d400eec211b41e58acc410b10d79ca4624828bcbf5f0eb291b0c1dd87f602843" 'False) ((C1 ('MetaCons "MShift" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MCtrl" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "MMeta" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MAlt" 'PrefixI 'False) (U1 :: Type -> Type))) |
Mouse buttons.
Instances
Eq Button | |
Ord Button | |
Read Button | |
Show Button | |
Generic Button | |
type Rep Button | |
Defined in Graphics.Vty.Input.Events type Rep Button = D1 ('MetaData "Button" "Graphics.Vty.Input.Events" "vty-5.33-d400eec211b41e58acc410b10d79ca4624828bcbf5f0eb291b0c1dd87f602843" 'False) ((C1 ('MetaCons "BLeft" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BMiddle" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "BRight" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "BScrollUp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BScrollDown" 'PrefixI 'False) (U1 :: Type -> Type)))) |
type ClassifyMap = [(String, Event)] #
Sets the style, background color and foreground color to the default values for the terminal. There is no easy way to determine what the default background and foreground colors are.
Valid style attributes include:
- standout
- underline
- reverseVideo
- blink
- dim
- bold/bright
- italic
- strikethrough (via the smxx/rmxx terminfo capabilities)
(The invisible, protect, and altcharset display attributes some terminals support are not supported via VTY.)
brightMagenta :: Color #
brightBlue :: Color #