HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulebrick-2.10Haskell2010

Brick.Keybindings.KeyConfig

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 Brick.Keybindings.KeyHandlerMap.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.

  • 3 types
  • 1 class
  • 13 values
  • Packagebrick-2.10
  • Exports17
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceKeyConfig.hs
datadata KeyConfig k
#

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 KeyEventHandlers with Brick.Keybindings.KeyHandlerMap.keyDispatcher.

Make a new KeyConfig with newKeyConfig.

A KeyConfig stores:

  • A collection of named key events, mapping the event type k to Text 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 with BindingList.

Instances2Eq, Show
  • Eq k => Eq (KeyConfig k)Defined in brick-2.10 · Brick.Keybindings.KeyConfig
  • Show k => Show (KeyConfig k)Defined in brick-2.10 · Brick.Keybindings.KeyConfig
valuenewKeyConfig
  1. :: Ord k
  2. => KeyEvents k

    The base mapping of key events and names to use.

  3. -> [(k, [Binding])]

    Default bindings by key event, such as from a configuration file or embedded code. Optional on a per-event basis.

  4. -> [(k, BindingState)]

    Custom bindings by key event, such as from a configuration file. Explicitly setting an event to Unbound here has the effect of disabling its default bindings. Optional on a per-event basis. Note that this function does not check for collisions since it is up to the application to determine whether a key bound to more than one event constitutes a collision!

  5. -> KeyConfig k
#

Build a KeyConfig with the specified KeyEvents event-to-name mapping, list of default bindings by event, and list of custom bindings by event.

datadata BindingState
#

An explicit configuration of key bindings for a key event.

Constructors

  • BindingList [Binding]

    Bind the event to the specified list of bindings.

  • Unbound

    Disable all bindings for the event, including default bindings.

Instances3Eq, Ord, Show

Specifying bindings

7 declarations
datadata Binding
#

A key binding.

The easiest way to express Bindings 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 Graphics.Vty.Input.KDown

Constructors

Instances4Eq, Ord, Show, ToBinding
  • Eq BindingDefined in brick-2.10 · Brick.Keybindings.KeyConfig
  • Ord BindingDefined in brick-2.10 · Brick.Keybindings.KeyConfig
  • Show BindingDefined in brick-2.10 · Brick.Keybindings.KeyConfig
  • ToBinding BindingDefined in brick-2.10 · Brick.Keybindings.KeyConfig
classclass ToBinding a where
#

The class of types that can form the basis of Bindings.

This is provided to make it easy to write and modify bindings in less verbose ways.

Methods

Instances3ToBinding
valuebinding :: Key -> [Modifier] -> Binding
#

Construct a Binding. Modifier order is ignored. If modifiers are given and the binding is for a character key, it is forced to lowercase.

valuemeta :: ToBinding a => a -> Binding
#

Add Meta to a binding. If the binding is for a character key, force it to lowercase.

valuectrl :: ToBinding a => a -> Binding
#

Add Ctrl to a binding. If the binding is for a character key, force it to lowercase.

valueshift :: ToBinding a => a -> Binding
#

Add Shift to a binding. If the binding is for a character key, force it to lowercase.

Querying KeyConfigs

5 declarations
valueallDefaultBindings :: Ord k => KeyConfig k -> k -> [Binding]
#

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.

valueallActiveBindings :: (Show k, Ord k) => KeyConfig k -> k -> [Binding]
#

Return all active key bindings for the specified event. This returns customized bindings if any have been set in the KeyConfig, no bindings if the event has been explicitly set to Unbound, or the default bindings if the event is absent from the customized bindings.

valuekeyEventMappings :: (Ord k, Eq k) => KeyConfig k -> [(Binding, Set k)]
#

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

2 declarations