Home

Awesome

Wrapping Editor for Haskell

TestsWEditorWEditorHyphenWEditorBrick
Haskell CIHackage StatusHackage StatusHackage Status

This library contains a simple text-editing component for fixed-size fonts. It can either be used as a Brick Widget or as the basis for creating a new widget for another UI library.

Here are some important features:

If you have any problems using this library, or if you would like to see new features, please see the issues page. Also check out the library reference.

Installation

This library is split into 3 separate packages:

All of these packages can be installed from Hackage using cabal. You will need to explicitly install WEditor in order to set up editors in either of the other packages.

Using with Brick

See brick-example.hs for an example program that uses WrappingEditor.

You can run the example with:

ghc -threaded example/WEditorBrick/brick-example.hs
example/WEditorBrick/brick-example README.md

Press Esc to exit when you are finished. The final contents of the editor will be sent to stdout without modifying the file.

You can customize the widget using the following helper functions from the WrappingEditor module:

Using the Generic Editor

import WEditor.LineWrap
import WEditor.Document

-- 1. Split your doc into paragraphs. Paragraph splitting is handled by the
--    caller so that the library can avoid end-of-line considerations.
paragraphs = map UnparsedPara $ lines $ "Your document contents."

-- 2. Create an editor. This example uses lazy word hyphenation.
editor = editDocument (breakWords lazyHyphen) paragraphs

-- 3a. Edit the document using actions from `Viewer` and `Editor`. Don't forget
--     to set the viewport size! If either dimension is < 1, the text will be
--     unbounded in that direction.
editor' = foldl (flip ($)) editor [
    viewerResizeAction (80,24),
    editorEndAction,
    editorEnterAction,
    editorAppendAction "Here is a new paragraph.",
    -- Resizing while editing is fine.
    viewerResizeAction (7,3),
    -- Use this if you don't like scrolling below the last line.
    viewerFillAction
  ]

-- 3b. Get the viewport contents for display. This does not necessarily fill up
--     the entire view area; pad it if necessary.
display = getVisible editor'

-- 4. Extract the edited contents.
final = unlines $ map upText $ exportData editor'

Wrapping Policies

Character Support

The generic editor can support any character type for which a wrapping policy is available. The editor for Brick currently only supports Char, but it will likely be modified to support other character types.