mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-01 06:11:49 +00:00
convert to_bytes to callbacks.print
This commit is contained in:
parent
8da8b26ddf
commit
dc0af635d6
17
src/common.c
17
src/common.c
@ -743,3 +743,20 @@ void print_battery_short(struct text_object *obj, char *p, int p_max_size)
|
|||||||
get_battery_short_status(p, p_max_size, obj->data.s);
|
get_battery_short_status(p, p_max_size, obj->data.s);
|
||||||
}
|
}
|
||||||
#endif /* !__OpenBSD__ */
|
#endif /* !__OpenBSD__ */
|
||||||
|
|
||||||
|
void print_to_bytes(struct text_object *obj, char *p, int p_max_size)
|
||||||
|
{
|
||||||
|
char buf[max_user_text];
|
||||||
|
long long bytes;
|
||||||
|
char unit[16]; // 16 because we can also have long names (like mega-bytes)
|
||||||
|
|
||||||
|
generate_text_internal(buf, max_user_text, *obj->sub, &info);
|
||||||
|
if(sscanf(buf, "%lli%s", &bytes, unit) == 2 && strlen(unit) < 16){
|
||||||
|
if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes);
|
||||||
|
else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024);
|
||||||
|
else if(strncasecmp("m", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024);
|
||||||
|
else if(strncasecmp("g", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024);
|
||||||
|
else if(strncasecmp("t", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024 * 1024);
|
||||||
|
}
|
||||||
|
snprintf(p, p_max_size, "%s", buf);
|
||||||
|
}
|
||||||
|
@ -125,4 +125,6 @@ uint8_t battery_percentage(struct text_object *);
|
|||||||
void print_battery_short(struct text_object *, char *, int);
|
void print_battery_short(struct text_object *, char *, int);
|
||||||
#endif /* !__OpenBSD__ */
|
#endif /* !__OpenBSD__ */
|
||||||
|
|
||||||
|
void print_to_bytes(struct text_object *, char *, int);
|
||||||
|
|
||||||
#endif /* _COMMON_H */
|
#endif /* _COMMON_H */
|
||||||
|
15
src/conky.c
15
src/conky.c
@ -1166,21 +1166,6 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OBJ(to_bytes) {
|
|
||||||
char buf[max_user_text];
|
|
||||||
long long bytes;
|
|
||||||
char unit[16]; // 16 because we can also have long names (like mega-bytes)
|
|
||||||
|
|
||||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
|
||||||
if(sscanf(buf, "%lli%s", &bytes, unit) == 2 && strlen(unit) < 16){
|
|
||||||
if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes);
|
|
||||||
else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024);
|
|
||||||
else if(strncasecmp("m", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024);
|
|
||||||
else if(strncasecmp("g", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024);
|
|
||||||
else if(strncasecmp("t", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024 * 1024);
|
|
||||||
}
|
|
||||||
snprintf(p, p_max_size, "%s", buf);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#undef DO_JUMP
|
#undef DO_JUMP
|
||||||
|
@ -1461,6 +1461,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
END OBJ_ARG(to_bytes, 0, "to_bytes needs a argument")
|
END OBJ_ARG(to_bytes, 0, "to_bytes needs a argument")
|
||||||
obj->sub = malloc(sizeof(struct text_object));
|
obj->sub = malloc(sizeof(struct text_object));
|
||||||
extract_variable_text_internal(obj->sub, arg);
|
extract_variable_text_internal(obj->sub, arg);
|
||||||
|
obj->callbacks.print = &print_to_bytes;
|
||||||
END OBJ(scroll, 0)
|
END OBJ(scroll, 0)
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
/* allocate a follower to reset any color changes */
|
/* allocate a follower to reset any color changes */
|
||||||
|
Loading…
Reference in New Issue
Block a user