use format_placeholder for cpu_temperature
This commit is contained in:
parent
b61e959a58
commit
2ef1d7440a
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include "i3status.h"
|
#include "i3status.h"
|
||||||
|
|
||||||
|
#define STRING_SIZE 20
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -213,7 +215,6 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
|
|||||||
char *outwalk = buffer;
|
char *outwalk = buffer;
|
||||||
#ifdef THERMAL_ZONE
|
#ifdef THERMAL_ZONE
|
||||||
const char *selected_format = format;
|
const char *selected_format = format;
|
||||||
const char *walk;
|
|
||||||
bool colorful_output = false;
|
bool colorful_output = false;
|
||||||
char *thermal_zone;
|
char *thermal_zone;
|
||||||
temperature_t temperature;
|
temperature_t temperature;
|
||||||
@ -248,18 +249,13 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
|
|||||||
selected_format = format_above_threshold;
|
selected_format = format_above_threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (walk = selected_format; *walk != '\0'; walk++) {
|
char string_degrees[STRING_SIZE];
|
||||||
if (*walk != '%') {
|
snprintf(string_degrees, STRING_SIZE, "%s", temperature.formatted_value);
|
||||||
*(outwalk++) = *walk;
|
placeholder_t placeholders[] = {
|
||||||
|
{.name = "%degrees", .value = string_degrees}};
|
||||||
|
|
||||||
} else if (BEGINS_WITH(walk + 1, "degrees")) {
|
const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
|
||||||
outwalk += sprintf(outwalk, "%s", temperature.formatted_value);
|
buffer = format_placeholders(selected_format, &placeholders[0], num);
|
||||||
walk += strlen("degrees");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
*(outwalk++) = '%';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (colorful_output) {
|
if (colorful_output) {
|
||||||
END_COLOR;
|
END_COLOR;
|
||||||
@ -269,6 +265,7 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
|
|||||||
free(thermal_zone);
|
free(thermal_zone);
|
||||||
|
|
||||||
OUTPUT_FULL_TEXT(buffer);
|
OUTPUT_FULL_TEXT(buffer);
|
||||||
|
free(buffer);
|
||||||
return;
|
return;
|
||||||
error:
|
error:
|
||||||
free(thermal_zone);
|
free(thermal_zone);
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
I can %haz literal% % ?
|
10
testcases/020-percentliteral-cpu_temperature/i3status.conf
Normal file
10
testcases/020-percentliteral-cpu_temperature/i3status.conf
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
general {
|
||||||
|
output_format = "none"
|
||||||
|
}
|
||||||
|
|
||||||
|
order += "cpu_temperature 0"
|
||||||
|
|
||||||
|
cpu_temperature 0 {
|
||||||
|
format = "I can %haz literal% % ?"
|
||||||
|
path = "testcases/020-percentliteral-cpu_temperature/temp1_input"
|
||||||
|
}
|
1
testcases/020-percentliteral-cpu_temperature/temp1_input
Normal file
1
testcases/020-percentliteral-cpu_temperature/temp1_input
Normal file
@ -0,0 +1 @@
|
|||||||
|
37000
|
Loading…
Reference in New Issue
Block a user