diff options
author | Raúl Benencia <rul@kalgan.cc> | 2013-08-26 13:44:44 -0300 |
---|---|---|
committer | Raúl Benencia <rul@kalgan.cc> | 2013-08-26 13:44:44 -0300 |
commit | 05d6b5f93cd1ed5e9c4f4f9d63cf392ada048afb (patch) | |
tree | dce051108263fee85f46c804be04d8c9ebfb7c83 /Handlers.hs | |
parent | 133c0d7cbcc5dcca2214bf532dd47d1ad86a4a17 (diff) |
towards lazy reading (broken)
Diffstat (limited to 'Handlers.hs')
-rw-r--r-- | Handlers.hs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Handlers.hs b/Handlers.hs new file mode 100644 index 0000000..566fca9 --- /dev/null +++ b/Handlers.hs @@ -0,0 +1,61 @@ +{- Event handlers for Lazymail + - + - Copyright 2013 Raúl Benencia <rul@kalgan.cc> + - + - Licensed under the GNU GPL version 3 or higher + -} + +module Handlers where + +import Control.Monad.State + +import Maildir +import State +import Types (LazymailCurses) + +previousMode :: Mode -> LazymailCurses () +previousMode IndexMode = (=<<) put $ get >>= \st -> return st { mode = MaildirMode } +previousMode EmailMode = (=<<) put $ get >>= \st -> return st { mode = IndexMode } +previousMode MaildirMode = (=<<) put $ get >>= \st -> return st { exitRequested = True } + +changeMode IndexMode = (=<<) put $ get >>= \st -> return st { mode = EmailMode } +changeMode EmailMode = return () +changeMode MaildirMode = do + st <- get + selectedEmails' <- liftIO $ do + let md = (selectedMD . maildirState) $ st + getMaildirEmails md + let indexState' = (indexState st) { + selectedEmails = selectedEmails' + , currentInLen = length selectedEmails' + , scrollBufferIn = scrollCrop (scrollRowIn . indexState $ st) (screenRows st) selectedEmails' + } + put $ st { mode = IndexMode, indexState = indexState' } + +incSelectedRow IndexMode = do + st <- get + let inSt = indexState st + if (selectedRowIn inSt) > (div (screenRows st) 2) + then do + let scrollRowIn' = scrollRowIn inSt + 1 + let scrollBufferIn' = scrollCrop scrollRowIn' (screenRows st) $ selectedEmails inSt + let inSt' = inSt { scrollRowIn = scrollRowIn', scrollBufferIn = scrollBufferIn' } + put st { indexState = inSt' } + else put $ incrementSelectedRow st +incSelectedRow _ = (=<<) put $ get >>= \st -> return $ incrementSelectedRow st + +decSelectedRow IndexMode = do + st <- get + let inSt = indexState st + if (scrollRowIn inSt) > 0 + then do + let scrollRowIn' = scrollRowIn inSt - 1 + let scrollBufferIn' = scrollCrop scrollRowIn' (screenRows st) $ selectedEmails inSt + let inSt' = inSt { scrollRowIn = scrollRowIn', scrollBufferIn = scrollBufferIn' } + put st { indexState = inSt' } + else put $ decrementSelectedRow st +decSelectedRow _ = (=<<) put $ get >>= \st -> return $ decrementSelectedRow st + +{- Given a list, it returns the elements that will be in the next screen refresh + - TODO: find a better name -} +scrollCrop top rows xs = take rows $ drop top xs |