From 92babe5d4ea236599f405380a8061ef21d69634e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Wed, 21 Aug 2013 22:44:06 -0300 Subject: Semi-functional core --- State.hs | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'State.hs') diff --git a/State.hs b/State.hs index 3826bfc..76f200e 100644 --- a/State.hs +++ b/State.hs @@ -27,7 +27,8 @@ import Network.Email.Mailbox(Flag(..), Flags) data Mode = MaildirMode | IndexMode | EmailMode data MState = MState { - selectedRow :: Integer + selectedRowMD :: Integer -- Selected row in MaildirMode + , selectedRowIn :: Integer -- Selected row in IndexMode , mode :: Mode , initPath :: String , scrRows :: Integer @@ -35,15 +36,18 @@ data MState = MState { , curRow :: Integer , colPadding :: Integer , selectedColorID :: ColorID + , statusColorID :: ColorID , selectedEmail :: Message , selectedEmails :: [(String, [Flag], String)] , selectedMD :: String , detectedMDs :: [String] - , exitRequested :: Bool + , exitRequested :: Bool + , showStatus :: Bool } initState = MState { - selectedRow = 0 + selectedRowMD = 0 + , selectedRowIn = 0 , mode = MaildirMode , initPath = "" , scrRows = (-1) @@ -51,22 +55,37 @@ initState = MState { , curRow = 0 , colPadding = 0 , selectedColorID = defaultColorID + , statusColorID = defaultColorID , selectedEmail = Message [] "Dummy email" , selectedEmails = [] , selectedMD = "" , detectedMDs = [] - , exitRequested = False + , exitRequested = False + , showStatus = True } incCurRow st = st { curRow = (curRow st) + 1 } -incSelectedRow st | selectedRow st < fromIntegral limit = st { selectedRow = (selectedRow st) + 1 } - | otherwise = st +incSelectedRow st | (selectedRow st) < limit = case (mode st) of + MaildirMode -> st { selectedRowMD = (selectedRowMD st) + 1 } + IndexMode -> st { selectedRowIn = (selectedRowIn st) + 1 } + | otherwise = st where - limit = case (mode st) of + limit' = case (mode st) of MaildirMode -> (length $ detectedMDs st ) - 1 IndexMode -> (length $ selectedEmails st) - 1 - _ -> fromIntegral $ scrRows st + limit = if (showStatus st) && (limit' == scrRowsAsInt st) + then fromIntegral $ limit' - 2 + else fromIntegral limit' -decSelectedRow st | selectedRow st > 0 = st { selectedRow = (selectedRow st) - 1 } - | otherwise = st \ No newline at end of file +decSelectedRow st | (selectedRow st) > 0 = case (mode st) of + MaildirMode -> st { selectedRowMD = (selectedRowMD st) - 1 } + IndexMode -> st { selectedRowIn = (selectedRowIn st) - 1 } + | otherwise = st + +selectedRow st = case (mode st) of + MaildirMode -> selectedRowMD st + IndexMode -> selectedRowIn st + +scrColsAsInt st = fromIntegral $ scrColumns st +scrRowsAsInt st = fromIntegral $ scrRows st \ No newline at end of file -- cgit v1.2.3