From 89cd31ce1275bee6c8da8b3d9f4b00155a2e5fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Sun, 25 Aug 2013 19:55:17 -0300 Subject: Added a couple of hooks --- Config.hs | 58 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 12 deletions(-) (limited to 'Config.hs') diff --git a/Config.hs b/Config.hs index 5c4e477..26c062d 100644 --- a/Config.hs +++ b/Config.hs @@ -8,23 +8,29 @@ module Config(LazymailConfig(..), defaultConfig, customConfig) where +import Data.List(sort, stripPrefix) +import System.FilePath(FilePath, takeFileName, dropTrailingPathSeparator) +import System.Posix.Files(getSymbolicLinkStatus, isSymbolicLink) import UI.NCurses(Color(..)) -import System.FilePath(FilePath) data LazymailConfig = LazymailConfig { - baseColor :: (Color, Color) -- (foreground, background) - , selectionColor :: (Color, Color) - , statusBarColor :: (Color, Color) - , showStatusBar :: Bool - , initialPath :: FilePath + baseColor :: (Color, Color) -- (foreground, background) + , selectionColor :: (Color, Color) + , statusBarColor :: (Color, Color) + , showStatusBar :: Bool + , initialPath :: FilePath + , filterMaildirsHook :: [FilePath] -> IO [FilePath] + , maildirDrawHook :: String -> String -> String } defaultConfig = LazymailConfig { - baseColor = (ColorWhite, ColorBlack) - , selectionColor = (ColorBlack, ColorWhite) - , statusBarColor = (ColorBlack, ColorWhite) - , showStatusBar = True - , initialPath = "" + baseColor = (ColorWhite, ColorBlack) + , selectionColor = (ColorBlack, ColorWhite) + , statusBarColor = (ColorBlack, ColorWhite) + , showStatusBar = True + , initialPath = "" + , filterMaildirsHook = \mds -> return mds + , maildirDrawHook = \_ md -> md } -- @@ -32,4 +38,32 @@ defaultConfig = LazymailConfig { -- preferences. In a possible future maybe I'll work in a not-so-crappy -- config system. -- -customConfig = defaultConfig { initialPath = "/home/rul/mail/linti/" } \ No newline at end of file +--customConfig = defaultConfig { initialPath = "/home/rul/mail/"} + + +customConfig = defaultConfig { initialPath = "/home/rul/mail/linti" + , maildirDrawHook = indentedShow + , filterMaildirsHook = filterSymlinks } + +indentedShow :: String -> String -> String +indentedShow bp md = + let str = case (stripPrefix bp md) of + Nothing -> md + Just s -> s + name' = takeFileName . dropTrailingPathSeparator $ str + name = takeFileName $ map (\x -> if x `elem` imapSep then '/' else x) name' + pad = " " + numPads = (length $ filter (== '/') str) + (length $ filter (`elem` imapSep) str) + imapSep = ['.'] -- IMAP usually separates its directories with dots + in (concat $ replicate (numPads - 1) pad) ++ pad ++ name + +filterSymlinks :: [FilePath] -> IO [FilePath] +filterSymlinks [] = return [] +filterSymlinks (md:mds) = do + filtered <- do + fs <- getSymbolicLinkStatus md + rest <- filterSymlinks mds + if isSymbolicLink fs + then return rest + else return (md:rest) + return $ sort filtered \ No newline at end of file -- cgit v1.2.3