From b8790e7ed5905ba0a8ac68a736e5059cbeaab351 Mon Sep 17 00:00:00 2001 From: Jens Nolte <jens@nightmarestudio.de> Date: Sat, 30 Nov 2019 04:20:26 +0100 Subject: [PATCH] Move runQBar to Server.hs, so it is easier to change the configuration It is now much easier to write a custom Main.hs that generates a custom bar configuration or that changes the argument parser. --- app/Main.hs | 11 +---------- src/QBar/Core.hs | 3 +++ src/QBar/Server.hs | 10 +++++++++- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index d9e15a5..8971411 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,17 +1,8 @@ module Main where import QBar.Cli -import QBar.ControlSocket import QBar.DefaultConfig -import QBar.Filter import QBar.Server main :: IO () -main = parseOptions >>= runQBar - -runQBar :: MainOptions -> IO () -runQBar options@MainOptions{barCommand} = runCommand barCommand - where - runCommand BarServer = runBarConfiguration generateDefaultBarConfig options - runCommand NoFilter = sendIpc options $ SetFilter $ StaticFilter None - runCommand RainbowFilter = sendIpc options $ SetFilter $ AnimatedFilter Rainbow \ No newline at end of file +main = parseOptions >>= (runQBar generateDefaultBarConfig) \ No newline at end of file diff --git a/src/QBar/Core.hs b/src/QBar/Core.hs index f95ddbb..f3d131b 100644 --- a/src/QBar/Core.hs +++ b/src/QBar/Core.hs @@ -78,6 +78,9 @@ data BarUpdateChannel = BarUpdateChannel (IO ()) type BarUpdateEvent = Event.Event +type BarConfiguration = BarUpdateChannel -> Producer CachedBlock IO () + + defaultColor :: T.Text defaultColor = "#969896" diff --git a/src/QBar/Server.hs b/src/QBar/Server.hs index 474f59a..c5769ed 100644 --- a/src/QBar/Server.hs +++ b/src/QBar/Server.hs @@ -211,4 +211,12 @@ runBarConfiguration generateBarConfig options = do renderLoop options handle barUpdateEvent initialOutput newBlockProducers createCommandChan :: IO CommandChan -createCommandChan = newTChanIO \ No newline at end of file +createCommandChan = newTChanIO + +-- |Entry point. +runQBar :: BarConfiguration -> MainOptions -> IO () +runQBar barConfiguration options@MainOptions{barCommand} = runCommand barCommand + where + runCommand BarServer = runBarConfiguration barConfiguration options + runCommand NoFilter = sendIpc options $ SetFilter $ StaticFilter None + runCommand RainbowFilter = sendIpc options $ SetFilter $ AnimatedFilter Rainbow \ No newline at end of file -- GitLab