|
1 | 1 | #include "fastfetch.h" |
2 | 2 | #include "common/parsing.h" |
| 3 | +#include "util/textModifier.h" |
3 | 4 |
|
4 | 5 | #include <ctype.h> |
5 | 6 | #include <inttypes.h> |
@@ -98,18 +99,39 @@ void ffParseSize(uint64_t bytes, FFstrbuf* result) |
98 | 99 |
|
99 | 100 | void ffParseTemperature(double celsius, FFstrbuf* buffer) |
100 | 101 | { |
101 | | - switch (instance.config.display.temperatureUnit) |
| 102 | + if (celsius != celsius) // ignores NaN |
| 103 | + return; |
| 104 | + |
| 105 | + const FFOptionsDisplay* options = &instance.config.display; |
| 106 | + const char* colorGreen = options->temperatureColorGreen.chars; |
| 107 | + const char* colorYellow = options->temperatureColorYellow.chars; |
| 108 | + const char* colorRed = options->temperatureColorRed.chars; |
| 109 | + |
| 110 | + if (!options->pipe) |
| 111 | + { |
| 112 | + if (celsius < 50) |
| 113 | + ffStrbufAppendF(buffer, "\e[%sm", colorGreen); |
| 114 | + else if (celsius < 80) |
| 115 | + ffStrbufAppendF(buffer, "\e[%sm", colorYellow); |
| 116 | + else |
| 117 | + ffStrbufAppendF(buffer, "\e[%sm", colorRed); |
| 118 | + } |
| 119 | + |
| 120 | + switch (options->temperatureUnit) |
102 | 121 | { |
103 | 122 | case FF_TEMPERATURE_UNIT_CELSIUS: |
104 | | - ffStrbufAppendF(buffer, "%.1f°C", celsius); |
| 123 | + ffStrbufAppendF(buffer, "%.*f°C", options->temperatureNdigits, celsius); |
105 | 124 | break; |
106 | 125 | case FF_TEMPERATURE_UNIT_FAHRENHEIT: |
107 | | - ffStrbufAppendF(buffer, "%.1f°F", celsius * 1.8 + 32); |
| 126 | + ffStrbufAppendF(buffer, "%.*f°F", options->temperatureNdigits, celsius * 1.8 + 32); |
108 | 127 | break; |
109 | 128 | case FF_TEMPERATURE_UNIT_KELVIN: |
110 | | - ffStrbufAppendF(buffer, "%.1f K", celsius + 273.15); |
| 129 | + ffStrbufAppendF(buffer, "%.*f K", options->temperatureNdigits, celsius + 273.15); |
111 | 130 | break; |
112 | 131 | } |
| 132 | + |
| 133 | + if (!options->pipe) |
| 134 | + ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); |
113 | 135 | } |
114 | 136 |
|
115 | 137 | void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, const FFstrbuf* gtk4) |
|
0 commit comments