aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaúl Benencia <rul@kalgan.cc>2013-09-03 12:29:47 -0300
committerRaúl Benencia <rul@kalgan.cc>2013-09-03 12:29:47 -0300
commitfc7a8483f4a66a3f47bbb335574a399df64d62e0 (patch)
treeee91c99a23b8999503d47635b1b404d54770e586
parentac5a65d8adc1d9a683327165057493d9cba6fdb8 (diff)
Color in new emails
-rw-r--r--Config.hs9
-rw-r--r--Handlers.hs2
-rw-r--r--Maildir.hs9
-rw-r--r--Print.hs7
-rw-r--r--Screen.hs22
-rw-r--r--State.hs1
-rw-r--r--Types.hs19
7 files changed, 52 insertions, 17 deletions
diff --git a/Config.hs b/Config.hs
index a0f872a..01b1435 100644
--- a/Config.hs
+++ b/Config.hs
@@ -16,14 +16,15 @@ import Types(LazymailConfig(..))
defaultConfig = LazymailConfig {
baseColor = (ColorWhite, ColorBlack)
- , selectionColor = (ColorYellow, ColorBlack)
- , statusBarColor = (ColorYellow, ColorBlack)
- , headerColor = (ColorYellow, ColorBlack)
+ , selectionColor = (ColorBlack, ColorWhite)
+ , statusBarColor = (ColorBlack, ColorBlue)
+ , headerColor = (ColorGreen, ColorBlack)
+ , newEmailColor = (ColorBlue, ColorBlack)
, showStatusBar = True
, initialPath = ""
, filterMaildirsHook = \mds -> return mds
, indexDateFormat = "%m %d"
- , headersToShow = ["date", "from", "to", "cc", "bcc", "subject", "reply-to"]
+ , headersToShow = ["date", "from", "to", "cc", "bcc", "subject", "reply-to"]
}
--
diff --git a/Handlers.hs b/Handlers.hs
index fc4c009..644d643 100644
--- a/Handlers.hs
+++ b/Handlers.hs
@@ -170,7 +170,7 @@ formatIndexModeRows st = map formatRow where
email = emailValue e
hs = mime_val_headers email
str = normalizeLen (screenColumns st) $ intercalate ppSep $
- [ ppFlags . getFlags $ fp
+ [ "[" ++ normalizeLen maxFlags (ppFlags . getFlags $ fp) ++ "]"
, formatDateTime "%b %d" $ emailDate e
, normalizeLen fromLen $ ppField $ lookupField "from" hs
, ppField $ lookupField "subject" hs
diff --git a/Maildir.hs b/Maildir.hs
index ede0f44..7e2941d 100644
--- a/Maildir.hs
+++ b/Maildir.hs
@@ -14,9 +14,8 @@ import Data.List(isPrefixOf)
import System.Directory (doesDirectoryExist, getDirectoryContents)
import System.FilePath ((</>))
import System.IO(IOMode(..), hGetContents, openFile)
-import Network.Email.Mailbox(Flag(..), Flags)
-type Maildir = FilePath
+import Types(Maildir, Flag(..), Flags)
isMaildir :: FilePath -> IO Bool
isMaildir fp = allM doesDirectoryExist [ fp
@@ -96,12 +95,16 @@ listMessageFlags fp = do
return (zip ids flags)
getFlags :: FilePath -> Flags
-getFlags fp = map toFlag $ strip fp
+getFlags fp = addNew $ map toFlag $ strip fp
where strip x
| null x = []
| ":2," `isPrefixOf` x = drop 3 x
| otherwise = let (discard, analyze) = span (/= ':') fp
in strip analyze
+ addNew flags = if elem SEEN flags then flags else (NEW:flags)
+
+isNew :: FilePath -> Bool
+isNew fp = elem NEW $ getFlags fp
toFlag :: Char -> Flag
toFlag c | c == 'S' = SEEN
diff --git a/Print.hs b/Print.hs
index cae3a45..d033bf2 100644
--- a/Print.hs
+++ b/Print.hs
@@ -10,11 +10,10 @@ module Print where
import Data.Char (isSpace)
import Data.List (intercalate)
-import Network.Email.Mailbox(Flag(..), Flags)
-import Text.ParserCombinators.Parsec.Rfc2822(NameAddr(..))
import Email
import Rfc1342
+import Types(Flag(..), Flags)
unquote xs= if (head xs == '"' && last xs == '"') then (tail . init) xs else xs
@@ -26,12 +25,16 @@ ppField = flat . decodeField
fromLen :: Int
fromLen = 20
+maxFlags :: Int
+maxFlags = 4
+
flat xs = intercalate " " $ map (dropWhile isSpace) $ map (filter (/= '\r')) $ lines xs
ppFlags :: Flags -> String
ppFlags = map ppFlag
ppFlag :: Flag -> Char
+ppFlag NEW = 'N'
ppFlag SEEN = 'S'
ppFlag ANSWERED = 'A'
ppFlag FLAGGED = 'F'
diff --git a/Screen.hs b/Screen.hs
index ea90e75..617bdcb 100644
--- a/Screen.hs
+++ b/Screen.hs
@@ -54,12 +54,12 @@ startCurses = do
basColID <- newColorID (fst . baseColor $ cfg) (snd . baseColor $ cfg) 1
selColID <- newColorID (fst . selectionColor $ cfg) (snd . selectionColor $ cfg) 2
staColID <- newColorID (fst . statusBarColor $ cfg) (snd . statusBarColor $ cfg) 3
- heaColID <- newColorID (fst . headerColor $ cfg) (snd . headerColor $ cfg) 3
- let style = ColorStyle defaultColorID selColID staColID heaColID
+ heaColID <- newColorID (fst . headerColor $ cfg) (snd . headerColor $ cfg) 4
+ newColID <- newColorID (fst . newEmailColor $ cfg) (snd . newEmailColor $ cfg) 5
+ let style = ColorStyle basColID selColID staColID heaColID newColID
return $ st { screenRows = fromIntegral $ rows - 1
, screenColumns = fromIntegral $ cols
, colorStyle = style }
-
resetScrollBuffer
screenLoop
@@ -110,7 +110,7 @@ drawSelectionList ((path, str):mds) = do
let ist = (indexState st) { selectedEmailPath = path }
return $ st { indexState = ist }
else do
- drawString $ normalizeLen (screenColumns st) str
+ drawSimpleRow st path str
return st
st <- get
@@ -122,6 +122,16 @@ drawSelectionList ((path, str):mds) = do
else
resetCurrentRow
+drawSimpleRow st path str | (mode st) == MaildirMode = drawString $ normalizeLen (screenColumns st) str
+ | (mode st) == IndexMode =
+ if isNew path
+ then do
+ setColor $ newEmailColorID . colorStyle $ st
+ drawCroppedString st str
+ setColor $ baseColorID . colorStyle $ st
+ else
+ drawCroppedString st str
+
{- Empty the whole window. Useful when changing modes. -}
clearMain rows columns = do
drawEmptyLine 0
@@ -166,7 +176,7 @@ drawEmailHeaders = do
Nothing -> parseHeaders headers row hs
Just f -> let p = capitalize h ++ ": " ++ (ppField f)
in p:parseHeaders headers (row + 1) hs
-
+
capitalize str = (toUpper . head $ str):(tail str)
drawHeaders _ _ [] = return ()
drawHeaders st row (h:hs) = do
@@ -187,7 +197,7 @@ drawStatus = do
liftUpdate $ do
moveCursor ((scrRowsAsInteger st) - 1) 0
setColor $ statusBarColorID . colorStyle $ st
- drawString . normalizeLen (screenColumns st) . concat $ drawStatusHelper (mode st) st
+ drawCroppedString st $ concat $ drawStatusHelper (mode st) st
setColor $ baseColorID . colorStyle $ st
{- Status bar string for Maildir mode -}
diff --git a/State.hs b/State.hs
index f9c8683..5d04035 100644
--- a/State.hs
+++ b/State.hs
@@ -65,6 +65,7 @@ initialColorStyle = ColorStyle {
, selectionColorID = defaultColorID
, statusBarColorID = defaultColorID
, headerColorID = defaultColorID
+ , newEmailColorID = defaultColorID
}
scrColsAsInteger st = toInteger $ screenColumns st
diff --git a/Types.hs b/Types.hs
index 4a7cc89..86ca334 100644
--- a/Types.hs
+++ b/Types.hs
@@ -27,11 +27,12 @@ data LazymailConfig = LazymailConfig {
, selectionColor :: (Color, Color)
, statusBarColor :: (Color, Color)
, headerColor :: (Color, Color)
+ , newEmailColor :: (Color, Color)
, showStatusBar :: Bool
, initialPath :: FilePath
, filterMaildirsHook :: [FilePath] -> IO [FilePath]
, indexDateFormat :: String
- , headersToShow :: [String]
+ , headersToShow :: [String]
}
data Email = Email {
@@ -47,6 +48,21 @@ instance Ord Email where
(Email _ d1 _) `compare` (Email _ d2 _) = d1 `compare` d2
data Mode = MaildirMode | IndexMode | EmailMode | ComposeMode
+ deriving (Show, Eq)
+
+type Maildir = FilePath
+
+data Flag = NEW
+ | SEEN
+ | ANSWERED
+ | FLAGGED
+ | DELETED
+ | DRAFT
+ | FORWARDED
+ | OTHERFLAG String
+ deriving (Eq)
+
+type Flags = [Flag]
data LazymailState = LazymailState {
mode :: Mode
@@ -97,4 +113,5 @@ data ColorStyle = ColorStyle {
, selectionColorID :: ColorID
, statusBarColorID :: ColorID
, headerColorID :: ColorID
+ , newEmailColorID :: ColorID
}
nihil fit ex nihilo