From d42e50abac78352cee37df0c42b967aff9d68f7c Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 5 Mar 2015 15:40:39 +0100 Subject: test5: wrap lines with '=' --- test5.hs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'test5.hs') diff --git a/test5.hs b/test5.hs index 7d9c3f4..500b1c2 100644 --- a/test5.hs +++ b/test5.hs @@ -40,6 +40,8 @@ import System.Posix.Files import System.Posix.Signals import System.Process import TagUtils +import Text.Hyphenation +import Text.LineBreak import Trammel import TreeSearch import TreeView @@ -264,6 +266,38 @@ keymap "\ESC[Z" = moveCursorUpToPrevUnread -- S-Tab keymap "\t" = moveCursorDownToNextUnread keymap "\DEL" = moveToParent -- backspace +-- TODO wrap/unwrap to separate module +keymap "=" = \q@State{..} -> + let cursor' = case Z.label cursor of + TVMessageLine a b c s -> + wrap (TVMessageLine a b c) cursor s + _ -> cursor + in return q { cursor = cursor' } + where + + --unwrap = error "WIP" + -- 1. get current id (must be TVMessageLine) + -- 2. find first adjoined TVMessageLine with same id + -- 3. find last adjoined TVMessageLine with same id + -- 4. join lines (with space?) + + wrap ctor loc s = + fromMaybe (error "die hard") $ + Z.nextTree $ + foldr (insert . ctor) + (Z.delete loc) + $ hy s + + insert a = + Z.prevSpace . Z.insert (Tree.Node a []) + + hy s = + breakStringLn bf s + where + shy = '\173' + hyp = Just german_1996 + bf = BreakFormat 80 8 shy hyp + keymap "\ESCq" = \q@State{..} -> let parse = filter (/='\n') -- TODO proper parse draft = fromMaybe "" $ getSearchTerm $ Z.label $ Z.root cursor -- cgit v1.2.3