aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaúl Benencia <rul@kalgan.cc>2013-08-25 23:11:18 -0300
committerRaúl Benencia <rul@kalgan.cc>2013-08-25 23:11:18 -0300
commit133c0d7cbcc5dcca2214bf532dd47d1ad86a4a17 (patch)
tree3473df37b12952a685bdc350c582fc116752e6db
parent89cd31ce1275bee6c8da8b3d9f4b00155a2e5fd2 (diff)
scrolling functionality in Index mode
-rw-r--r--Config.hs3
-rw-r--r--Screen.hs52
-rw-r--r--State.hs6
3 files changed, 49 insertions, 12 deletions
diff --git a/Config.hs b/Config.hs
index 26c062d..34bd509 100644
--- a/Config.hs
+++ b/Config.hs
@@ -40,7 +40,6 @@ defaultConfig = LazymailConfig {
--
--customConfig = defaultConfig { initialPath = "/home/rul/mail/"}
-
customConfig = defaultConfig { initialPath = "/home/rul/mail/linti"
, maildirDrawHook = indentedShow
, filterMaildirsHook = filterSymlinks }
@@ -55,7 +54,7 @@ indentedShow bp md =
pad = " "
numPads = (length $ filter (== '/') str) + (length $ filter (`elem` imapSep) str)
imapSep = ['.'] -- IMAP usually separates its directories with dots
- in (concat $ replicate (numPads - 1) pad) ++ pad ++ name
+ in (concat $ replicate (numPads - 1) pad) ++ name
filterSymlinks :: [FilePath] -> IO [FilePath]
filterSymlinks [] = return []
diff --git a/Screen.hs b/Screen.hs
index c8ef25a..e5b97cf 100644
--- a/Screen.hs
+++ b/Screen.hs
@@ -77,12 +77,12 @@ performUpdate = do
liftUpdate $ clearMain (scrRowsAsInteger st) (screenColumns st)
drawMode (mode st)
drawStatus
- get >>= return
+ get
{- Pattern match on the received mode and draw it in the screen. -}
drawMode :: Mode -> LazymailUpdate ()
drawMode MaildirMode = get >>= \st -> drawMaildirHelper $ detectedMDs . maildirState $ st
-drawMode IndexMode = get >>= \st -> drawIndexHelper $ selectedEmails . indexState $ st
+drawMode IndexMode = get >>= \st -> drawIndexHelper $ scrollBufferIn . indexState $ st
drawMode EmailMode = drawEmailHelper
{- Helper function of drawMode -}
@@ -132,7 +132,7 @@ drawIndexHelper ((fp, _, msg):ts) = do
let email = parseEmail msg
let fs = getFields email
let str = normalizeLen (screenColumns st) . concat $
- [ show $ (currentRow st) + 1
+ [ show $ (currentRow st) + (scrollRowIn . indexState $ st) + 1
, (ppSep ++) $ ppFlags . getFlags $ fp
, (ppSep ++) $ ppIndexNameAddr . getFrom $ fs
, (ppSep ++) $ ppIndexSubject . getSubject $ fs
@@ -204,8 +204,8 @@ drawStatusHelper MaildirMode st = ["Maildir listing - "
, show (length $ detectedMDs . maildirState $ st), ")"]
drawStatusHelper IndexMode st = ["mode: Index - "
- , "(", show ((+ 1) . selectedRow $ st), "/"
- , show (length $ selectedEmails . indexState $ st), ")"]
+ , "(", show ((selectedRow st) + (scrollRowIn . indexState $ st) + 1), "/"
+ , show (currentInLen . indexState $ st), ")"]
drawStatusHelper EmailMode st = ["mode: Email"]
@@ -226,11 +226,11 @@ handleEvent = loop where
EmailMode -> put $ st { mode = IndexMode }
MaildirMode -> put $ st { exitRequested = True }
- EventSpecialKey KeyUpArrow -> put $ decrementSelectedRow st
- EventCharacter 'k' -> put $ decrementSelectedRow st
+ EventSpecialKey KeyUpArrow -> decrementActions (mode st)
+ EventCharacter 'k' -> decrementActions (mode st)
- EventSpecialKey KeyDownArrow -> put $ incrementSelectedRow st
- EventCharacter 'j' -> put $ incrementSelectedRow st
+ EventSpecialKey KeyDownArrow -> incrementActions (mode st)
+ EventCharacter 'j' -> incrementActions (mode st)
EventSpecialKey KeyRightArrow -> do
case (mode st) of
@@ -240,10 +240,42 @@ handleEvent = loop where
selectedEmails' <- liftIO $ do
let md = (selectedMD . maildirState) $ st
getAll md
- let indexState' = (indexState st) { selectedEmails = selectedEmails' }
+ let indexState' = (indexState st) { selectedEmails = selectedEmails'
+ , currentInLen = length selectedEmails'
+ , scrollBufferIn = scrollCrop (scrollRowIn . indexState $ st) (screenRows st) selectedEmails'
+ }
put $ st { mode = IndexMode, indexState = indexState' }
_ -> loop
+{- 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
+
+incrementActions 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
+incrementActions _ = (=<<) put $ get >>= \st -> return $ incrementSelectedRow st
+
+decrementActions 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
+decrementActions _ = (=<<) put $ get >>= \st -> return $ decrementSelectedRow st
+
resetCurrentRow = (=<<) put $ get >>= \st -> return $ st { currentRow = 0 }
incrementCurrentRow = (=<<) put $ get >>= \st -> return $ st { currentRow = (currentRow st) + 1 }
+
diff --git a/State.hs b/State.hs
index 57b6258..a3fbef0 100644
--- a/State.hs
+++ b/State.hs
@@ -40,6 +40,9 @@ data IndexState = IndexState {
selectedRowIn :: Int
, selectedEmail :: Message
, selectedEmails :: [(String, [Flag], String)]
+ , scrollRowIn :: Int
+ , currentInLen :: Int
+ , scrollBufferIn :: [(String, [Flag], String)]
}
data ComposeState = ComposeState {
@@ -77,6 +80,9 @@ initialIndexState = IndexState {
selectedRowIn = 0
, selectedEmail = Message [] "Dummy email"
, selectedEmails = []
+ , scrollRowIn = 0
+ , currentInLen = 0
+ , scrollBufferIn = []
}
initialComposeState = ComposeState {
nihil fit ex nihilo