-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Generic text-editor logic for use with fixed-width fonts.
--
-- This package contains interfaces and implementations of text-editing
-- idioms that can be wired up to UI libraries to create a text-editor
-- widget.
--
-- The goal is to provide:
--
--
-- - Dynamic line wrapping that preserves the cursor and edit
-- positions.
-- - Customizable line-wrapping policies and word-hyphenation
-- policies.
-- - Automatic management of a dynamically-sized viewable area.
-- - Support for novel character types.
--
@package WEditor
@version 0.2.0.0
-- | Features of character sets.
module WEditor.Base.Char
-- | Supporting hyphenation.
class HyphenChar c
-- | The canonical hyphen character.
defaultHyphen :: HyphenChar c => c
-- | Dealing with whitespace characters.
class WhitespaceChar c
-- | Predicate for identifying whitespace characters.
defaultIsWhitespace :: WhitespaceChar c => c -> Bool
-- | Dealing with word characters.
class WhitespaceChar c => WordChar c
-- | Predicate for identifying word characters.
defaultIsWordChar :: WordChar c => c -> Bool
instance WEditor.Base.Char.HyphenChar GHC.Types.Char
instance WEditor.Base.Char.WordChar GHC.Types.Char
instance WEditor.Base.Char.WhitespaceChar GHC.Types.Char
-- | Simple representation of viewable text lines.
module WEditor.Base.Line
-- | Line meant for viewing.
data VisibleLine c b
VisibleLine :: b -> [c] -> VisibleLine c b
-- | The type of line break for this line.
[vlBreak] :: VisibleLine c b -> b
-- | The complete data of the line.
[vlText] :: VisibleLine c b -> [c]
instance (GHC.Show.Show b, GHC.Show.Show c) => GHC.Show.Show (WEditor.Base.Line.VisibleLine c b)
instance (GHC.Classes.Ord b, GHC.Classes.Ord c) => GHC.Classes.Ord (WEditor.Base.Line.VisibleLine c b)
instance (GHC.Classes.Eq b, GHC.Classes.Eq c) => GHC.Classes.Eq (WEditor.Base.Line.VisibleLine c b)
-- | Simple representation of text paragraphs.
module WEditor.Base.Para
-- | Single paragraph that has not been parsed into lines.
data UnparsedPara c
UnparsedPara :: [c] -> UnparsedPara c
-- | The complete and uparsed paragraph data.
[upText] :: UnparsedPara c -> [c]
-- | Create an empty paragraph.
emptyPara :: UnparsedPara c
instance GHC.Show.Show c => GHC.Show.Show (WEditor.Base.Para.UnparsedPara c)
instance GHC.Classes.Ord c => GHC.Classes.Ord (WEditor.Base.Para.UnparsedPara c)
instance GHC.Classes.Eq c => GHC.Classes.Eq (WEditor.Base.Para.UnparsedPara c)
-- | Generic text-editing functionality.
module WEditor.Base.Editor
-- | Actions that modify data.
data EditAction c
-- | Insert a block of characters.
InsertText :: [c] -> EditAction c
-- | Delete a single character.
DeleteText :: EditAction c
-- | Modification direction, relative to the cursor.
data EditDirection
-- | Apply the edit before the cursor.
EditBefore :: EditDirection
-- | Apply the edit after the cursor.
EditAfter :: EditDirection
-- | Any action that updates a FixedFontEditor.
type EditorAction c = forall a. FixedFontEditor a c => a -> a
-- | Actions that change the cursor position without changing data.
data MoveDirection
-- | Move up one line.
MoveUp :: MoveDirection
-- | Move down one line.
MoveDown :: MoveDirection
-- | Move backward one character.
MovePrev :: MoveDirection
-- | Move forward one character.
MoveNext :: MoveDirection
-- | Implementation-defined home operation.
MoveHome :: MoveDirection
-- | Implementation-defined end operation.
MoveEnd :: MoveDirection
-- | Implementation-defined page-up operation.
MovePageUp :: MoveDirection
-- | Implementation-defined page-down operation.
MovePageDown :: MoveDirection
-- | Generic text editor for fixed-width fonts.
class FixedFontEditor a c | a -> c
-- | Apply an edit action.
editText :: FixedFontEditor a c => a -> EditAction c -> EditDirection -> a
-- | Break the current paragraph at the cursor.
breakPara :: FixedFontEditor a c => a -> EditDirection -> a
-- | Apply a cursor movement.
moveCursor :: FixedFontEditor a c => a -> MoveDirection -> a
-- | Get the (row,col) cursor position relative to the viewport.
getCursor :: FixedFontEditor a c => a -> (Int, Int)
-- | Get the absolute (paragraph,char) edit position.
--
-- The position can be restored after cursor movements by calling
-- setEditPoint; however, calling editText or
-- breakPara invalidates this position.
getEditPoint :: FixedFontEditor a c => a -> (Int, Int)
-- | Set the absolute (paragraph,char) edit position.
setEditPoint :: FixedFontEditor a c => a -> (Int, Int) -> a
-- | Get the number of characters in the current paragraph.
getParaSize :: FixedFontEditor a c => a -> Int
-- | Get the number of paragraphs in the document.
getParaCount :: FixedFontEditor a c => a -> Int
-- | Export the modified data.
exportData :: FixedFontEditor a c => a -> [UnparsedPara c]
-- | Action for normal character insertion.
editorAppendAction :: [c] -> EditorAction c
-- | Action for the Backspace key.
editorBackspaceAction :: EditorAction c
-- | Action for the Delete key.
editorDeleteAction :: EditorAction c
-- | Action for the down-arrow key.
editorDownAction :: EditorAction c
-- | Action for the End key.
editorEndAction :: EditorAction c
-- | Action for the Enter key.
editorEnterAction :: EditorAction c
-- | Action for the Home key.
editorHomeAction :: EditorAction c
-- | Action to insert after the cursor.
editorInsertAction :: [c] -> EditorAction c
-- | Action for the left-arrow key.
editorLeftAction :: EditorAction c
-- | Action for the PageDown key.
editorPageDownAction :: EditorAction c
-- | Action for the PageUp key.
editorPageUpAction :: EditorAction c
-- | Action for the right-arrow key.
editorRightAction :: EditorAction c
-- | Action to set the absolute (paragraph,char) edit position.
editorSetPositionAction :: (Int, Int) -> EditorAction c
-- | Action for the up-arrow key.
editorUpAction :: EditorAction c
instance GHC.Show.Show WEditor.Base.Editor.MoveDirection
instance GHC.Classes.Eq WEditor.Base.Editor.MoveDirection
instance GHC.Show.Show WEditor.Base.Editor.EditDirection
instance GHC.Classes.Eq WEditor.Base.Editor.EditDirection
instance GHC.Show.Show c => GHC.Show.Show (WEditor.Base.Editor.EditAction c)
instance GHC.Classes.Eq c => GHC.Classes.Eq (WEditor.Base.Editor.EditAction c)
-- | Generic line-parsing functionality.
module WEditor.Base.Parser
-- | Line parser for fixed-width fonts.
class FixedFontParser a c | a -> c where {
-- | Type used to differentiate between line-break types.
type family BreakType a :: *;
}
-- | Change the max line width used for parsing. A width of zero must
-- result in breakLines skipping line breaks.
setLineWidth :: FixedFontParser a c => a -> Int -> a
-- | Break the sequence into lines.
--
-- The following must hold for all possible inputs to a
-- FixedFontParser p:
--
--
-- concat (map vlText (breakLines p line)) == line
--
--
-- Implement renderLine and tweakCursor to make visual
-- adjustments (such as adding hyphens or indentation) if necessary.
breakLines :: FixedFontParser a c => a -> [c] -> [VisibleLine c (BreakType a)]
-- | A place-holder line for empty paragraphs.
emptyLine :: FixedFontParser a c => a -> VisibleLine c (BreakType a)
-- | Render the line for viewing. Implement tweakCursor if
-- renderLine changes the positions of any characters on the line.
renderLine :: FixedFontParser a c => a -> VisibleLine c (BreakType a) -> [c]
-- | Adjust the horizontal cursor position.
tweakCursor :: FixedFontParser a c => a -> VisibleLine c (BreakType a) -> Int -> Int
-- | Split the line to create a paragraph break.
splitLine :: FixedFontParser a c => a -> Int -> VisibleLine c (BreakType a) -> (VisibleLine c (BreakType a), VisibleLine c (BreakType a))
-- | Generic editor-viewport functionality.
module WEditor.Base.Viewer
-- | Generic editor viewport for fixed-width fonts.
class FixedFontViewer a c | a -> c
-- | Set the (width,height) size of the viewport. A width < 0 must
-- disable line wrapping, and a height < 0 must disable vertical
-- bounding.
setViewSize :: FixedFontViewer a c => a -> (Int, Int) -> a
-- | Get the (width,height) size of the viewport.
getViewSize :: FixedFontViewer a c => a -> (Int, Int)
-- | Get the visible lines in the viewport. This does not need to
-- completely fill the viewport area, but it must not exceed it.
getVisible :: FixedFontViewer a c => a -> [[c]]
-- | Apply a view change.
updateView :: FixedFontViewer a c => a -> ViewAction -> a
-- | Actions that modify the view without affecting editing.
data ViewAction
-- | Shift the vertical offset. Negative values shift up.
ShiftVertical :: Int -> ViewAction
-- | Attempt to fill the entire viewport.
FillView :: ViewAction
-- | Any action that updates a FixedFontViewer.
type ViewerAction c = forall a. FixedFontViewer a c => a -> a
viewerFillAction :: ViewerAction c
-- | Action to resize the viewport.
viewerResizeAction :: (Int, Int) -> ViewerAction c
-- | Action to shift the view upward.
viewerShiftUpAction :: Int -> ViewerAction c
-- | Action to shift the view downward.
viewerShiftDownAction :: Int -> ViewerAction c
instance GHC.Show.Show WEditor.Base.Viewer.ViewAction
instance GHC.Classes.Eq WEditor.Base.Viewer.ViewAction
-- | Base module for implementing new editor functionality.
module WEditor.Base
-- | Generic document-editing components.
module WEditor.Document
-- | Generic document editor with a dynamic viewport.
--
-- This editor bounds vertical view scrolling (see ViewAction) to
-- keep the cursor within view.
data EditingDocument c
-- | Create an editor for a document.
editDocument :: FixedFontParser a c => a -> [UnparsedPara c] -> EditingDocument c
-- | Actions that modify data.
data EditAction c
-- | Insert a block of characters.
InsertText :: [c] -> EditAction c
-- | Delete a single character.
DeleteText :: EditAction c
-- | Modification direction, relative to the cursor.
data EditDirection
-- | Apply the edit before the cursor.
EditBefore :: EditDirection
-- | Apply the edit after the cursor.
EditAfter :: EditDirection
-- | Any action that updates a FixedFontEditor.
type EditorAction c = forall a. FixedFontEditor a c => a -> a
-- | Generic text editor for fixed-width fonts.
class FixedFontEditor a c | a -> c
-- | Apply an edit action.
editText :: FixedFontEditor a c => a -> EditAction c -> EditDirection -> a
-- | Break the current paragraph at the cursor.
breakPara :: FixedFontEditor a c => a -> EditDirection -> a
-- | Apply a cursor movement.
moveCursor :: FixedFontEditor a c => a -> MoveDirection -> a
-- | Get the (row,col) cursor position relative to the viewport.
getCursor :: FixedFontEditor a c => a -> (Int, Int)
-- | Get the absolute (paragraph,char) edit position.
--
-- The position can be restored after cursor movements by calling
-- setEditPoint; however, calling editText or
-- breakPara invalidates this position.
getEditPoint :: FixedFontEditor a c => a -> (Int, Int)
-- | Set the absolute (paragraph,char) edit position.
setEditPoint :: FixedFontEditor a c => a -> (Int, Int) -> a
-- | Get the number of characters in the current paragraph.
getParaSize :: FixedFontEditor a c => a -> Int
-- | Get the number of paragraphs in the document.
getParaCount :: FixedFontEditor a c => a -> Int
-- | Export the modified data.
exportData :: FixedFontEditor a c => a -> [UnparsedPara c]
-- | Line parser for fixed-width fonts.
class FixedFontParser a c | a -> c
-- | Generic editor viewport for fixed-width fonts.
class FixedFontViewer a c | a -> c
-- | Set the (width,height) size of the viewport. A width < 0 must
-- disable line wrapping, and a height < 0 must disable vertical
-- bounding.
setViewSize :: FixedFontViewer a c => a -> (Int, Int) -> a
-- | Get the (width,height) size of the viewport.
getViewSize :: FixedFontViewer a c => a -> (Int, Int)
-- | Get the visible lines in the viewport. This does not need to
-- completely fill the viewport area, but it must not exceed it.
getVisible :: FixedFontViewer a c => a -> [[c]]
-- | Apply a view change.
updateView :: FixedFontViewer a c => a -> ViewAction -> a
-- | Actions that change the cursor position without changing data.
data MoveDirection
-- | Move up one line.
MoveUp :: MoveDirection
-- | Move down one line.
MoveDown :: MoveDirection
-- | Move backward one character.
MovePrev :: MoveDirection
-- | Move forward one character.
MoveNext :: MoveDirection
-- | Implementation-defined home operation.
MoveHome :: MoveDirection
-- | Implementation-defined end operation.
MoveEnd :: MoveDirection
-- | Implementation-defined page-up operation.
MovePageUp :: MoveDirection
-- | Implementation-defined page-down operation.
MovePageDown :: MoveDirection
-- | Single paragraph that has not been parsed into lines.
data UnparsedPara c
UnparsedPara :: [c] -> UnparsedPara c
-- | The complete and uparsed paragraph data.
[upText] :: UnparsedPara c -> [c]
-- | Any action that updates a FixedFontViewer.
type ViewerAction c = forall a. FixedFontViewer a c => a -> a
-- | Action for normal character insertion.
editorAppendAction :: [c] -> EditorAction c
-- | Action for the Backspace key.
editorBackspaceAction :: EditorAction c
-- | Action for the Delete key.
editorDeleteAction :: EditorAction c
-- | Action for the down-arrow key.
editorDownAction :: EditorAction c
-- | Action for the End key.
editorEndAction :: EditorAction c
-- | Action for the Enter key.
editorEnterAction :: EditorAction c
-- | Action for the Home key.
editorHomeAction :: EditorAction c
-- | Action to insert after the cursor.
editorInsertAction :: [c] -> EditorAction c
-- | Action for the left-arrow key.
editorLeftAction :: EditorAction c
-- | Action for the PageDown key.
editorPageDownAction :: EditorAction c
-- | Action for the PageUp key.
editorPageUpAction :: EditorAction c
-- | Action for the right-arrow key.
editorRightAction :: EditorAction c
-- | Action to set the absolute (paragraph,char) edit position.
editorSetPositionAction :: (Int, Int) -> EditorAction c
-- | Action for the up-arrow key.
editorUpAction :: EditorAction c
viewerFillAction :: ViewerAction c
-- | Action to resize the viewport.
viewerResizeAction :: (Int, Int) -> ViewerAction c
-- | Action to shift the view upward.
viewerShiftUpAction :: Int -> ViewerAction c
-- | Action to shift the view downward.
viewerShiftDownAction :: Int -> ViewerAction c
instance GHC.Show.Show (WEditor.Document.EditingDocument c)
instance WEditor.Base.Viewer.FixedFontViewer (WEditor.Document.EditingDocument c) c
instance WEditor.Base.Editor.FixedFontEditor (WEditor.Document.EditingDocument c) c
-- | Line-wrapping implementations. (See FixedFontParser for custom
-- wrapping.)
module WEditor.LineWrap
-- | Wrapping policy that breaks lines based on words. Use
-- breakWords to construct a new value.
data BreakWords c
-- | Line break type for a single paragraph line.
data LineBreak
-- | Word-splitting operations for use with BreakWords.
class WordSplitter a c | a -> c
-- | Determine where to break a word.
--
--
-- - The splitter can refuse to process the word by returning
-- Nothing.
-- - The segment sizes must provide space for a hyphen if
-- appendHyphen extends the line.
-- - Once the word has been split up by BreakWords, the segments
-- are processed as follows:
- The last segment is prepended to the
-- next line to be parsed. This means that if the word is not split, it
-- gets deferred to the next line.
- If there are more segments,
-- the first is appended to the current line being parsed.
- All
-- remaining segments are put on separate lines between the current and
-- next lines.
--
splitWord :: WordSplitter a c => a -> Int -> Int -> [c] -> Maybe [Int]
-- | Predicate for characters that should be treated as a part of a word.
isWordChar :: WordSplitter a c => a -> c -> Bool
-- | Predicate for detecting whitespace between words.
isWhitespace :: WordSplitter a c => a -> c -> Bool
-- | Append the canonical hyphen character to show word breaks.
appendHyphen :: WordSplitter a c => a -> [c] -> [c]
-- | Wrapping policy that breaks at exactly the viewer width.
breakExact :: BreakWords c
-- | Wrapping policy that breaks lines based on words.
breakWords :: (Show a, WordSplitter a c) => a -> BreakWords c
-- | Hyphenates words using simple aesthetics, without dictionary
-- awareness.
lazyHyphen :: (WordChar c, HyphenChar c) => LazyHyphen c
-- | The line is at the end of the paragraph.
lineBreakEnd :: LineBreak
-- | The line ends with a hyphenated word.
lineBreakHyphen :: LineBreak
-- | The line is nothing special.
lineBreakSimple :: LineBreak
-- | Avoids splitting words unless they are longer than a single line.
noHyphen :: WordChar c => NoHyphen c
instance GHC.Show.Show (WEditor.LineWrap.LazyHyphen c)
instance GHC.Show.Show (WEditor.LineWrap.NoHyphen c)
instance GHC.Show.Show (WEditor.LineWrap.NoSplit c)
instance GHC.Classes.Ord WEditor.LineWrap.LineBreak
instance GHC.Classes.Eq WEditor.LineWrap.LineBreak
instance (WEditor.Base.Char.WordChar c, WEditor.Base.Char.HyphenChar c) => WEditor.LineWrap.WordSplitter (WEditor.LineWrap.LazyHyphen c) c
instance WEditor.Base.Char.WordChar c => WEditor.LineWrap.WordSplitter (WEditor.LineWrap.NoHyphen c) c
instance GHC.Show.Show (WEditor.LineWrap.BreakWords c)
instance WEditor.Base.Parser.FixedFontParser (WEditor.LineWrap.BreakWords c) c
instance WEditor.LineWrap.WordSplitter (WEditor.LineWrap.NoSplit c) c
instance GHC.Show.Show WEditor.LineWrap.LineBreak