diff options
author | jao <jao@gnu.org> | 2022-02-04 03:34:48 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2022-02-04 03:34:48 +0000 |
commit | 57e8e23ec7b81b0a680dd9decc70bbf98892abab (patch) | |
tree | e2e63f3ce4fe65e59fcac3645af769829f108c59 /src/Xmobar/Text | |
parent | c1b6c382d8b020238e64c811bcc6f905f0f5390d (diff) | |
download | xmobar-57e8e23ec7b81b0a680dd9decc70bbf98892abab.tar.gz xmobar-57e8e23ec7b81b0a680dd9decc70bbf98892abab.tar.bz2 |
Refactoring: event loop handling simplifications
Diffstat (limited to 'src/Xmobar/Text')
-rw-r--r-- | src/Xmobar/Text/Loop.hs | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/src/Xmobar/Text/Loop.hs b/src/Xmobar/Text/Loop.hs index 42c8700..2903aa9 100644 --- a/src/Xmobar/Text/Loop.hs +++ b/src/Xmobar/Text/Loop.hs @@ -14,48 +14,35 @@ -- ------------------------------------------------------------------------------ -module Xmobar.Text.Loop (loop) where +module Xmobar.Text.Loop (textLoop) where import Prelude hiding (lookup) import System.IO import Control.Monad.Reader -import Control.Concurrent.Async (Async) import Control.Concurrent.STM import Xmobar.System.Signal - import Xmobar.Config.Types (Config) - -import qualified Xmobar.Run.Loop as Loop - +import Xmobar.Run.Loop (loop) import Xmobar.Run.Parsers (parseString) - import Xmobar.Text.Output (formatSegment) -- | Starts the main event loop and threads -loop :: Config -> IO () -loop conf = Loop.loop conf (startTextLoop' conf) - -startTextLoop' :: Config - -> TMVar SignalType - -> TMVar () - -> [[([Async ()], TVar String)]] - -> IO () -startTextLoop' cfg sig pauser vs = do - hSetBuffering stdin LineBuffering - hSetBuffering stdout LineBuffering - tv <- Loop.initLoop sig pauser vs - eventLoop cfg tv sig +textLoop :: Config -> IO () +textLoop conf = do + hSetBuffering stdin LineBuffering + hSetBuffering stdout LineBuffering + loop conf (eventLoop conf) -- | Continuously wait for a signal from a thread or a interrupt handler -eventLoop :: Config -> TVar [String] -> TMVar SignalType -> IO () -eventLoop cfg tv signal = do +eventLoop :: Config -> TMVar SignalType -> TVar [String] -> IO () +eventLoop cfg signal tv = do typ <- atomically $ takeTMVar signal case typ of - Wakeup -> updateString cfg tv >>= putStrLn >> eventLoop cfg tv signal - _ -> eventLoop cfg tv signal + Wakeup -> updateString cfg tv >>= putStrLn >> eventLoop cfg signal tv + _ -> eventLoop cfg signal tv updateString :: Config -> TVar [String] -> IO String updateString conf v = do |