brick-0.7: A declarative terminal user interface library

Safe HaskellNone




This module provides a basic text editor widget. You'll need to embed an Editor in your application state and transform it with handleEvent when relevant events arrive. To get the contents of the editor, just use getEditContents. To modify it, use the TextZipper interface with applyEdit.

The editor's HandleEvent instance handles a set of basic input events that should suffice for most purposes; see the source for a complete list.



data Editor n Source

Editor state. Editors support the following events by default:

  • Ctrl-a: go to beginning of line
  • Ctrl-e: go to end of line
  • Ctrl-d, Del: delete character at cursor position
  • Backspace: delete character prior to cursor position
  • Ctrl-k: delete all from cursor to end of line
  • Arrow keys: move cursor
  • Enter: break the current line at the cursor position


Constructing an editor

editor Source


:: n

The editor's name (must be unique)

-> ([String] -> Widget n)

The content rendering function

-> Maybe Int

The limit on the number of lines in the editor (Nothing means no limit)

-> String

The initial content

-> Editor n 

Construct an editor.

Reading editor contents

getEditContents :: Editor n -> [String] Source

Get the contents of the editor.

Handling events

Editing text

applyEdit Source


:: (TextZipper String -> TextZipper String)

The Zipper editing transformation to apply

-> Editor n 
-> Editor n 

Apply an editing operation to the editor's contents. Bear in mind that you should only apply zipper operations that operate on the current line; the editor will only ever render the first line of text.

Lenses for working with editors

editDrawContentsL :: forall n. Lens' (Editor n) ([String] -> Widget n) Source

Rendering editors

renderEditor Source


:: (Ord n, Show n) 
=> Bool

Whether the editor has focus. It will report a cursor position if and only if it has focus.

-> Editor n

The editor.

-> Widget n 

Turn an editor state value into a widget


editAttr :: AttrName Source

The attribute assigned to the editor when it does not have focus.

editFocusedAttr :: AttrName Source

The attribute assigned to the editor when it has focus. Extends editAttr.