diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Much/API.hs | 13 | ||||
| -rw-r--r-- | src/Much/API/Config.hs | 11 | ||||
| -rw-r--r-- | src/Much/Core.hs | 3 | ||||
| -rw-r--r-- | src/Much/State.hs | 4 | 
4 files changed, 23 insertions, 8 deletions
| diff --git a/src/Much/API.hs b/src/Much/API.hs index 5810c92..0c1bf8d 100644 --- a/src/Much/API.hs +++ b/src/Much/API.hs @@ -1,15 +1,17 @@  {-# LANGUAGE DataKinds #-}  {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-}  {-# LANGUAGE OverloadedStrings #-}  {-# LANGUAGE TypeOperators #-} -module Much.API where +module Much.API (module Much.API) where  import Control.Concurrent  import Control.Exception (catch, finally, throwIO)  import Control.Monad.IO.Class  import Data.Function ((&))  import Data.Proxy (Proxy) +import Much.API.Config as Much.API  import Much.Event  import Much.State  import Much.TreeView @@ -34,12 +36,11 @@ type API =  api :: Proxy API  api = Proxy -main :: (Event -> IO ()) -> IO () -main putEvent = do +main :: Config -> (Event -> IO ()) -> IO () +main Config{socketPath} putEvent = do      sock <- socket AF_UNIX Stream defaultProtocol -    let sockFile = "/home/tv/tmp/much/warp.sock" -- PID? -    removeIfExists sockFile -    bind sock $ SockAddrUnix sockFile +    removeIfExists socketPath +    bind sock $ SockAddrUnix socketPath      listen sock maxListenQueue      let settings = defaultSettings            & setPort 0 diff --git a/src/Much/API/Config.hs b/src/Much/API/Config.hs new file mode 100644 index 0000000..2e3b1cc --- /dev/null +++ b/src/Much/API/Config.hs @@ -0,0 +1,11 @@ +module Much.API.Config where + +data Config = Config +    { socketPath :: FilePath +    } + +emptyConfig :: Config +emptyConfig = +    Config +      { socketPath = "/tmp/much.api.sock" +      } diff --git a/src/Much/Core.hs b/src/Much/Core.hs index 769fd03..b0f9a51 100644 --- a/src/Much/Core.hs +++ b/src/Much/Core.hs @@ -70,6 +70,7 @@ emptyState = State          , unreadSearch = SGR [38,5,250]          }      , tagSymbols = M.empty +    , apiConfig = Much.API.emptyConfig      } @@ -164,7 +165,7 @@ runState q0 = do      threadIds <- mapM forkIO          [ forever $ scan stdin >>= putEvent . EScan -        , Much.API.main putEvent +        , Much.API.main (apiConfig q1) putEvent          ]      winchHandler putEvent diff --git a/src/Much/State.hs b/src/Much/State.hs index 43756a7..b7b01e6 100644 --- a/src/Much/State.hs +++ b/src/Much/State.hs @@ -9,9 +9,10 @@ import GHC.Generics  import Much.TreeView (TreeView)  import Scanner  import System.Posix.Signals -import qualified Data.Text as T  import qualified Data.Map as M +import qualified Data.Text as T  import qualified Data.Tree.Zipper as Z +import qualified Much.API.Config  data State = State      { cursor :: Z.TreePos Z.Full TreeView @@ -29,6 +30,7 @@ data State = State      , mousemap :: Scan -> State -> IO State      , tagSymbols :: M.Map T.Text T.Text      , colorConfig :: ColorConfig (Blessings String -> Blessings String) +    , apiConfig :: Much.API.Config.Config      }  instance Show (State -> IO ()) where | 
