Skip to content
Snippets Groups Projects
Commit f4f34923 authored by Jens Nolte's avatar Jens Nolte
Browse files

Refactor rendering of initial blocks out of main entry point

parent 7d78fce0
No related branches found
No related tags found
No related merge requests found
...@@ -157,6 +157,16 @@ installSignalHandlers = do ...@@ -157,6 +157,16 @@ installSignalHandlers = do
hPutStrLn stderr "SIGCONT received" hPutStrLn stderr "SIGCONT received"
updateBar' bar 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 :: BarIO () -> MainOptions -> IO ()
runBarConfiguration generateBarConfig options = do runBarConfiguration generateBarConfig options = do
-- Create IORef to contain the active filter -- Create IORef to contain the active filter
...@@ -166,12 +176,6 @@ runBarConfiguration generateBarConfig options = do ...@@ -166,12 +176,6 @@ runBarConfiguration generateBarConfig options = do
putStrLn "{\"version\":1,\"click_events\":true}" putStrLn "{\"version\":1,\"click_events\":true}"
putStrLn "[" 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 (requestBarUpdate, barUpdateEvent) <- createBarUpdateChannel
-- Create channel to send new block producers to render loop -- Create channel to send new block producers to render loop
...@@ -186,9 +190,8 @@ runBarConfiguration generateBarConfig options = do ...@@ -186,9 +190,8 @@ runBarConfiguration generateBarConfig options = do
handleActiveFilter = activeFilter 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 -- Fork stdin handler
void $ forkFinally (runReaderT (handleStdin options actionList) bar) (\result -> hPutStrLn stderr $ "handleStdin failed: " <> show result) void $ forkFinally (runReaderT (handleStdin options actionList) bar) (\result -> hPutStrLn stderr $ "handleStdin failed: " <> show result)
...@@ -221,6 +224,7 @@ runBarConfiguration generateBarConfig options = do ...@@ -221,6 +224,7 @@ runBarConfiguration generateBarConfig options = do
-- Evaluate config -- Evaluate config
generateBarConfig generateBarConfig
createCommandChan :: IO CommandChan createCommandChan :: IO CommandChan
createCommandChan = newTChanIO createCommandChan = newTChanIO
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment