brick-2.1.1: A declarative terminal user interface library

Safe Haskell | Safe-Inferred
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?" As is typical in such cases, we assume that this dialog box is used modally, meaning that while it is open it is has exclusive input focus until it is closed.

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 n
- dialogTitle :: Dialog a n -> Maybe (Widget n)
- dialogButtons :: Dialog a n -> [(String, n, a)]
- dialogWidth :: Dialog a n -> Int
- dialog :: Eq n => Maybe (Widget n) -> Maybe (n, [(String, n, a)]) -> Int -> Dialog a n
- renderDialog :: Ord n => Dialog a n -> Widget n -> Widget n
- getDialogFocus :: Dialog a n -> Maybe n
- setDialogFocus :: Eq n => n -> Dialog a n -> Dialog a n
- handleDialogEvent :: Event -> EventM n (Dialog a n) ()
- dialogSelection :: Eq n => Dialog a n -> Maybe (n, a)
- dialogAttr :: AttrName
- buttonAttr :: AttrName
- buttonSelectedAttr :: AttrName
- dialogButtonsL :: forall a n a. Lens (Dialog a n) (Dialog a n) [(String, n, a)] [(String, n, a)]
- dialogWidthL :: forall a n. Lens' (Dialog a n) Int
- dialogTitleL :: forall a n. Lens' (Dialog a n) (Maybe (Widget n))

# Documentation

data Dialog a n 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 n -> Maybe (Widget n) Source #

The dialog title

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

The dialog buttons' labels, resource names, and values

dialogWidth :: Dialog a n -> Int Source #

The maximum width of the dialog

# Construction and rendering

dialog Source #

Arguments

:: Eq n |
=> Maybe (Widget n) | The dialog title
-> Maybe (n, [(String, n, a)]) | The currently-selected button resource name and the button labels, resource names, and values to use for each button, respectively
-> Int | The maximum width of the dialog
-> Dialog a n |

Create a dialog.

renderDialog :: Ord n => Dialog a n -> 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.

getDialogFocus :: Dialog a n -> Maybe n Source #

Get the focused button of a dialog.

setDialogFocus :: Eq n => n -> Dialog a n -> Dialog a n Source #

Set the focused button of a dialog.

# Handling events

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

# Getting a dialog's current value

dialogSelection :: Eq n => Dialog a n -> Maybe (n, a) Source #

Obtain the resource name and value associated with the dialog's currently-selected button, if any. The result of 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 n a. Lens (Dialog a n) (Dialog a n) [(String, n, a)] [(String, n, a)] Source #

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

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