forked from external/yambar
Implement conditions on tag
A condition is formed by: <tag> <op> <value> <tag> is the normal yambar tag. <op> is one of '==', '!=', '<', '<=', '>', or '>='. <value> is what you wish to compare it to. 'boolean' tags must be used directly. They falsehood is matched with '~': <tag> ~<tag> Finally, to match an empty string, one must use ' "" ': <tag> <op> ""
This commit is contained in:
parent
4496d82cfb
commit
2b103b7acd
11 changed files with 416 additions and 75 deletions
|
@ -67,10 +67,9 @@ bar:
|
|||
- foreign-toplevel:
|
||||
content:
|
||||
map:
|
||||
tag: activated
|
||||
values:
|
||||
false: {empty: {}}
|
||||
true:
|
||||
conditions:
|
||||
(activated == false): {empty: {}}
|
||||
(activated == true):
|
||||
- string: {text: "{app-id}: {title}"}
|
||||
```
|
||||
|
||||
|
|
|
@ -102,10 +102,9 @@ bar:
|
|||
content:
|
||||
"":
|
||||
map:
|
||||
tag: state
|
||||
default: {string: {text: "{name}"}}
|
||||
values:
|
||||
focused: {string: {text: "{name}*"}}
|
||||
conditions:
|
||||
(state == focused): {string: {text: "{name}*"}}
|
||||
current: { string: {text: "{application}: {title}"}}
|
||||
```
|
||||
|
||||
|
|
|
@ -74,13 +74,12 @@ bar:
|
|||
- removables:
|
||||
content:
|
||||
map:
|
||||
tag: mounted
|
||||
values:
|
||||
false:
|
||||
conditions:
|
||||
(mounted == false):
|
||||
string:
|
||||
on-click: udisksctl mount -b {device}
|
||||
text: "{label}"
|
||||
true:
|
||||
(mounted == true):
|
||||
string:
|
||||
on-click: udisksctl unmount -b {device}
|
||||
text: "{label}"
|
||||
|
|
|
@ -79,10 +79,9 @@ bar:
|
|||
title: {string: { text: "{seat} - {title}" }}
|
||||
content:
|
||||
map:
|
||||
tag: occupied
|
||||
values:
|
||||
false: {empty: {}}
|
||||
true:
|
||||
conditions:
|
||||
(occupied == false): {empty: {}}
|
||||
(occupied == true):
|
||||
string:
|
||||
margin: 5
|
||||
text: "{id}: {state}"
|
||||
|
|
|
@ -133,10 +133,9 @@ bar:
|
|||
title|string|{{title}}
|
||||
content:
|
||||
map:
|
||||
tag: status
|
||||
values:
|
||||
Paused: {empty: {}}
|
||||
Playing:
|
||||
conditions:
|
||||
(status == Paused): {empty: {}}
|
||||
(status == Playing):
|
||||
content: {string: {text: "{artist} - {title}"}}
|
||||
```
|
||||
|
||||
|
|
|
@ -68,20 +68,17 @@ in red.
|
|||
```
|
||||
content:
|
||||
map:
|
||||
tag: carrier
|
||||
values:
|
||||
false: {empty: {}}
|
||||
true:
|
||||
conditions:
|
||||
(carrier == false): {empty: {}}
|
||||
(carrier == true):
|
||||
map:
|
||||
tag: state
|
||||
default: {string: {text: , font: *awesome, foreground: ffffff66}}
|
||||
values:
|
||||
up:
|
||||
conditions:
|
||||
(state == up):
|
||||
map:
|
||||
tag: ipv4
|
||||
default: {string: {text: , font: *awesome}}
|
||||
values:
|
||||
"": {string: {text: , font: *awesome, foreground: ffffff66}}
|
||||
conditions:
|
||||
(ipv4 == ""): {string: {text: , font: *awesome, foreground: ffffff66}}
|
||||
```
|
||||
|
||||
## Use yaml anchors
|
||||
|
|
|
@ -208,7 +208,37 @@ content:
|
|||
# MAP
|
||||
|
||||
This particle maps the values of a specific tag to different
|
||||
particles. In addition to explicit tag values, you can also specify a
|
||||
particles based on conditions. A condition takes the form of:
|
||||
|
||||
<tag> <operation> <value>
|
||||
|
||||
Where <tag> is the tag you would like to map, <operation> is one of:
|
||||
|
||||
[- ==
|
||||
:- !=
|
||||
:- >=
|
||||
:- >
|
||||
:- <=
|
||||
:- <
|
||||
|
||||
and <value> is the value you would like to compare it to. Conditions
|
||||
may be chained together using either '&&' or '||':
|
||||
|
||||
<condition1> && <condition2>
|
||||
|
||||
You may surround the *whole expression* with parenthesis to make it
|
||||
more readable:
|
||||
|
||||
(<condition1> && <condition2>)
|
||||
|
||||
Note that "nested" conditions are *NOT* supported. That is, something
|
||||
like (<condition1> && (<condition2> || <condition3>)) will *NOT* work.
|
||||
|
||||
Furthermore, *conditions are evaluated with a strcmp*. This means
|
||||
some odd behaviour may arise if prefixes (such as zeroes) are added
|
||||
to numerical constants.
|
||||
|
||||
In addition to explicit tag values, you can also specify a
|
||||
default/fallback particle.
|
||||
|
||||
## CONFIGURATION
|
||||
|
@ -217,34 +247,29 @@ default/fallback particle.
|
|||
:[ *Type*
|
||||
:[ *Req*
|
||||
:[ *Description*
|
||||
| tag
|
||||
: string
|
||||
: yes
|
||||
: The tag (name of) which values should be mapped
|
||||
| values
|
||||
| conditions
|
||||
: associative array
|
||||
: yes
|
||||
: An associative array of tag values mapped to particles
|
||||
: An associative array of conditions (see above) mapped to particles
|
||||
| default
|
||||
: particle
|
||||
: no
|
||||
: Default particle to use, when tag's value does not match any of the
|
||||
mapped values.
|
||||
: Default particle to use, none of the conditions are true
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
```
|
||||
content:
|
||||
map:
|
||||
tag: tag_name
|
||||
default:
|
||||
string:
|
||||
text: this is the default particle; the tag's value is now {tag_name}
|
||||
values:
|
||||
one_value:
|
||||
# Note, below, how the parenthesis are optional
|
||||
conditions:
|
||||
(tag == one_value):
|
||||
string:
|
||||
text: tag's value is now one_value
|
||||
another_value:
|
||||
tag == another_value:
|
||||
string:
|
||||
text: tag's value is now another_value
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue