diff options
author | Raúl Benencia <rul@kalgan.cc> | 2013-09-05 21:41:20 -0300 |
---|---|---|
committer | Raúl Benencia <rul@kalgan.cc> | 2013-09-05 21:41:20 -0300 |
commit | 7af6e583d7d6893f67745e23017eba436f8ed826 (patch) | |
tree | b65568d156cfc3c0319a43548b6c5b644c379d90 /src/Lazymail/Keymap.hs | |
parent | e3a455fc3791539275fdb6aff003ffa8460f8850 (diff) |
towards configurable keybindings
Diffstat (limited to 'src/Lazymail/Keymap.hs')
-rw-r--r-- | src/Lazymail/Keymap.hs | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/src/Lazymail/Keymap.hs b/src/Lazymail/Keymap.hs index 1cef1b1..27dce60 100644 --- a/src/Lazymail/Keymap.hs +++ b/src/Lazymail/Keymap.hs @@ -1,16 +1,48 @@ +{- Lazymail default keymap. + - + - Copyright 2013 Raúl Benencia <rul@kalgan.cc> + - + - Licensed under the GNU GPL version 3 or higher + -} + module Lazymail.Keymap ( defaultGlobalKeymap , defaultMaildirKeymap , defaultIndexKeymap , defaultEmailKeymap , defaultComposeKeymap + , findHandler ) where -import UI.NCurses(Event(..)) -import Lazymail.Types(LazymailCurses) +import UI.NCurses(Event(..), Key(..)) + +import Lazymail.Types(Keymap, LazymailState(..), Mode(..), LazymailConfig(..)) +import Lazymail.Handlers(advanceMode, previousMode, scrollUp, scrollDown) -defaultGlobalKeymap = [] +defaultGlobalKeymap = [ ([EventCharacter '\n', EventSpecialKey KeyRightArrow], advanceMode) + , ([EventCharacter 'q', EventCharacter 'Q'], previousMode) + , ([EventSpecialKey KeyUpArrow, EventCharacter 'k'], scrollUp) + , ([EventSpecialKey KeyDownArrow, EventCharacter 'j'], scrollDown) + ] defaultMaildirKeymap = [] -defaultIndexKeymap = [] -defaultEmailKeymap = [] -defaultComposeKeymap = []
\ No newline at end of file +defaultIndexKeymap = [] +defaultEmailKeymap = [] +defaultComposeKeymap = [] + +-- | Try to find a keymap for the current mode. If nothing is found, then +-- try looking up in the global keymap. +findHandler st cfg ev = case modeHandler (mode st) ev of + Nothing -> globalHandler ev + Just h -> Just h -- I think I saw a way of using an as-pattern in this case + where + modeHandler MaildirMode = lookupHandler $ maildirModeKeymap cfg + modeHandler IndexMode = lookupHandler $ indexModeKeymap cfg + modeHandler EmailMode = lookupHandler $ emailModeKeymap cfg + modeHandler ComposeMode = lookupHandler $ composeModeKeymap cfg + + globalHandler = lookupHandler $ globalKeymap cfg + + lookupHandler [] _ = Nothing + lookupHandler (km:kms) ev + | elem ev (fst km) = Just $ snd km + | otherwise = lookupHandler kms ev
\ No newline at end of file |