From f25d0d8d82dff0be2d68476148479004b2888bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Sun, 25 Aug 2013 17:56:39 -0300 Subject: Finished porting to state monad --- State.hs | 84 ++++++++++++++++++++++++---------------------------------------- 1 file changed, 31 insertions(+), 53 deletions(-) (limited to 'State.hs') diff --git a/State.hs b/State.hs index f4ac3d8..7ff8359 100644 --- a/State.hs +++ b/State.hs @@ -95,64 +95,42 @@ curRowAsInteger st = toInteger $ currentRow st colPadAsInteger st = toInteger $ columnPadding st - -{- data MState = MState { - selectedRowMD :: Integer -- Selected row in MaildirMode - , selectedRowIn :: Integer -- Selected row in IndexMode - , mode :: Mode - , initPath :: String - , scrRows :: Integer - , scrColumns :: Integer - , curRow :: Integer - , colPadding :: Integer - , selectedColorID :: ColorID - , statusColorID :: ColorID - , selectedEmail :: Message - , selectedEmails :: [(String, [Flag], String)] - , selectedMD :: String - , detectedMDs :: [String] - , exitRequested :: Bool - , showStatus :: Bool -} - -initState = MState { - selectedRowMD = 0 - , selectedRowIn = 0 - , mode = MaildirMode - , initPath = "" - , scrRows = (-1) - , scrColumns = (-1) - , curRow = 0 - , colPadding = 0 - , selectedColorID = defaultColorID - , statusColorID = defaultColorID - , selectedEmail = Message [] "Dummy email" - , selectedEmails = [] - , selectedMD = "" - , detectedMDs = [] - , exitRequested = False - , showStatus = True -} - -incCurRow st = st { curRow = (curRow st) + 1 } - -incSelectedRow st | (selectedRow st) < limit = case (mode st) of - MaildirMode -> st { selectedRowMD = (selectedRowMD st) + 1 } - IndexMode -> st { selectedRowIn = (selectedRowIn st) + 1 } - | otherwise = st +incrementSelectedRow st | (selectedRow st) < limit = case (mode st) of + MaildirMode -> + let + sr = (selectedRowMD . maildirState) st + maildirState' = (maildirState st) { selectedRowMD = sr + 1 } + in + st { maildirState = maildirState' } + IndexMode -> + let + sr = (selectedRowIn . indexState) st + indexState' = (indexState st) { selectedRowIn = sr + 1 } + in + st { indexState = indexState' } + | otherwise = st where limit' = case (mode st) of - MaildirMode -> (length $ detectedMDs st ) - 1 - IndexMode -> (length $ selectedEmails st) - 1 - limit = if (showStatus st) && (limit' == scrRowsAsInt st) + MaildirMode -> (length $ detectedMDs . maildirState $ st ) - 1 + IndexMode -> (length $ selectedEmails . indexState $ st) - 1 + limit = if (statusBar st) && (limit' == screenRows st) then fromIntegral $ limit' - 2 else fromIntegral limit' -decSelectedRow st | (selectedRow st) > 0 = case (mode st) of - MaildirMode -> st { selectedRowMD = (selectedRowMD st) - 1 } - IndexMode -> st { selectedRowIn = (selectedRowIn st) - 1 } - | otherwise = st --} +decrementSelectedRow st | (selectedRow st) > 0 = case (mode st) of + MaildirMode -> + let + sr = (selectedRowMD . maildirState) st + maildirState' = (maildirState st) { selectedRowMD = sr - 1 } + in + st { maildirState = maildirState' } + IndexMode -> + let + sr = (selectedRowIn . indexState) st + indexState' = (indexState st) { selectedRowIn = sr - 1 } + in + st { indexState = indexState' } + | otherwise = st selectedRow st = case (mode st) of MaildirMode -> selectedRowMD . maildirState $ st -- cgit v1.2.3