Edit: docstrings, export only useful lenses

This commit is contained in:
Jonathan Daugherty 2015-07-07 20:01:46 -07:00
parent 00798b78b3
commit 8399654b76

View File

@ -1,12 +1,24 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
-- | This module provides a basic single-line 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 'editContents'.
--
-- 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.
module Brick.Widgets.Edit
( Editor(editContents, editCursorPos, editorName, editDrawContents)
-- * Constructing an editor
, editor
-- * Lenses for working with editors
, editContentsL
, editCursorPosL
, editorNameL
, editDrawContentsL
-- * Rendering editors
, renderEditor
-- * Attributes
, editAttr
)
where
@ -20,11 +32,16 @@ import Brick.Widgets.Core
import Brick.Util (clamp)
import Brick.AttrMap
-- | Editor state.
data Editor =
Editor { editContents :: !String
-- ^ The contents of the editor
, editCursorPos :: !Int
-- ^ The editor's cursor position
, editDrawContents :: String -> Widget
-- ^ The function the editor uses to draw its contents
, editorName :: Name
-- ^ The name of the editor
}
suffixLenses ''Editor
@ -80,12 +97,21 @@ insertChar c theEdit =
listInsert :: a -> Int -> [a] -> [a]
listInsert a i as = take i as ++ [a] ++ drop i as
editor :: Name -> (String -> Widget) -> String -> Editor
-- | Construct an editor.
editor :: Name
-- ^ The editor's name (must be unique)
-> (String -> Widget)
-- ^ The content rendering function
-> String
-- ^ The initial content
-> Editor
editor name draw s = Editor s (length s) draw name
-- | The attribute assigned to the editor
editAttr :: AttrName
editAttr = "edit"
-- | Turn an editor state value into a widget
renderEditor :: Editor -> Widget
renderEditor e =
let cursorLoc = Location (e^.editCursorPosL, 0)