Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides a basic text editor widget. You'll need to
embed an Editor
in your application state and transform it with
handleEditorEvent
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 handleEditorEvent
function handles a set of basic
input events that should suffice for most purposes; see the source
for a complete list.
Bear in mind that the editor provided by this module is intended to provide basic input support for brick applications but it is not intended to be a replacement for your favorite editor such as Vim or Emacs. It is also not suitable for building sophisticated editors. If you want to build your own editor, I suggest starting from scratch.
- data Editor t n
- editor :: GenericTextZipper a => n -> Maybe Int -> a -> Editor a n
- editorText :: n -> Maybe Int -> Text -> Editor Text n
- getEditContents :: Monoid t => Editor t n -> [t]
- handleEditorEvent :: (Eq t, Monoid t) => Event -> Editor t n -> EventM n (Editor t n)
- applyEdit :: (TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
- editContentsL :: forall t n t. Lens (Editor t n) (Editor t n) (TextZipper t) (TextZipper t)
- renderEditor :: (Ord n, Show n, Monoid t, TextWidth t, GenericTextZipper t) => ([t] -> Widget n) -> Bool -> Editor t n -> Widget n
- editAttr :: AttrName
- editFocusedAttr :: AttrName
Documentation
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
- Ctrl-u: delete all from cursor to beginning of line
- Arrow keys: move cursor
- Enter: break the current line at the cursor position
Constructing an editor
:: GenericTextZipper a | |
=> n | The editor's name (must be unique) |
-> Maybe Int | The limit on the number of lines in the editor ( |
-> a | The initial content |
-> Editor a n |
Construct an editor over String
values
:: n | The editor's name (must be unique) |
-> Maybe Int | The limit on the number of lines in the editor ( |
-> Text | The initial content |
-> Editor Text n |
Construct an editor over Text
values
Reading editor contents
getEditContents :: Monoid t => Editor t n -> [t] Source #
Get the contents of the editor.
Handling events
Editing text
:: (TextZipper t -> TextZipper t) | The |
-> Editor t n | |
-> Editor t 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
editContentsL :: forall t n t. Lens (Editor t n) (Editor t n) (TextZipper t) (TextZipper t) Source #
Rendering editors
:: (Ord n, Show n, Monoid t, TextWidth t, GenericTextZipper t) | |
=> ([t] -> Widget n) | The content drawing function |
-> Bool | Whether the editor has focus. It will report a cursor position if and only if it has focus. |
-> Editor t n | The editor. |
-> Widget n |
Turn an editor state value into a widget. This uses the editor's name for its scrollable viewport handle and the name is also used to report mouse events.
Attributes
editFocusedAttr :: AttrName Source #
The attribute assigned to the editor when it has focus. Extends
editAttr
.