Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qbar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
qbar
Commits
1fb0ba68
Commit
1fb0ba68
authored
5 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Remove intermediate refactoring types
parent
7de6ecaf
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/QBar/Core.hs
+7
-10
7 additions, 10 deletions
src/QBar/Core.hs
src/QBar/Server.hs
+17
-17
17 additions, 17 deletions
src/QBar/Server.hs
with
24 additions
and
27 deletions
src/QBar/Core.hs
+
7
−
10
View file @
1fb0ba68
...
...
@@ -48,14 +48,11 @@ data CachedMode = CachedMode
-- |Block that 'yield's an update whenever the block should be changed
type
PushBlock
=
PushBlockProducer
type
PushBlockProducer
=
Producer
BlockOutput
IO
PushMode
type
PushBlock
=
Producer
BlockOutput
IO
PushMode
-- |Block that generates an update on 'yield'. Should only be pulled when an update is required.
type
PullBlock
=
PullBlockProducer
type
PullBlockProducer
=
Producer
BlockOutput
IO
PullMode
type
PullBlock
=
Producer
BlockOutput
IO
PullMode
-- |Cached block. Always 'yield's the latest update, so it should only be pulled when the bar is rendered.
type
CachedBlock
=
CachedBlockProducer
type
CachedBlockProducer
=
Producer
BlockOutput
IO
CachedMode
type
CachedBlock
=
Producer
BlockOutput
IO
CachedMode
class
IsBlock
a
where
toCachedBlock
::
BarUpdateChannel
->
a
->
CachedBlock
...
...
@@ -185,7 +182,7 @@ cacheFromInput input = fmap (\_ -> CachedMode) $ fromInput input
-- Returns an IO action that can be used to attach blocks to the shared interval and an async that contains a reference to the scheduler thread.
sharedInterval
::
BarUpdateChannel
->
Int
->
IO
(
PullBlock
->
CachedBlock
,
Async
()
)
sharedInterval
barUpdateChannel
seconds
=
do
clientsMVar
<-
newMVar
(
[]
::
[(
MVar
PullBlock
Producer
,
Output
BlockOutput
)])
clientsMVar
<-
newMVar
(
[]
::
[(
MVar
PullBlock
,
Output
BlockOutput
)])
task
<-
async
$
forever
$
do
threadDelay
$
seconds
*
1000000
...
...
@@ -197,11 +194,11 @@ sharedInterval barUpdateChannel seconds = do
return
(
addClient
clientsMVar
,
task
)
where
runAndFilterClient
::
(
MVar
PullBlock
Producer
,
Output
BlockOutput
)
->
IO
(
Maybe
(
MVar
PullBlock
Producer
,
Output
BlockOutput
))
runAndFilterClient
::
(
MVar
PullBlock
,
Output
BlockOutput
)
->
IO
(
Maybe
(
MVar
PullBlock
,
Output
BlockOutput
))
runAndFilterClient
client
=
do
result
<-
runClient
client
return
$
if
result
then
Just
client
else
Nothing
runClient
::
(
MVar
PullBlock
Producer
,
Output
BlockOutput
)
->
IO
Bool
runClient
::
(
MVar
PullBlock
,
Output
BlockOutput
)
->
IO
Bool
runClient
(
blockProducerMVar
,
output
)
=
modifyMVar
blockProducerMVar
$
\
blockProducer
->
do
result
<-
next
blockProducer
...
...
@@ -228,7 +225,7 @@ sharedInterval barUpdateChannel seconds = do
void
$
runClient
(
blockProducerMVar
,
output
)
-- Notify bar about changed block state, this is usually done by the shared interval handler
updateBar
barUpdateChannel
addClient
::
MVar
[(
MVar
PullBlock
Producer
,
Output
BlockOutput
)]
->
PullBlock
Producer
->
CachedBlock
addClient
::
MVar
[(
MVar
PullBlock
,
Output
BlockOutput
)]
->
PullBlock
->
CachedBlock
addClient
clientsMVar
blockProducer
=
do
-- Spawn the mailbox that preserves the latest block
(
output
,
input
)
<-
lift
$
spawn
$
latest
emptyBlock
...
...
This diff is collapsed.
Click to expand it.
src/QBar/Server.hs
+
17
−
17
View file @
1fb0ba68
...
...
@@ -37,27 +37,27 @@ renderIndicator :: CachedBlock
-- Using 'cachedBlock' is a hack to actually get the block to update on every bar update (by doing this it will not get a cache later in the pipeline).
renderIndicator
=
forever
$
each
$
map
createBlock
[
"/"
,
"-"
,
"
\\
"
,
"|"
]
runBlock
::
CachedBlock
Producer
->
IO
(
Maybe
(
BlockOutput
,
CachedBlock
Producer
))
runBlock
::
CachedBlock
->
IO
(
Maybe
(
BlockOutput
,
CachedBlock
))
runBlock
producer
=
do
next'
<-
next
producer
return
$
case
next'
of
Left
_
->
Nothing
Right
(
block
,
newProducer
)
->
Just
(
block
,
newProducer
)
runBlocks
::
[
CachedBlock
Producer
]
->
IO
([
BlockOutput
],
[
CachedBlock
Producer
])
runBlocks
block
Producers
=
unzip
.
catMaybes
<$>
mapM
runBlock
block
Producers
runBlocks
::
[
CachedBlock
]
->
IO
([
BlockOutput
],
[
CachedBlock
])
runBlocks
block
=
unzip
.
catMaybes
<$>
mapM
runBlock
block
renderLoop
::
MainOptions
->
Handle
->
BarUpdateEvent
->
BS
.
ByteString
->
TChan
CachedBlock
->
IO
()
renderLoop
options
handle
@
Handle
{
handleActiveFilter
}
barUpdateEvent
previousBarOutput
newBlockChan
=
renderLoop'
previousBarOutput
[]
where
addNewBlock
Producer
s
::
[
CachedBlock
]
->
IO
[
CachedBlock
]
addNewBlock
Producers
blockProducer
s
=
do
addNewBlocks
::
[
CachedBlock
]
->
IO
[
CachedBlock
]
addNewBlock
s
block
s
=
do
maybeNewBlock
<-
atomically
$
tryReadTChan
newBlockChan
case
maybeNewBlock
of
Nothing
->
return
block
Producer
s
Just
newBlock
->
addNewBlock
Producer
s
(
newBlock
:
block
Producer
s
)
Nothing
->
return
blocks
Just
newBlock
->
addNewBlocks
(
newBlock
:
blocks
)
renderLoop'
::
BS
.
ByteString
->
[
CachedBlock
]
->
IO
()
renderLoop'
previousBarOutput'
block
Producer
s
=
do
renderLoop'
previousBarOutput'
blocks
=
do
blockFilter
<-
readIORef
handleActiveFilter
-- Wait for an event (unless the filter is animated)
...
...
@@ -67,16 +67,16 @@ renderLoop options handle@Handle{handleActiveFilter} barUpdateEvent previousBarO
threadDelay
10000
Event
.
clear
barUpdateEvent
block
Producer
s'
<-
addNewBlock
Producers
blockProducer
s
blocks'
<-
addNewBlock
s
block
s
(
blocks
,
block
Producer
s''
)
<-
runBlocks
block
Producer
s'
(
block
Output
s
,
blocks''
)
<-
runBlocks
blocks'
currentBarOutput
<-
renderLine
options
handle
blockFilter
blocks
previousBarOutput'
currentBarOutput
<-
renderLine
options
handle
blockFilter
block
Output
s
previousBarOutput'
-- Wait for 100ms after rendering a line to limit cpu load of rapid events
threadDelay
100000
renderLoop'
currentBarOutput
block
Producer
s''
renderLoop'
currentBarOutput
blocks''
renderLine
::
MainOptions
->
Handle
->
Filter
->
[
BlockOutput
]
->
BS
.
ByteString
->
IO
BS
.
ByteString
renderLine
MainOptions
{
verbose
}
Handle
{
handleActionList
}
blockFilter
blocks
previousEncodedOutput
=
do
...
...
@@ -181,16 +181,16 @@ runBarConfiguration generateBarConfig options = do
-- Create and initialzie blocks
(
barUpdateChannel
,
barUpdateEvent
)
<-
createBarUpdateChannel
block
Producer
s
<-
toListM
$
generateBarConfig
barUpdateChannel
blocks
<-
toListM
$
generateBarConfig
barUpdateChannel
-- Attach spinner indicator when verbose flag is set
let
block
Producer
s'
=
if
indicator
options
then
(
renderIndicator
:
block
Producer
s
)
else
block
Producer
s
let
blocks'
=
if
indicator
options
then
(
renderIndicator
:
blocks
)
else
blocks
-- Create channel to send new block producers to render loop
newBlock
Producer
s
<-
newTChanIO
newBlocks
<-
newTChanIO
-- Send initial block producers to render loop
forM_
block
Producer
s'
$
\
bp
->
atomically
$
writeTChan
newBlock
Producer
s
bp
forM_
blocks'
$
\
bp
->
atomically
$
writeTChan
newBlocks
bp
-- Install signal handler for SIGCONT
installSignalHandlers
barUpdateChannel
...
...
@@ -208,7 +208,7 @@ runBarConfiguration generateBarConfig options = do
updateBar
barUpdateChannel
link
socketUpdateAsync
renderLoop
options
handle
barUpdateEvent
initialOutput
newBlock
Producer
s
renderLoop
options
handle
barUpdateEvent
initialOutput
newBlocks
createCommandChan
::
IO
CommandChan
createCommandChan
=
newTChanIO
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment