Skip to content

Commit

Permalink
Tweak Config a bit, use mkVtyEscDelay
Browse files Browse the repository at this point in the history
  • Loading branch information
alip committed Jun 12, 2010
1 parent 1369a9d commit 03913e6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/Qoropa.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import Qoropa.Config (QoropaConfig)
import Qoropa.UI (start, mainLoop)

qoropa :: QoropaConfig -> IO ()
qoropa conf = do
ui <- start
mainLoop conf ui
qoropa cfg = do
ui <- start cfg
mainLoop ui

-- vim: set ft=haskell et ts=4 sts=4 sw=4 fdm=marker :
30 changes: 16 additions & 14 deletions src/Qoropa/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,14 @@ searchDrawStatusMessage :: Search.Attributes -> Search.StatusMessage -> Image
searchDrawStatusMessage attr msg = string (Search.attrStatusMessage attr) (Search.sMessage msg)

data QoropaConfig = QoropaConfig
{ databasePath :: FilePath
, folderList :: [(String,String)]
, keys :: Map Event (UI -> IO ())
, logPriority :: Priority
, themeSearch :: Search.Theme
, themeFolder :: Folder.Theme
, themeLog :: Log.Theme
{ configDatabasePath :: FilePath
, configFolderList :: [(String,String)]
, configKeys :: Map Event (UI -> IO ())
, configLogPriority :: Priority
, configThemeSearch :: Search.Theme
, configThemeFolder :: Folder.Theme
, configThemeLog :: Log.Theme
, configVtyEscDelay :: Int
}

defaultKeys :: Map Event (UI -> IO ())
Expand All @@ -332,13 +333,14 @@ defaultKeys = Map.fromList $

defaultConfig :: QoropaConfig
defaultConfig = QoropaConfig
{ databasePath = "~/.maildir"
, folderList = [("inbox", "tag:inbox"), ("unread", "tag:inbox and tag:unread")]
, keys = defaultKeys
, logPriority = NOTICE
, themeSearch = defaultSearchTheme
, themeFolder = defaultFolderTheme
, themeLog = defaultLogTheme
{ configDatabasePath = "~/.maildir"
, configFolderList = [("inbox", "tag:inbox"), ("unread", "tag:inbox and tag:unread")]
, configKeys = defaultKeys
, configLogPriority = NOTICE
, configThemeSearch = defaultSearchTheme
, configThemeFolder = defaultFolderTheme
, configThemeLog = defaultLogTheme
, configVtyEscDelay = 1000
}

-- vim: set ft=haskell et ts=4 sts=4 sw=4 fdm=marker :
22 changes: 22 additions & 0 deletions src/Qoropa/Config.hs-boot
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{-
- Qoropa -- Love Your Mail!
- Copyright © 2010 Ali Polatel
-
- This file is part of the Qoropa mail reader. Qoropa is free software;
- you can redistribute it and/or modify it under the terms of the GNU General
- Public License version 2, as published by the Free Software Foundation.
-
- Qoropa 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, write to the Free Software Foundation, Inc., 59 Temple
- Place, Suite 330, Boston, MA 02111-1307 USA
-
- Author: Ali Polatel <[email protected]>
-}

module Qoropa.Config where data QoropaConfig

-- vim: set ft=haskell et ts=4 sts=4 sw=4 fdm=marker :
40 changes: 21 additions & 19 deletions src/Qoropa/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import System.Log.Logger
)

import Graphics.Vty
( Vty, mkVty, reserve_display, shutdown, terminal, update
( Vty, mkVtyEscDelay, reserve_display, shutdown, terminal, update
, DisplayRegion(..), display_bounds
, Event(..), Key(..), Modifier(..), next_event
)
Expand Down Expand Up @@ -79,7 +79,8 @@ import Qoropa.Config (QoropaConfig(..))
import Qoropa.Util (beep, expandTilde)

data UI = UI
{ vty :: Vty
{ userConfig :: QoropaConfig
, vty :: Vty
, uiEvent :: MVar UIEvent
, uiThread :: ThreadId
, scrSize :: IORef (Int, Int)
Expand Down Expand Up @@ -215,17 +216,18 @@ cancelOperation ui = do
BufSearch ref -> Search.cancelLoad ref
_ -> beep

start :: IO UI
start = do
tid <- myThreadId
eventUI <- newEmptyMVar
start :: QoropaConfig -> IO UI
start cfg = do
tid <- myThreadId
eventUI <- newEmptyMVar

vtyUI <- mkVty
vtyUI <- mkVtyEscDelay (configVtyEscDelay cfg)
DisplayRegion x0 y0 <- display_bounds $ terminal vtyUI
size <- newIORef (fromEnum y0, fromEnum x0)
sq <- newIORef Seq.empty
cur <- newIORef 0
let ui = UI { vty = vtyUI
let ui = UI { userConfig = cfg
, vty = vtyUI
, scrSize = size
, uiEvent = eventUI
, uiThread = tid
Expand All @@ -246,21 +248,21 @@ exit ui = do
throwTo (uiThread ui) ExitSuccess
return ()

mainLoop :: QoropaConfig -> UI -> IO ()
mainLoop conf ui = do
path <- expandTilde (databasePath conf)
mainLoop :: UI -> IO ()
mainLoop ui = do
path <- expandTilde $ configDatabasePath $ userConfig ui

-- Initialize the log buffer
sq <- readIORef (bufSeq ui)
el <- Log.emptyLog (themeLog conf)
sq <- readIORef $ bufSeq ui
el <- Log.emptyLog $ configThemeLog $ userConfig ui
logRef <- newIORef el
logLock <- Lock.new
writeIORef (bufSeq ui) (sq Seq.|> (BufLog logRef, logLock))
writeIORef (bufCurrent ui) (Seq.length sq + 1)

-- Add the log handler
let logHandler = Log.handler (logRef, logLock) (uiEvent ui) (logPriority conf)
updateGlobalLogger rootLoggerName $ setLevel (logPriority conf) . setHandlers [logHandler]
let logHandler = Log.handler (logRef, logLock) (uiEvent ui) (configLogPriority $ userConfig ui)
updateGlobalLogger rootLoggerName $ setLevel (configLogPriority $ userConfig ui) . setHandlers [logHandler]
noticeM rootLoggerName "Initialized"

forkIO $ putMVar (uiEvent ui) NewFolder
Expand All @@ -275,21 +277,21 @@ mainLoop conf ui = do
(EvResize x y) -> writeIORef (scrSize ui) (y, x) >> redraw ui
(EvKey (KASCII 'z') [MCtrl]) -> raiseSignal sigTSTP
_ ->
case Map.lookup e (keys conf) of
case Map.lookup e (configKeys $ userConfig ui) of
Just f -> f ui
Nothing -> debugM rootLoggerName $ "Unhandled event: " ++ show e
NewFolder -> do
sq <- readIORef (bufSeq ui)
ef <- Folder.emptyFolder (themeFolder conf)
ef <- Folder.emptyFolder (configThemeFolder $ userConfig ui)
folderRef <- newIORef ef
folderLock <- Lock.new
writeIORef (bufSeq ui) (sq Seq.|> (BufFolder folderRef, folderLock))
writeIORef (bufCurrent ui) (Seq.length sq + 1)
forkIO $ Folder.new (folderRef, folderLock) (uiEvent ui) path (folderList conf)
forkIO $ Folder.new (folderRef, folderLock) (uiEvent ui) path (configFolderList $ userConfig ui)
return ()
NewSearch term -> do
sq <- readIORef (bufSeq ui)
es <- Search.emptySearch (themeSearch conf)
es <- Search.emptySearch (configThemeSearch $ userConfig ui)
searchRef <- newIORef es
searchLock <- Lock.new
writeIORef (bufSeq ui) (sq Seq.|> (BufSearch searchRef, searchLock))
Expand Down
4 changes: 3 additions & 1 deletion src/Qoropa/UI.hs-boot
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ import Graphics.Vty (Vty, Event)

import Qoropa.Lock (Lock)
import {-# SOURCE #-} Qoropa.Buffer (Buffer)
import {-# SOURCE #-} Qoropa.Config (QoropaConfig)

data UI = UI
{ vty :: Vty
{ userConfig :: QoropaConfig
, vty :: Vty
, uiEvent :: MVar UIEvent
, uiThread :: ThreadId
, scrSize :: IORef (Int, Int)
Expand Down

0 comments on commit 03913e6

Please sign in to comment.