Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides KeyConfig
and associated functions. A
KeyConfig
is the basis for the custom keybinding system in this
library.
To get started, see newKeyConfig
. Once a KeyConfig
has been
constructed, see keyDispatcher
.
Since a key configuration can have keys bound to multiple events, it
is the application author's responsibility to check for collisions
since the nature of the collisions will depend on how the application
is implemented. To check for collisions, use the result of
keyEventMappings
.
Synopsis
- data KeyConfig k
- newKeyConfig :: Ord k => KeyEvents k -> [(k, [Binding])] -> [(k, BindingState)] -> KeyConfig k
- data BindingState
- = BindingList [Binding]
- | Unbound
- data Binding = Binding {}
- class ToBinding a where
- binding :: Key -> [Modifier] -> Binding
- fn :: Int -> Binding
- meta :: ToBinding a => a -> Binding
- ctrl :: ToBinding a => a -> Binding
- shift :: ToBinding a => a -> Binding
- firstDefaultBinding :: (Show k, Ord k) => KeyConfig k -> k -> Maybe Binding
- firstActiveBinding :: (Show k, Ord k) => KeyConfig k -> k -> Maybe Binding
- allDefaultBindings :: Ord k => KeyConfig k -> k -> [Binding]
- allActiveBindings :: (Show k, Ord k) => KeyConfig k -> k -> [Binding]
- keyEventMappings :: (Ord k, Eq k) => KeyConfig k -> [(Binding, Set k)]
- keyConfigEvents :: KeyConfig k -> KeyEvents k
- lookupKeyConfigBindings :: Ord k => KeyConfig k -> k -> Maybe BindingState
Documentation
A configuration of custom key bindings. A KeyConfig
stores everything needed to resolve a key event into one or
more key bindings. Make a KeyConfig
with newKeyConfig
,
then use it to dispatch to KeyEventHandler
s with
keyDispatcher
.
Make a new KeyConfig
with newKeyConfig
.
A KeyConfig
stores:
- A collection of named key events, mapping the event type
k
toText
labels. - For each event
k
, optionally store a list of default key bindings for that event. - An optional customized binding list for each event, setting the
event to either
Unbound
or providing explicit overridden bindings withBindingList
.
:: Ord k | |
=> KeyEvents k | The base mapping of key events and names to use. |
-> [(k, [Binding])] | Default bindings by key event, such as from a configuration file or embedded code. Optional on a per-event basis. |
-> [(k, BindingState)] | Custom bindings by key event, such as from a
configuration file. Explicitly setting an event to
|
-> KeyConfig k |
data BindingState Source #
An explicit configuration of key bindings for a key event.
BindingList [Binding] | Bind the event to the specified list of bindings. |
Unbound | Disable all bindings for the event, including default bindings. |
Instances
Show BindingState Source # | |
Defined in Brick.Keybindings.KeyConfig showsPrec :: Int -> BindingState -> ShowS # show :: BindingState -> String # showList :: [BindingState] -> ShowS # | |
Eq BindingState Source # | |
Defined in Brick.Keybindings.KeyConfig (==) :: BindingState -> BindingState -> Bool # (/=) :: BindingState -> BindingState -> Bool # | |
Ord BindingState Source # | |
Defined in Brick.Keybindings.KeyConfig compare :: BindingState -> BindingState -> Ordering # (<) :: BindingState -> BindingState -> Bool # (<=) :: BindingState -> BindingState -> Bool # (>) :: BindingState -> BindingState -> Bool # (>=) :: BindingState -> BindingState -> Bool # max :: BindingState -> BindingState -> BindingState # min :: BindingState -> BindingState -> BindingState # |
Specifying bindings
A key binding.
The easiest way to express Binding
s is to use the helper functions
in this module that work with instances of ToBinding
, e.g.
let ctrlB =ctrl
'b' shiftX =shift
'x' ctrlMetaK =ctrl
$meta
'k' -- Or with Vty keys directly: ctrlDown =ctrl
KDown
class ToBinding a where Source #
The class of types that can form the basis of Binding
s.
This is provided to make it easy to write and modify bindings in less verbose ways.
Instances
Querying KeyConfigs
firstDefaultBinding :: (Show k, Ord k) => KeyConfig k -> k -> Maybe Binding Source #
A convenience function to return the first result of
allDefaultBindings
, if any.
firstActiveBinding :: (Show k, Ord k) => KeyConfig k -> k -> Maybe Binding Source #
A convenience function to return the first result of
allActiveBindings
, if any.
allDefaultBindings :: Ord k => KeyConfig k -> k -> [Binding] Source #
Returns the list of default bindings for the specified event,
irrespective of whether the event has been explicitly configured with
other bindings or set to Unbound
.
keyEventMappings :: (Ord k, Eq k) => KeyConfig k -> [(Binding, Set k)] Source #
Return a list of mappings including each key bound to any event combined with the list of events to which it is bound. This is useful for identifying problematic key binding collisions. Since key binding collisions cannot be determined in general, we leave it up to the application author to determine which key-to-event bindings are problematic.
Misc
keyConfigEvents :: KeyConfig k -> KeyEvents k Source #
The base mapping of events and their names that is used in this configuration.
lookupKeyConfigBindings :: Ord k => KeyConfig k -> k -> Maybe BindingState Source #
Look up the binding state for the specified event. This returns
Nothing
when the event has no explicitly configured custom
BindingState
.