mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-23 04:25:42 +02:00
tag: add support for "min", "max" and "unit" tag arguments
This commit is contained in:
parent
7936e197af
commit
a0ecc1ff03
1 changed files with 21 additions and 2 deletions
19
tag.c
19
tag.c
|
@ -450,8 +450,27 @@ tags_expand_template(const char *template, const struct tag_set *tags)
|
|||
sbuf_append_at_most(&formatted, template, begin - template);
|
||||
|
||||
/* Copy tag value */
|
||||
if (tag_arg == NULL) {
|
||||
const char *value = tag->as_string(tag);
|
||||
sbuf_append(&formatted, value);
|
||||
} else if (strcmp(tag_arg, "min") == 0 ||
|
||||
strcmp(tag_arg, "max") == 0)
|
||||
{
|
||||
long value = strcmp(tag_arg, "min") == 0 ? tag->min(tag) : tag->max(tag);
|
||||
char str[24];
|
||||
snprintf(str, sizeof(str), "%ld", value);
|
||||
sbuf_append(&formatted, str);
|
||||
} else if (strcmp(tag_arg, "unit") == 0) {
|
||||
const char *value = NULL;
|
||||
|
||||
switch (tag->realtime(tag)) {
|
||||
case TAG_REALTIME_NONE: value = ""; break;
|
||||
case TAG_REALTIME_SECS: value = "s"; break;
|
||||
case TAG_REALTIME_MSECS: value = "ms"; break;
|
||||
}
|
||||
|
||||
sbuf_append(&formatted, value);
|
||||
}
|
||||
|
||||
/* Skip past tag name + closing '}' */
|
||||
template = end + 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue