diff options
author | Kierán Meinhardt <kieran.meinhardt@gmail.com> | 2020-09-22 22:27:51 +0200 |
---|---|---|
committer | Kierán Meinhardt <kieran.meinhardt@gmail.com> | 2020-09-22 22:35:38 +0200 |
commit | c7fc18648a6fe295d14284cb491b9ea2d1a28cac (patch) | |
tree | 151294ba8d3432e5d6ec7b4fe54fdb0a353962a4 /config | |
parent | 8c288cf1f2747aa9f8cee68cc1b9a35dd02229b8 (diff) |
config: add kmein
Diffstat (limited to 'config')
-rw-r--r-- | config/kmein.hs | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/config/kmein.hs b/config/kmein.hs new file mode 100644 index 0000000..f5d9849 --- /dev/null +++ b/config/kmein.hs @@ -0,0 +1,106 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} + +module Main (main) where + +import Action +import Blessings.String +import Core +import Data.Maybe +import Scanner +import State +import Text.Hyphenation +import Text.LineBreak +import TreeView +import qualified Data.Tree as Tree +import qualified Data.Tree.Zipper as Z +import qualified Notmuch.Message as Notmuch + +main :: IO () +main = + mainWithState emptyState + { keymap = myKeymap + , mousemap = myMousemap + } + +myKeymap :: String -> State -> IO State +myKeymap "a" = toggleTagAtCursor "inbox" +myKeymap "s" = toggleTagAtCursor "unread" +myKeymap "&" = toggleTagAtCursor "killed" +myKeymap "*" = toggleTagAtCursor "star" +myKeymap "k" = moveCursorUp 1 +myKeymap "j" = moveCursorDown 1 +myKeymap "K" = moveTreeDown 1 +myKeymap "J" = moveTreeUp 1 +myKeymap "\ESC[A" = moveCursorUp 1 +myKeymap "\ESC[B" = moveCursorDown 1 +myKeymap "\ESC[a" = moveTreeDown 1 +myKeymap "\ESC[b" = moveTreeUp 1 +myKeymap "\ESC[c" = moveTreeLeft 1 -- S-Right +myKeymap "\ESC[d" = moveTreeRight 1 -- S-Left +myKeymap "\ESC[5~" = \q -> moveTreeDown (screenHeight q `div` 2) q -- PgUp +myKeymap "\ESC[6~" = \q -> moveTreeUp (screenHeight q `div` 2) q -- PgDn +myKeymap "\n" = toggleFold +myKeymap "\ESC[Z" = moveCursorUpToPrevUnread -- S-Tab +myKeymap "\t" = moveCursorDownToNextUnread +myKeymap "\DEL" = moveToParent -- backspace +myKeymap "=" = \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 + +-- <F1> +myKeymap "\ESC[11~" = \q@State{..} -> + return q { flashMessage = Plain $ show $ treeViewId $ Z.label cursor } + +-- <F2> +myKeymap "\ESC[12~" = \q@State{..} -> + return q { flashMessage = + Plain $ + show $ + maybe Nothing (Just . Notmuch.messageFilename) $ + getMessage $ + Z.label cursor + } + +-- TODO Stuff Vim sends after exit (also there is more...) +myKeymap "\ESC[2;2R" = \q -> return q { flashMessage = flashMessage q <> " " <> Plain "stupid" } +myKeymap "\ESC[>85;95;0c" = \q -> return q { flashMessage = flashMessage q <> " " <> Plain "stupid" } + +myKeymap s = displayKey s + + +myMousemap :: Scan -> State -> IO State +myMousemap ScanMouse{mouseButton=1,mouseY=y} = defaultMouse1Click y +myMousemap ScanMouse{mouseButton=3,mouseY=y} = \q -> defaultMouse1Click y q >>= toggleFold +myMousemap ScanMouse{mouseButton=4} = moveTreeDown 3 +myMousemap ScanMouse{mouseButton=5} = moveTreeUp 3 +myMousemap ScanMouse{mouseButton=0} = return +myMousemap info = displayMouse info |