mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
tag: add 'kbit' 'mbit' 'gbit' 'kibit' 'mibit' 'gibit' formatters
This commit is contained in:
parent
700bf5b28c
commit
981afaab86
2 changed files with 39 additions and 1 deletions
|
@ -100,6 +100,15 @@ be used.
|
||||||
: format
|
: format
|
||||||
: All tag types
|
: All tag types
|
||||||
: Same as *kb*, *mb* and *gb*, but divide by 1024^n instead of 1000^n.
|
: Same as *kb*, *mb* and *gb*, but divide by 1024^n instead of 1000^n.
|
||||||
|
| kbit, mbit, gbit
|
||||||
|
: format
|
||||||
|
: All tag types
|
||||||
|
: Renders a tag's value (in decimal) divided by 8\*1000, 8\*1000^2 or
|
||||||
|
8\*1000^3. Note: no unit suffix is appended
|
||||||
|
| kibit, mibit, gibit
|
||||||
|
: format
|
||||||
|
: All tag types
|
||||||
|
: Same as *kbit*, *mbit* and *gbit*, but divide by 8\*1024^n instead of 8\*1000^n.
|
||||||
| min
|
| min
|
||||||
: selector
|
: selector
|
||||||
: Range tags
|
: Range tags
|
||||||
|
|
31
tag.c
31
tag.c
|
@ -530,6 +530,7 @@ tags_expand_template(const char *template, const struct tag_set *tags)
|
||||||
|
|
||||||
int digits = 0;
|
int digits = 0;
|
||||||
int decimals = 2;
|
int decimals = 2;
|
||||||
|
bool use_byte = false;
|
||||||
bool zero_pad = false;
|
bool zero_pad = false;
|
||||||
char *point = NULL;
|
char *point = NULL;
|
||||||
|
|
||||||
|
@ -546,16 +547,40 @@ tags_expand_template(const char *template, const struct tag_set *tags)
|
||||||
format = FMT_BYTE;
|
format = FMT_BYTE;
|
||||||
else if (strcmp(tag_args[i], "kb") == 0)
|
else if (strcmp(tag_args[i], "kb") == 0)
|
||||||
format = FMT_KBYTE;
|
format = FMT_KBYTE;
|
||||||
|
else if (strcmp(tag_args[i], "kbit") == 0) {
|
||||||
|
format = FMT_KBYTE;
|
||||||
|
use_byte = true;
|
||||||
|
}
|
||||||
else if (strcmp(tag_args[i], "mb") == 0)
|
else if (strcmp(tag_args[i], "mb") == 0)
|
||||||
format = FMT_MBYTE;
|
format = FMT_MBYTE;
|
||||||
|
else if (strcmp(tag_args[i], "mbit") == 0) {
|
||||||
|
format = FMT_MBYTE;
|
||||||
|
use_byte = true;
|
||||||
|
}
|
||||||
else if (strcmp(tag_args[i], "gb") == 0)
|
else if (strcmp(tag_args[i], "gb") == 0)
|
||||||
format = FMT_GBYTE;
|
format = FMT_GBYTE;
|
||||||
|
else if (strcmp(tag_args[i], "gbit") == 0) {
|
||||||
|
format = FMT_GBYTE;
|
||||||
|
use_byte = true;
|
||||||
|
}
|
||||||
else if (strcmp(tag_args[i], "kib") == 0)
|
else if (strcmp(tag_args[i], "kib") == 0)
|
||||||
format = FMT_KIBYTE;
|
format = FMT_KIBYTE;
|
||||||
|
else if (strcmp(tag_args[i], "kibit") == 0) {
|
||||||
|
format = FMT_KIBYTE;
|
||||||
|
use_byte = true;
|
||||||
|
}
|
||||||
else if (strcmp(tag_args[i], "mib") == 0)
|
else if (strcmp(tag_args[i], "mib") == 0)
|
||||||
format = FMT_MIBYTE;
|
format = FMT_MIBYTE;
|
||||||
|
else if (strcmp(tag_args[i], "mibit") == 0) {
|
||||||
|
format = FMT_MIBYTE;
|
||||||
|
use_byte = true;
|
||||||
|
}
|
||||||
else if (strcmp(tag_args[i], "gib") == 0)
|
else if (strcmp(tag_args[i], "gib") == 0)
|
||||||
format = FMT_GIBYTE;
|
format = FMT_GIBYTE;
|
||||||
|
else if (strcmp(tag_args[i], "gibit") == 0) {
|
||||||
|
format = FMT_GIBYTE;
|
||||||
|
use_byte = true;
|
||||||
|
}
|
||||||
else if (strcmp(tag_args[i], "min") == 0)
|
else if (strcmp(tag_args[i], "min") == 0)
|
||||||
kind = VALUE_MIN;
|
kind = VALUE_MIN;
|
||||||
else if (strcmp(tag_args[i], "max") == 0)
|
else if (strcmp(tag_args[i], "max") == 0)
|
||||||
|
@ -644,7 +669,7 @@ tags_expand_template(const char *template, const struct tag_set *tags)
|
||||||
case FMT_KIBYTE:
|
case FMT_KIBYTE:
|
||||||
case FMT_MIBYTE:
|
case FMT_MIBYTE:
|
||||||
case FMT_GIBYTE: {
|
case FMT_GIBYTE: {
|
||||||
const long divider =
|
long divider =
|
||||||
format == FMT_BYTE
|
format == FMT_BYTE
|
||||||
? 8
|
? 8
|
||||||
: format == FMT_KBYTE
|
: format == FMT_KBYTE
|
||||||
|
@ -661,6 +686,10 @@ tags_expand_template(const char *template, const struct tag_set *tags)
|
||||||
? 1024 * 1024 * 1024
|
? 1024 * 1024 * 1024
|
||||||
: 1;
|
: 1;
|
||||||
|
|
||||||
|
if (use_byte) {
|
||||||
|
divider *= 8;
|
||||||
|
}
|
||||||
|
|
||||||
char str[24];
|
char str[24];
|
||||||
if (tag->type(tag) == TAG_TYPE_FLOAT) {
|
if (tag->type(tag) == TAG_TYPE_FLOAT) {
|
||||||
const char *fmt = zero_pad ? "%0*.*f" : "%*.*f";
|
const char *fmt = zero_pad ? "%0*.*f" : "%*.*f";
|
||||||
|
|
Loading…
Add table
Reference in a new issue