brick-0.2.1: A declarative terminal user interface library

Safe HaskellNone
LanguageHaskell2010

Brick.Widgets.Edit

Contents

Description

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.

Synopsis

Documentation

data Editor 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

Instances

Constructing an editor

editor Source

Arguments

:: Name

The editor's name (must be unique)

-> ([String] -> Widget)

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 

Construct an editor.

Reading editor contents

getEditContents :: Editor -> [String] Source

Get the contents of the editor.

Editing text

applyEdit Source

Arguments

:: (TextZipper String -> TextZipper String)

The Zipper editing transformation to apply

-> Editor 
-> Editor 

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

Rendering editors

renderEditor :: Editor -> Widget Source

Turn an editor state value into a widget

Attributes

editAttr :: AttrName Source

The attribute assigned to the editor