From 6532d2b357160fe6a41ac4ec3aeb1283027d116e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Thu, 29 Aug 2013 23:03:58 -0300 Subject: Filled email state --- Handlers.hs | 30 +++++++++++++++++------------- Screen.hs | 6 +++--- State.hs | 4 ++-- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Handlers.hs b/Handlers.hs index 3d0b787..e01d51a 100644 --- a/Handlers.hs +++ b/Handlers.hs @@ -11,7 +11,7 @@ import Control.Monad.State import Data.List(stripPrefix) import System.FilePath(FilePath, takeFileName, dropTrailingPathSeparator) -import Email(parseEmail, getFields, getSubject, getFrom) +import Email(parseEmail, getFields, getSubject, getFrom, getBody, formatBody) import Maildir import Print import State @@ -23,7 +23,7 @@ previousMode MaildirMode = (=<<) put $ get >>= \st -> return st { exitRequested previousMode EmailMode = (=<<) put $ get >>= \st -> return st { mode = IndexMode } previousMode IndexMode = do st <- get - let ist = (indexState st) { selectedRowIn = 0, scrollRowIn = 0 } + let ist = (indexState st) { selectedRowIn = 0, scrollRowIn = 0 } put $ st { mode = MaildirMode, indexState = ist } changeMode :: Mode -> LazymailCurses () @@ -31,9 +31,13 @@ changeMode EmailMode = return () changeMode IndexMode = do st <- get msg <- liftIO $ UTF8.readFile . selectedEmailPath . indexState $ st - let ist = (indexState st) { selectedEmail = (parseEmail msg) } - put $ st { mode = EmailMode, indexState = ist } - + let email = parseEmail msg + let body = getBody $ email + let el = formatBody body $ screenColumns st + let sbe = scrollCrop 0 (screenRows st) el + let est = (emailState st) { currentEmail = email, emailLines = el, scrollBufferEm = sbe } + put $ st { mode = EmailMode, emailState = est } + changeMode MaildirMode = do st <- get selectedEmails' <- liftIO $ do @@ -64,7 +68,7 @@ incSelectedRow IndexMode = do put st { indexState = inSt' } else -- Move the selected row put $ incrementSelectedRow st - + incSelectedRow MaildirMode = do st <- get let mdSt = maildirState st @@ -88,9 +92,9 @@ incSelectedRow _ = (=<<) put $ get >>= \st -> return $ incrementSelectedRow st decSelectedRow IndexMode = do st <- get let inSt = indexState st - let selRow = selectedRowIn inSt + let selRow = selectedRowIn inSt let startScrolling = (div (screenRows st) 4) - let topScrollRow = scrollRowIn inSt + let topScrollRow = scrollRowIn inSt if topScrollRow > 0 && selRow < startScrolling then do let scrollRowIn' = scrollRowIn inSt - 1 @@ -99,13 +103,13 @@ 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 selRow = selectedRowMD mdSt let startScrolling = (div (screenRows st) 4) - let topScrollRow = scrollRowMD mdSt + let topScrollRow = scrollRowMD mdSt if topScrollRow > 0 && selRow < startScrolling then do let scrollRowMD' = scrollRowMD mdSt - 1 @@ -114,7 +118,7 @@ decSelectedRow MaildirMode = do 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 @@ -132,7 +136,7 @@ formatIndexModeRows st = mapM formatRow where , (ppSep ++) $ ppIndexSubject . getSubject $ fs ] return (fp, str) - + formatMaildirModeRows st = mapM formatRow where formatRow fp = return $ (fp, (concat $ replicate (numPads - 1) pad) ++ name) where bp = basePath st diff --git a/Screen.hs b/Screen.hs index c2da7ac..26c5d9b 100644 --- a/Screen.hs +++ b/Screen.hs @@ -75,7 +75,7 @@ screenLoop = do then screenLoop else return () -{- Perform the screen for the next update. A clean is made -} +{- Perform the screen update, by cleaning it first. -} performUpdate :: LazymailUpdate LazymailState performUpdate = do st <- get @@ -137,7 +137,7 @@ drawEmailHelper = do drawEmailHeader st <- get - let body = getBody $ selectedEmail . indexState $ st + let body = getBody $ currentEmail . emailState $ st let maxRows = if statusBar st then (scrRowsAsInteger st) - 1 else scrRowsAsInteger st let emailLines = formatBody body $ (screenColumns st) - 1 liftUpdate $ drawBody ((curRowAsInteger st) + 4) (colPadAsInteger st) maxRows emailLines @@ -146,7 +146,7 @@ drawEmailHelper = do drawEmailHeader = do st <- get liftUpdate $ do - let fs = getFields $ selectedEmail . indexState $ st + let fs = getFields $ currentEmail . emailState $ st let cropWith xs = normalizeLen $ (screenColumns st) - (length xs) let row = curRowAsInteger st setColor $ headerColorID . colorStyle $ st diff --git a/State.hs b/State.hs index e7f551e..b6561ff 100644 --- a/State.hs +++ b/State.hs @@ -41,7 +41,6 @@ data MaildirState = MaildirState { data IndexState = IndexState { selectedRowIn :: Int - , selectedEmail :: Message , selectedEmailPath :: FilePath , selectedEmails :: [(FilePath, String)] , scrollRowIn :: Int @@ -57,6 +56,7 @@ data EmailState = EmailState { scrollBufferEm :: [String] , scrollRowEm :: Int , emailLines :: [String] + , currentEmail :: Message } data ColorStyle = ColorStyle { @@ -92,7 +92,6 @@ initialMaildirState = MaildirState { initialIndexState = IndexState { selectedRowIn = 0 - , selectedEmail = Message [] "Dummy email" , selectedEmailPath = "" , selectedEmails = [] , scrollRowIn = 0 @@ -104,6 +103,7 @@ initialEmailState = EmailState { scrollBufferEm = [] , scrollRowEm = 0 , emailLines = [] + , currentEmail = Message [] "Dummy email" } initialComposeState = ComposeState { -- cgit v1.2.3