-- 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 text-editor
-- widgets.
--
-- The goal is to provide:
--
--
-- - Automatic management of a dynamically-sized viewable area, with
-- preservation of the cursor position and minimal view disruption during
-- resizing.
-- - Customizable line-wrapping policies and word-hyphenation
-- policies.
-- - Support for user-defined character types.
--
--
-- Also see WEditorHyphen for language-specific
-- hyphenation rules.
@package WEditor
@version 0.2.1.1
-- | Features of character sets.
module WEditor.Base.Char
-- | Supporting hyphenation.
class HyphenChar c
-- | The canonical hyphen character.
defaultHyphen :: HyphenChar c => c
isDefaultHyphen :: HyphenChar c => c -> Bool
-- | 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 e. FixedFontEditor e c => e -> e
-- | 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.
--
--
-- - e: Editor type providing the operations.
-- - c: Character type.
--
class FixedFontEditor e c | e -> c
-- | Apply an edit action.
editText :: FixedFontEditor e c => e -> EditAction c -> EditDirection -> e
-- | Break the current paragraph at the cursor.
breakPara :: FixedFontEditor e c => e -> EditDirection -> e
-- | Apply e cursor movement.
moveCursor :: FixedFontEditor e c => e -> MoveDirection -> e
-- | Get the (col,row) cursor position relative to the viewport.
getCursor :: FixedFontEditor e c => e -> (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 e c => e -> (Int, Int)
-- | Set the absolute (paragraph,char) edit position.
setEditPoint :: FixedFontEditor e c => e -> (Int, Int) -> e
-- | Get the number of characters in the current paragraph.
getParaSize :: FixedFontEditor e c => e -> Int
-- | Get the number of paragraphs in the document.
getParaCount :: FixedFontEditor e c => e -> Int
-- | Export the modified data.
exportData :: FixedFontEditor e c => e -> [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.
--
--
-- - p: Parser type providing the operations.
-- - c: Character type.
--
class FixedFontParser p c | p -> c where {
-- | Type used to differentiate between line-break types.
type family BreakType p :: *;
}
-- | Change the max line width used for parsing. A width of zero must
-- result in breakLines skipping line breaks.
setLineWidth :: FixedFontParser p c => p -> Int -> p
-- | Break the sequence into lines.
--
-- The following must hold for all possible inputs to a
-- FixedFontParser p:
--
--
-- concat (map vlText (breakLines p l)) == l
--
--
-- Implement renderLine and tweakCursor to make visual
-- adjustments (such as adding hyphens or indentation) if necessary.
breakLines :: FixedFontParser p c => p -> [c] -> [VisibleLine c (BreakType p)]
-- | A place-holder line for empty paragraphs.
emptyLine :: FixedFontParser p c => p -> VisibleLine c (BreakType p)
-- | Render the line for viewing. Implement tweakCursor if
-- renderLine changes the positions of any characters on the line.
renderLine :: FixedFontParser p c => p -> VisibleLine c (BreakType p) -> [c]
-- | Adjust the horizontal cursor position.
tweakCursor :: FixedFontParser p c => p -> VisibleLine c (BreakType p) -> Int -> Int
-- | Split the line to create a paragraph break.
--
-- The following must hold for all possible inputs to a
-- FixedFontParser p:
--
--
-- let (b,t) = splitLine p n l in vlText l == vlText b ++ vlText t
--
splitLine :: FixedFontParser p c => p -> Int -> VisibleLine c (BreakType p) -> (VisibleLine c (BreakType p), VisibleLine c (BreakType p))
-- | Generic editor-viewport functionality.
module WEditor.Base.Viewer
-- | Generic editor viewport for fixed-width fonts.
--
--
-- - v: Viewer type providing the operations.
-- - c: Character type.
--
class FixedFontViewer v c | v -> c
-- | Set the (width,height) size of the viewport. Setting either
-- to <=0 disables bounding in that dimension.
setViewSize :: FixedFontViewer v c => v -> (Int, Int) -> v
-- | Get the (width,height) size of the viewport.
getViewSize :: FixedFontViewer v c => v -> (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 v c => v -> [[c]]
-- | Apply a view change.
updateView :: FixedFontViewer v c => v -> ViewAction -> v
-- | 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 v. FixedFontViewer v c => v -> v
-- | Action to attempt to fill the viewport.
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 e. FixedFontEditor e c => e -> e
-- | Generic text editor for fixed-width fonts.
--
--
-- - e: Editor type providing the operations.
-- - c: Character type.
--
class FixedFontEditor e c | e -> c
-- | Apply an edit action.
editText :: FixedFontEditor e c => e -> EditAction c -> EditDirection -> e
-- | Break the current paragraph at the cursor.
breakPara :: FixedFontEditor e c => e -> EditDirection -> e
-- | Apply e cursor movement.
moveCursor :: FixedFontEditor e c => e -> MoveDirection -> e
-- | Get the (col,row) cursor position relative to the viewport.
getCursor :: FixedFontEditor e c => e -> (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 e c => e -> (Int, Int)
-- | Set the absolute (paragraph,char) edit position.
setEditPoint :: FixedFontEditor e c => e -> (Int, Int) -> e
-- | Get the number of characters in the current paragraph.
getParaSize :: FixedFontEditor e c => e -> Int
-- | Get the number of paragraphs in the document.
getParaCount :: FixedFontEditor e c => e -> Int
-- | Export the modified data.
exportData :: FixedFontEditor e c => e -> [UnparsedPara c]
-- | Line parser for fixed-width fonts.
--
--
-- - p: Parser type providing the operations.
-- - c: Character type.
--
class FixedFontParser p c | p -> c
-- | Generic editor viewport for fixed-width fonts.
--
--
-- - v: Viewer type providing the operations.
-- - c: Character type.
--
class FixedFontViewer v c | v -> c
-- | Set the (width,height) size of the viewport. Setting either
-- to <=0 disables bounding in that dimension.
setViewSize :: FixedFontViewer v c => v -> (Int, Int) -> v
-- | Get the (width,height) size of the viewport.
getViewSize :: FixedFontViewer v c => v -> (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 v c => v -> [[c]]
-- | Apply a view change.
updateView :: FixedFontViewer v c => v -> ViewAction -> v
-- | 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 v. FixedFontViewer v c => v -> v
-- | 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
-- | Action to attempt to fill the viewport.
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.
--
--
-- - s: Splitter type providing the operations.
-- - c: Character type.
--
class WordSplitter s c | s -> 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 s c => s -> Int -> Int -> [c] -> Maybe [Int]
-- | Predicate for characters that should be treated as a part of a word.
isWordChar :: WordSplitter s c => s -> c -> Bool
-- | Predicate for detecting whitespace between words.
isWhitespace :: WordSplitter s c => s -> c -> Bool
-- | Append the canonical hyphen character to show word breaks.
appendHyphen :: WordSplitter s c => s -> [c] -> [c]
-- | Check the word segment for an existing hyphenation.
endsWithHyphen :: WordSplitter s c => s -> [c] -> Bool
-- | Wrapping policy that breaks at exactly the viewer width.
breakExact :: BreakWords c
-- | Wrapping policy that breaks lines based on words.
breakWords :: (Show s, WordSplitter s c) => s -> 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