diff options
author | Raúl Benencia <rul@kalgan.cc> | 2013-08-27 23:34:10 -0300 |
---|---|---|
committer | Raúl Benencia <rul@kalgan.cc> | 2013-08-27 23:34:10 -0300 |
commit | 77112dd4cd7657ebf16734d117d42283ee34c742 (patch) | |
tree | a180f9d9635ced5071d5e32557dfb13b5ad49541 /Handlers.hs | |
parent | 496546229d1b5060c88266210f303a48280c885c (diff) |
Scrolling working in Maildir mode
Diffstat (limited to 'Handlers.hs')
-rw-r--r-- | Handlers.hs | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/Handlers.hs b/Handlers.hs index 007933d..4605756 100644 --- a/Handlers.hs +++ b/Handlers.hs @@ -19,9 +19,12 @@ import System.IO(IOMode(..), hGetContents, openFile) 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 } +previousMode EmailMode = (=<<) put $ get >>= \st -> return st { mode = IndexMode } +previousMode IndexMode = do + st <- get + let ist = (indexState st) { selectedRowIn = 0, scrollRowIn = 0 } + put $ st { mode = MaildirMode, indexState = ist } changeMode :: Mode -> LazymailCurses () changeMode EmailMode = return () @@ -44,6 +47,7 @@ changeMode MaildirMode = do } put $ st { mode = IndexMode, indexState = indexState' } +{- Boilerplate code -} incSelectedRow IndexMode = do st <- get let inSt = indexState st @@ -60,9 +64,27 @@ incSelectedRow IndexMode = do put st { indexState = inSt' } else -- Move the selected row put $ incrementSelectedRow st + +incSelectedRow MaildirMode = do + st <- get + let mdSt = maildirState st + let selRow = selectedRowMD mdSt + let topScrollRow = scrollRowMD mdSt + let startScrolling = (div (screenRows st) 4) * 3 + let totalRows = length $ detectedMDs mdSt + + if selRow > startScrolling && (topScrollRow <= (totalRows - (screenRows st))) + then do -- Scroll emails + let scrollRowMD' = topScrollRow + 1 + let scrollBufferMD' = scrollCrop scrollRowMD' (screenRows st) $ detectedMDs mdSt + let mdSt' = mdSt { scrollRowMD = scrollRowMD', scrollBufferMD = scrollBufferMD' } + put st { maildirState = mdSt' } + else -- Move the selected row + put $ incrementSelectedRow st incSelectedRow _ = (=<<) put $ get >>= \st -> return $ incrementSelectedRow st +{- More boilerplate code -} decSelectedRow IndexMode = do st <- get let inSt = indexState st @@ -77,6 +99,22 @@ decSelectedRow IndexMode = do put st { indexState = inSt' } else put $ decrementSelectedRow st + +decSelectedRow MaildirMode = do + st <- get + let mdSt = maildirState st + let selRow = selectedRowMD mdSt + let startScrolling = (div (screenRows st) 4) + let topScrollRow = scrollRowMD mdSt + if topScrollRow > 0 && selRow < startScrolling + then do + let scrollRowMD' = scrollRowMD mdSt - 1 + let scrollBufferMD' = scrollCrop scrollRowMD' (screenRows st) $ detectedMDs mdSt + let mdSt' = mdSt { scrollRowMD = scrollRowMD', scrollBufferMD = scrollBufferMD' } + put st { maildirState = mdSt' } + 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 @@ -89,8 +127,7 @@ formatIndexModeRows st = mapM formatRow where let email = parseEmail msg let fs = getFields email let str = normalizeLen (screenColumns st) . concat $ - [ show $ (currentRow st) + (scrollRowIn . indexState $ st) + 1 - , (ppSep ++) $ ppFlags . getFlags $ fp + [ (ppSep ++) $ ppFlags . getFlags $ fp , (ppSep ++) $ ppIndexNameAddr . getFrom $ fs , (ppSep ++) $ ppIndexSubject . getSubject $ fs ] |