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
8a00c483
Commit
8a00c483
authored
5 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Implement automatic blockName generation
parent
7bd7d908
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
+16
-3
16 additions, 3 deletions
src/QBar/Core.hs
src/QBar/DefaultConfig.hs
+4
-8
4 additions, 8 deletions
src/QBar/DefaultConfig.hs
with
20 additions
and
11 deletions
src/QBar/Core.hs
+
16
−
3
View file @
8a00c483
...
...
@@ -5,6 +5,7 @@ module QBar.Core where
import
QBar.BlockOutput
import
QBar.Time
import
QBar.Util
import
Control.Concurrent.Async
import
Control.Concurrent.Event
as
Event
...
...
@@ -17,6 +18,7 @@ import Control.Monad.Writer (WriterT)
import
Data.Aeson.TH
import
Data.Either
(
isRight
)
import
Data.Int
(
Int64
)
import
Data.Maybe
(
fromMaybe
)
import
qualified
Data.Text.Lazy
as
T
import
Pipes
import
Pipes.Concurrent
...
...
@@ -242,14 +244,25 @@ newCache'' = do
-- |Creates a cache from a push block.
cachePushBlock
::
PushBlock
->
BlockCache
cachePushBlock
pushBlock
=
newCache
$
()
<$
(
pushBlock
>->
updateBarP
)
cachePushBlock
pushBlock
=
newCache
$
()
<$
(
pushBlock
>->
updateBarP
>->
fixBlockName
>->
PP
.
map
(
\
a
->
[
a
])
)
where
updateBarP
::
Pipe
BlockUpdate
[
BlockState
]
BarIO
PushMode
updateBarP
::
Pipe
BlockUpdate
BlockState
BarIO
r
updateBarP
=
forever
$
do
(
state
,
reason
)
<-
await
yield
[
state
]
yield
state
updateBar
reason
-- |Sets 'blockName' to a random (but static) identifier if an event handler is set but the 'blockName' is not set.
fixBlockName
::
Pipe
BlockState
BlockState
BarIO
r
fixBlockName
=
do
defaultBlockName
<-
randomIdentifier
forever
$
do
state
<-
await
yield
$
if
hasEventHandler
state
then
(
_Just
.
_1
.
blockName
)
%~
(
Just
.
fromMaybe
defaultBlockName
)
$
state
else
state
modify
::
(
BlockOutput
->
BlockOutput
)
->
Pipe
BlockUpdate
BlockUpdate
BarIO
r
modify
x
=
PP
.
map
(
over
(
_1
.
_Just
.
_1
)
x
)
...
...
This diff is collapsed.
Click to expand it.
src/QBar/DefaultConfig.hs
+
4
−
8
View file @
8a00c483
...
...
@@ -6,16 +6,13 @@ import QBar.Core
import
Pipes
import
Control.Lens
defaultBarConfig
::
BarIO
()
defaultBarConfig
=
do
let
battery
=
batteryBlock
>->
modify
(
blockName
?~
"battery"
)
let
cpuUsage
=
cpuUsageBlock
1
>->
modify
((
blockName
?~
"cpuUsage"
)
.
addIcon
"💻
\xFE0E
"
)
let
cpuUsage
=
cpuUsageBlock
1
>->
modify
(
addIcon
"💻
\xFE0E
"
)
-- TODO: commented-out blocks should be added as soon as they are implemented in qbar
addBlock
dateBlock
addBlock
battery
addBlock
battery
Block
--addBlock volumeBlock
addBlock
cpuUsage
--addBlock ramUsageBlock
...
...
@@ -30,11 +27,10 @@ legacyBarConfig = do
let
ram
=
(
scriptBlock
$
blockLocation
"memory"
)
>->
modify
(
addIcon
"🐏
\xFE0E
"
)
>->
autoPadding
let
temperature
=
(
scriptBlock
$
blockLocation
"temperature"
)
>->
autoPadding
let
volumeBlock
=
persistentScriptBlock
$
blockLocation
"volume-pulseaudio -S -F3"
let
battery
=
batteryBlock
>->
modify
(
blockName
?~
"battery"
)
let
cpuUsage
=
cpuUsageBlock
1
>->
modify
((
blockName
?~
"cpuUsage"
)
.
addIcon
"💻
\xFE0E
"
)
let
cpuUsage
=
cpuUsageBlock
1
>->
modify
(
addIcon
"💻
\xFE0E
"
)
addBlock
dateBlock
addBlock
battery
addBlock
battery
Block
addBlock
volumeBlock
addBlock
temperature
addBlock
ram
...
...
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