brick-0.47.1: A declarative terminal user interface library

Safe Haskell | None
Language | Haskell2010

Brick.Widgets.Dialog

Contents

- Construction and rendering
- Handling events
- Getting a dialog's current value
- Attributes
- Lenses

Description

This module provides a simple dialog widget. You get to pick the dialog title, if any, as well as its body and buttons.

Note that this dialog is really for simple use cases where you want to get the user's answer to a question, such as "Would you like to save changes before quitting?" If you require something more sophisticated, you'll need to build it yourself. You might also consider seeing the `Forms` module for help with input management, and see the implementation of this module to see how to reproduce a dialog-style UI.

Synopsis

- data Dialog a
- dialogTitle :: Dialog a -> Maybe String
- dialogButtons :: Dialog a -> [(String, a)]
- dialogSelectedIndex :: Dialog a -> Maybe Int
- dialogWidth :: Dialog a -> Int
- dialog :: Maybe String -> Maybe (Int, [(String, a)]) -> Int -> Dialog a
- renderDialog :: Dialog a -> Widget n -> Widget n
- handleDialogEvent :: Event -> Dialog a -> EventM n (Dialog a)
- dialogSelection :: Dialog a -> Maybe a
- dialogAttr :: AttrName
- buttonAttr :: AttrName
- buttonSelectedAttr :: AttrName
- dialogButtonsL :: forall a a. Lens (Dialog a) (Dialog a) [(String, a)] [(String, a)]
- dialogSelectedIndexL :: forall a. Lens' (Dialog a) (Maybe Int)
- dialogWidthL :: forall a. Lens' (Dialog a) Int
- dialogTitleL :: forall a. Lens' (Dialog a) (Maybe String)

# Documentation

data Dialog a Source #

Dialogs present a window with a title (optional), a body, and buttons (optional). Dialog buttons are labeled with strings and map to values of type `a`, which you choose.

Dialogs handle the following events by default with handleDialogEvent:

- Tab or Right Arrow: select the next button
- Shift-tab or Left Arrow: select the previous button

dialogTitle :: Dialog a -> Maybe String Source #

The dialog title

dialogButtons :: Dialog a -> [(String, a)] Source #

The dialog button labels and values

dialogSelectedIndex :: Dialog a -> Maybe Int Source #

The currently selected dialog button index (if any)

dialogWidth :: Dialog a -> Int Source #

The maximum width of the dialog

# Construction and rendering

dialog Source #

Arguments

:: Maybe String | The dialog title
-> Maybe (Int, [(String, a)]) | The currently-selected button index (starting at zero) and the button labels and values to use
-> Int | The maximum width of the dialog
-> Dialog a |

Create a dialog.

renderDialog :: Dialog a -> Widget n -> Widget n Source #

Render a dialog with the specified body widget. This renders the dialog as a layer, which makes this suitable as a top-level layer in your rendering function to be rendered on top of the rest of your interface.

# Handling events

handleDialogEvent :: Event -> Dialog a -> EventM n (Dialog a) Source #

# Getting a dialog's current value

dialogSelection :: Dialog a -> Maybe a Source #

Obtain the value associated with the dialog's currently-selected button, if any. This function is probably what you want when someone presses `Enter` in a dialog.

# Attributes

dialogAttr :: AttrName Source #

The default attribute of the dialog

buttonAttr :: AttrName Source #

The default attribute for all dialog buttons

buttonSelectedAttr :: AttrName Source #

The attribute for the selected dialog button (extends `dialogAttr`)

# Lenses

dialogButtonsL :: forall a a. Lens (Dialog a) (Dialog a) [(String, a)] [(String, a)] Source #

dialogSelectedIndexL :: forall a. Lens' (Dialog a) (Maybe Int) Source #

dialogWidthL :: forall a. Lens' (Dialog a) Int Source #

dialogTitleL :: forall a. Lens' (Dialog a) (Maybe String) Source #