brick-2.3.1: A declarative terminal user interface library
Safe HaskellSafe-Inferred
LanguageHaskell2010

Brick.Widgets.Dialog

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

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

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 #