From f4f349231c42c84db80cc28ca34a04edcf618ee4 Mon Sep 17 00:00:00 2001 From: Jens Nolte <jens@nightmarestudio.de> Date: Wed, 4 Dec 2019 00:18:12 +0100 Subject: [PATCH] Refactor rendering of initial blocks out of main entry point --- src/QBar/Server.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/QBar/Server.hs b/src/QBar/Server.hs index f6c5be9..81756a7 100644 --- a/src/QBar/Server.hs +++ b/src/QBar/Server.hs @@ -157,6 +157,16 @@ installSignalHandlers = do hPutStrLn stderr "SIGCONT received" updateBar' bar +renderInitialBlocks :: MainOptions -> Handle -> Filter -> IO C8.ByteString +renderInitialBlocks options handle blockFilter = do + date <- dateBlockOutput + let initialBlocks = [date] + -- Attach spinner indicator when verbose flag is set + let initialBlocks' = if indicator options then initialBlocks <> [createBlock "*"] else initialBlocks + -- Render initial time block so the bar is not empty after startup + renderLine options handle blockFilter initialBlocks' "" + + runBarConfiguration :: BarIO () -> MainOptions -> IO () runBarConfiguration generateBarConfig options = do -- Create IORef to contain the active filter @@ -166,12 +176,6 @@ runBarConfiguration generateBarConfig options = do putStrLn "{\"version\":1,\"click_events\":true}" putStrLn "[" - date <- dateBlockOutput - let initialBlocks = [date] - - -- Attach spinner indicator when verbose flag is set - let initialBlocks' = if indicator options then initialBlocks <> [createBlock "*"] else initialBlocks - (requestBarUpdate, barUpdateEvent) <- createBarUpdateChannel -- Create channel to send new block producers to render loop @@ -186,9 +190,8 @@ runBarConfiguration generateBarConfig options = do handleActiveFilter = activeFilter } + initialOutput <- renderInitialBlocks options handle initialBlockFilter - -- Render initial time block so the bar is not empty after startup - initialOutput <- renderLine options handle initialBlockFilter initialBlocks' "" -- Fork stdin handler void $ forkFinally (runReaderT (handleStdin options actionList) bar) (\result -> hPutStrLn stderr $ "handleStdin failed: " <> show result) @@ -221,6 +224,7 @@ runBarConfiguration generateBarConfig options = do -- Evaluate config generateBarConfig + createCommandChan :: IO CommandChan createCommandChan = newTChanIO -- GitLab