From 77112dd4cd7657ebf16734d117d42283ee34c742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Tue, 27 Aug 2013 23:34:10 -0300 Subject: Scrolling working in Maildir mode --- Handlers.hs | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'Handlers.hs') 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 ] -- cgit v1.2.3