aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Codec/Text/Rfc1342.hs (renamed from Rfc1342.hs)2
-rw-r--r--Lazymail.hs22
-rw-r--r--Lazymail/Config.hs (renamed from Config.hs)10
-rw-r--r--Lazymail/Email.hs (renamed from Email.hs)4
-rw-r--r--Lazymail/Handlers.hs (renamed from Handlers.hs)12
-rw-r--r--Lazymail/Keymap.hs16
-rw-r--r--Lazymail/Maildir.hs (renamed from Maildir.hs)4
-rw-r--r--Lazymail/Print.hs (renamed from Print.hs)8
-rw-r--r--Lazymail/Screen.hs (renamed from Screen.hs)22
-rw-r--r--Lazymail/State.hs (renamed from State.hs)4
-rw-r--r--Lazymail/Types.hs (renamed from Types.hs)11
-rw-r--r--Main.hs19
12 files changed, 75 insertions, 59 deletions
diff --git a/Rfc1342.hs b/Codec/Text/Rfc1342.hs
index c2dad42..f6d8fe2 100644
--- a/Rfc1342.hs
+++ b/Codec/Text/Rfc1342.hs
@@ -5,7 +5,7 @@
- Licensed under the GNU GPL version 3 or higher
-
-}
-module Rfc1342 (decodeField) where
+module Codec.Text.Rfc1342 (decodeField) where
import qualified Codec.Binary.Base64 as B64
import qualified Codec.Binary.QuotedPrintable as QP
diff --git a/Lazymail.hs b/Lazymail.hs
deleted file mode 100644
index fbb7e3e..0000000
--- a/Lazymail.hs
+++ /dev/null
@@ -1,22 +0,0 @@
-{- Lazymail monad.
- -
- - Copyright 2013 Raúl Benencia <rul@kalgan.cc>
- -
- - Licensed under the GNU GPL version 3 or higher
- -
- -}
-
-module Lazymail where
-
-import Control.Monad.Reader
-import Control.Monad.State
-
-import Config
-import State
-import Types
-
-run :: Lazymail a -> IO (a, LazymailState)
-run k =
- let config = customConfig
- state = initialState { basePath = initialPath config }
- in runStateT (runReaderT k config) state \ No newline at end of file
diff --git a/Config.hs b/Lazymail/Config.hs
index 01b1435..2566bc9 100644
--- a/Config.hs
+++ b/Lazymail/Config.hs
@@ -6,13 +6,14 @@
-
-}
-module Config(LazymailConfig(..), defaultConfig, customConfig) where
+module Lazymail.Config(LazymailConfig(..), defaultConfig, customConfig) where
import Data.List(sort, stripPrefix)
import System.Posix.Files(getSymbolicLinkStatus, isSymbolicLink)
import UI.NCurses(Color(..))
-import Types(LazymailConfig(..))
+import Lazymail.Keymap
+import Lazymail.Types(LazymailConfig(..))
defaultConfig = LazymailConfig {
baseColor = (ColorWhite, ColorBlack)
@@ -25,6 +26,11 @@ defaultConfig = LazymailConfig {
, filterMaildirsHook = \mds -> return mds
, indexDateFormat = "%m %d"
, headersToShow = ["date", "from", "to", "cc", "bcc", "subject", "reply-to"]
+ , globalKeymaps = defaultGlobalKeymap
+ , maildirModeKeymap = defaultMaildirKeymap
+ , indexModeKeymap = defaultIndexKeymap
+ , emailModeKeymap = defaultEmailKeymap
+ , composeModeKeymap = defaultComposeKeymap
}
--
diff --git a/Email.hs b/Lazymail/Email.hs
index db6f17b..fc63a89 100644
--- a/Email.hs
+++ b/Lazymail/Email.hs
@@ -5,7 +5,7 @@
- Licensed under the GNU GPL version 3 or higher
-
-}
-module Email where
+module Lazymail.Email where
import Codec.MIME.Type(MIMEValue(..), MIMEContent(..), showMIMEType, Type(..), MIMEType(..))
import Data.Char(toLower)
@@ -20,7 +20,7 @@ getBody msg =
Nothing -> "This email has no displayable content."
where
unwrapContent (Single c) = c
-
+
-- hackish function for showing the email. In he future the logic of this
-- function should be improved.
firstTextPart [] = Nothing
diff --git a/Handlers.hs b/Lazymail/Handlers.hs
index 5c04f89..b0b1165 100644
--- a/Handlers.hs
+++ b/Lazymail/Handlers.hs
@@ -5,7 +5,7 @@
- Licensed under the GNU GPL version 3 or higher
-}
-module Handlers where
+module Lazymail.Handlers where
import Codec.MIME.Parse(parseMIMEMessage)
import Codec.MIME.Type(MIMEValue(..))
@@ -18,11 +18,11 @@ import System.Locale(rfc822DateFormat)
import Data.DateTime(parseDateTime, startOfTime, formatDateTime)
import qualified System.IO.UTF8 as UTF8
-import Email(lookupField, getBody, formatBody)
-import Maildir
-import Print
-import State
-import Types
+import Lazymail.Email(lookupField, getBody, formatBody)
+import Lazymail.Maildir
+import Lazymail.Print
+import Lazymail.State
+import Lazymail.Types
previousMode :: Mode -> LazymailCurses ()
previousMode MaildirMode = (=<<) put $ get >>= \st -> return st { exitRequested = True }
diff --git a/Lazymail/Keymap.hs b/Lazymail/Keymap.hs
new file mode 100644
index 0000000..1cef1b1
--- /dev/null
+++ b/Lazymail/Keymap.hs
@@ -0,0 +1,16 @@
+module Lazymail.Keymap
+ ( defaultGlobalKeymap
+ , defaultMaildirKeymap
+ , defaultIndexKeymap
+ , defaultEmailKeymap
+ , defaultComposeKeymap
+ ) where
+
+import UI.NCurses(Event(..))
+import Lazymail.Types(LazymailCurses)
+
+defaultGlobalKeymap = []
+defaultMaildirKeymap = []
+defaultIndexKeymap = []
+defaultEmailKeymap = []
+defaultComposeKeymap = [] \ No newline at end of file
diff --git a/Maildir.hs b/Lazymail/Maildir.hs
index 752f6f0..1793105 100644
--- a/Maildir.hs
+++ b/Lazymail/Maildir.hs
@@ -6,7 +6,7 @@
-
-}
-module Maildir where
+module Lazymail.Maildir where
import Control.Monad.Loops(allM)
import Control.Monad (forM, filterM)
@@ -15,7 +15,7 @@ import System.Directory (doesDirectoryExist, getDirectoryContents, renameFile)
import System.FilePath ((</>), takeFileName, takeDirectory, splitDirectories, joinPath)
import System.IO(IOMode(..), hGetContents, openFile)
-import Types(Maildir, Flag(..), Flags)
+import Lazymail.Types(Maildir, Flag(..), Flags)
isMaildir :: FilePath -> IO Bool
isMaildir fp = allM doesDirectoryExist [ fp
diff --git a/Print.hs b/Lazymail/Print.hs
index 81dd9d0..15e9df1 100644
--- a/Print.hs
+++ b/Lazymail/Print.hs
@@ -6,14 +6,14 @@
-
-}
-module Print where
+module Lazymail.Print where
import Data.Char (isSpace)
import Data.List (intercalate)
-import Email
-import Rfc1342
-import Types(Flag(..), Flags)
+import Lazymail.Email
+import Codec.Text.Rfc1342
+import Lazymail.Types(Flag(..), Flags)
unquote xs= if (head xs == '"' && last xs == '"') then (tail . init) xs else xs
diff --git a/Screen.hs b/Lazymail/Screen.hs
index 6bc5b5e..699f84e 100644
--- a/Screen.hs
+++ b/Lazymail/Screen.hs
@@ -7,7 +7,7 @@
- This code is in an urgent need of a big refactoring.
-}
-module Screen where
+module Lazymail.Screen where
import Codec.MIME.Type(MIMEValue(..))
import Control.Monad.Trans(liftIO)
@@ -19,15 +19,14 @@ import System.Exit
import UI.NCurses
-- Local imports
-import Config
-import qualified Handlers as EH
-import Lazymail
-import Maildir
-import Email(lookupField, getBody, getHeaders, lookupField')
-import Print
-import Rfc1342
-import State
-import Types
+import Lazymail.Config
+import qualified Lazymail.Handlers as EH
+import Lazymail.Maildir
+import Lazymail.Email(lookupField, getBody, getHeaders, lookupField')
+import Lazymail.Print
+import Codec.Text.Rfc1342
+import Lazymail.State
+import Lazymail.Types
{- This function is the nexus between Curses and IO -}
entryPoint :: Lazymail ()
@@ -51,6 +50,7 @@ startCurses = do
(=<<) put $ liftCurses $ do
setEcho False
setCursorMode CursorInvisible
+ w <- defaultWindow
(rows, cols) <- screenSize
basColID <- newColorID (fst . baseColor $ cfg) (snd . baseColor $ cfg) 1
selColID <- newColorID (fst . selectionColor $ cfg) (snd . selectionColor $ cfg) 2
@@ -237,7 +237,7 @@ handleEvent = loop where
EventSpecialKey KeyDownArrow -> EH.incSelectedRow (mode st)
EventCharacter 'j' -> EH.incSelectedRow (mode st)
- EventSpecialKey KeyEnter -> EH.changeMode (mode st)
+ EventCharacter '\n' -> EH.changeMode (mode st)
EventSpecialKey KeyRightArrow -> EH.changeMode (mode st)
_ -> loop
diff --git a/State.hs b/Lazymail/State.hs
index 5c3112f..06353da 100644
--- a/State.hs
+++ b/Lazymail/State.hs
@@ -6,7 +6,7 @@
-
-}
-module State where
+module Lazymail.State where
import Codec.MIME.Type(MIMEValue, nullMIMEValue)
import Text.ParserCombinators.Parsec.Rfc2822(Message, GenericMessage(..))
@@ -14,7 +14,7 @@ import UI.NCurses(ColorID(..), defaultColorID)
import Network.Email.Mailbox(Flag(..), Flags)
import System.FilePath
-import Types
+import Lazymail.Types
initialState = LazymailState {
mode = MaildirMode
diff --git a/Types.hs b/Lazymail/Types.hs
index 07c9144..fb30f91 100644
--- a/Types.hs
+++ b/Lazymail/Types.hs
@@ -5,7 +5,7 @@
- Licensed under the GNU GPL version 3 or higher
-}
-module Types where
+module Lazymail.Types where
import Codec.MIME.Type(MIMEValue(..))
import Control.Monad.Reader(ReaderT)
@@ -13,7 +13,7 @@ import Control.Monad.State(StateT)
import Data.DateTime(DateTime)
import System.FilePath(FilePath)
import System.IO(Handle)
-import UI.NCurses(Curses, Update, Color(..), ColorID)
+import UI.NCurses(Curses, Update, Color(..), ColorID, Event(..))
type LazymailUpdate = ReaderT LazymailConfig (StateT LazymailState Update)
type LazymailCurses = ReaderT LazymailConfig (StateT LazymailState Curses)
@@ -34,6 +34,11 @@ data LazymailConfig = LazymailConfig {
, filterMaildirsHook :: [FilePath] -> IO [FilePath]
, indexDateFormat :: String
, headersToShow :: [String]
+ , globalKeymaps :: [Keymap]
+ , maildirModeKeymap :: [Keymap]
+ , indexModeKeymap :: [Keymap]
+ , emailModeKeymap :: [Keymap]
+ , composeModeKeymap :: [Keymap]
}
data Email = Email {
@@ -119,3 +124,5 @@ data ColorStyle = ColorStyle {
, headerColorID :: ColorID
, newEmailColorID :: ColorID
}
+
+type Keymap = ([Event], LazymailCurses ()) \ No newline at end of file
diff --git a/Main.hs b/Main.hs
index 416b65a..2144d9c 100644
--- a/Main.hs
+++ b/Main.hs
@@ -8,15 +8,18 @@
module Main (main) where
+import Control.Monad.Reader(runReaderT)
+import Control.Monad.State(runStateT)
import System.Environment
import System.Exit
import System.FilePath(takeDirectory)
-import Lazymail
-import Email
-import Maildir
-import Screen
-import State
+import Lazymail.Config(customConfig)
+import Lazymail.Email
+import Lazymail.Maildir
+import Lazymail.Screen
+import Lazymail.State
+import Lazymail.Types
parse ["-h"] = usage >> exit
parse ["--help"] = usage >> exit
@@ -24,6 +27,12 @@ parse ["-v"] = version >> exit
parse ["--version"] = version >> exit
parse _ = run entryPoint
+run :: Lazymail a -> IO (a, LazymailState)
+run k =
+ let config = customConfig
+ state = initialState { basePath = initialPath config }
+ in runStateT (runReaderT k config) state
+
usage = putStrLn . unlines $ usageText where
usageText = ["Usage: ./Main [-vh] <maildirs>"
," where <maildirs> is a directory with Maildirs, or a Maildir itself."
nihil fit ex nihilo