From 4728bb04b2f5daff7a2ed8c30dd0fd8a8ee9539b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Sat, 24 Aug 2013 17:12:14 -0300 Subject: Advancing with monad transformers --- Config.hs | 6 +++--- Screen.hs | 53 +++++++++++++++++++++++++++++++++++------------------ State.hs | 54 ++++++++++++++++++++++++++++++++++++------------------ 3 files changed, 74 insertions(+), 39 deletions(-) diff --git a/Config.hs b/Config.hs index bf35cb1..d57983e 100644 --- a/Config.hs +++ b/Config.hs @@ -16,7 +16,7 @@ data LazymailConfig = LazymailConfig { , selectionColor :: (Color, Color) , statusBarColor :: (Color, Color) , showStatusBar :: Bool - , basePath :: Maybe FilePath + , initialPath :: Maybe FilePath } defaultConfig = LazymailConfig { @@ -24,7 +24,7 @@ defaultConfig = LazymailConfig { , selectionColor = (ColorBlack, ColorWhite) , statusBarColor = (ColorBlack, ColorWhite) , showStatusBar = True - , basePath = Nothing + , initialPath = Nothing } -- @@ -32,4 +32,4 @@ defaultConfig = LazymailConfig { -- preferences. In a possible future maybe I'll work in a not-so-crappy -- config system. -- -customConfig = defaultConfig { basePath = Just "/home/rul/mail/kalgan" } \ No newline at end of file +customConfig = defaultConfig { initialPath = Just "/home/rul/mail/kalgan" } \ No newline at end of file diff --git a/Screen.hs b/Screen.hs index df6ed92..22587cb 100644 --- a/Screen.hs +++ b/Screen.hs @@ -1,35 +1,50 @@ --- This module is part of Lazymail, a Haskell email client. --- --- Copyright (C) 2013 Raúl Benencia --- --- This program is free software: you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation, either version 3 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program. If not, see . +{- Lazymail interaction with curses. + - + - Copyright 2013 Raúl Benencia + - + - Licensed under the GNU GPL version 3 or higher + - + -} module Screen where import Control.Monad.Trans(liftIO) +import Control.Monad.Reader +import Control.Monad.State import Data.List(isPrefixOf) -import UI.NCurses +import UI.NCurses as UI import Text.ParserCombinators.Parsec.Rfc2822(Message(..)) -- Local imports +import Config +import Lazymail import Maildir import Email import Print import Rfc1342 import State --- | Main entry point +type LazymailCurses = ReaderT LazymailConfig (StateT LazymailState Curses) +liftCurses = lift . lift + +entryPoint :: Lazymail () +entryPoint = do + st <- get + cfg <- ask + maildirs <- liftIO $ getMaildirsRecursively $ basePath st + liftIO $ runCurses $ runStateT (runReaderT startCurses cfg) st + return () + +startCurses :: LazymailCurses () +startCurses = do + st <- get + (rows, columns) <- liftCurses $ do + UI.setEcho False + UI.screenSize + + return () + +{-- | Main entry point entryPoint :: MState -> IO () entryPoint st' = do maildirs <- getMaildirsRecursively (initPath st') @@ -203,3 +218,5 @@ handleEvent st = loop where return $ st { mode = IndexMode, selectedEmails = selEmails } _ -> loop + +-} \ No newline at end of file diff --git a/State.hs b/State.hs index 471ec1b..cb5e426 100644 --- a/State.hs +++ b/State.hs @@ -3,7 +3,7 @@ - Copyright 2013 Raúl Benencia - - Licensed under the GNU GPL version 3 or higher - - + - -} module State where @@ -11,20 +11,23 @@ module State where import Text.ParserCombinators.Parsec.Rfc2822(Message, GenericMessage(..)) import UI.NCurses(ColorID(..), defaultColorID) import Network.Email.Mailbox(Flag(..), Flags) +import System.FilePath data Mode = MaildirMode | IndexMode | EmailMode | ComposeMode data LazymailState = LazymailState { mode :: Mode + , basePath :: FilePath , screenRows :: Int , screenColumns :: Int , currentRow :: Int - , columnPadding :: Int + , columnPadding :: Int , exitRequested :: Bool - , statusBar :: Bool - , maildirState :: MaildirState - , indexState :: IndexState - , composeState :: ComposeState + , statusBar :: Bool + , maildirState :: MaildirState + , indexState :: IndexState + , composeState :: ComposeState + , colorStyle :: ColorStyle } data MaildirState = MaildirState { @@ -35,7 +38,7 @@ data MaildirState = MaildirState { data IndexState = IndexState { selectedRowIn :: Int - , selectedEmail :: Message + , selectedEmail :: Message , selectedEmails :: [(String, [Flag], String)] } @@ -43,35 +46,50 @@ data ComposeState = ComposeState { composition :: Maybe String } +data ColorStyle = ColorStyle { + baseColorID :: ColorID + , selectionColorID :: ColorID + , statusBarColorID :: ColorID +} + initialState = LazymailState { mode = MaildirMode - , screenRows = 0 + , basePath = "" + , screenRows = 0 , screenColumns = 0 - , currentRow = 0 + , currentRow = 0 , columnPadding = 0 , exitRequested = False - , statusBar = True + , statusBar = True , maildirState = initialMaildirState - , indexState = initialIndexState - , composeState = initialComposeState -} + , indexState = initialIndexState + , composeState = initialComposeState + , colorStyle = initialColorStyle +} initialMaildirState = MaildirState { selectedRowMD = 0 , selectedMD = "" - , detectedMDs = [] + , detectedMDs = [] } - + initialIndexState = IndexState { selectedRowIn = 0 , selectedEmail = Message [] "Dummy email" , selectedEmails = [] -} +} initialComposeState = ComposeState { composition = Nothing -} - +} + +initialColorStyle = ColorStyle { + baseColorID = defaultColorID + , selectionColorID = defaultColorID + , statusBarColorID = defaultColorID +} + + {- data MState = MState { selectedRowMD :: Integer -- Selected row in MaildirMode , selectedRowIn :: Integer -- Selected row in IndexMode -- cgit v1.2.3