Skip to content

Commit ba78859

Browse files
committed
Weather: honor display.temp.unit
Fix #1560
1 parent a8afd05 commit ba78859

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

doc/json_schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@
817817
"unit": {
818818
"type": "string",
819819
"description": "Set the unit of the temperature",
820-
"enum": ["CELSIUS", "C", "FAHRENHEIT", "F", "KELVIN", "K"],
821-
"default": "C"
820+
"enum": ["D", "Default", "Celsius", "C", "Fahrenheit", "F", "Kelvin", "K"],
821+
"default": "D"
822822
},
823823
"ndigits": {
824824
"type": "integer",

src/common/temps.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void ffTempsAppendNum(double celsius, FFstrbuf* buffer, FFColorRangeConfig confi
3939

4040
switch (options->tempUnit)
4141
{
42+
case FF_TEMPERATURE_UNIT_DEFAULT:
4243
case FF_TEMPERATURE_UNIT_CELSIUS:
4344
ffStrbufAppendF(buffer, "%.*f°C", options->tempNdigits, celsius);
4445
break;

src/data/help.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,12 @@
722722
"arg": {
723723
"type": "enum",
724724
"enum": {
725+
"D": "Default",
725726
"C": "Celsius",
726727
"F": "Fahrenheit",
727728
"K": "Kelvin"
728729
},
729-
"default": "C"
730+
"default": "D"
730731
}
731732
},
732733
{

src/detection/weather/weather.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ void ffPrepareWeather(FFWeatherOptions* options)
1919
ffStrbufAppend(&path, &options->location);
2020
ffStrbufAppendS(&path, "?format=");
2121
ffStrbufAppend(&path, &options->outputFormat);
22+
switch (instance.config.display.tempUnit)
23+
{
24+
case FF_TEMPERATURE_UNIT_CELSIUS:
25+
ffStrbufAppendS(&path, "&m");
26+
break;
27+
case FF_TEMPERATURE_UNIT_FAHRENHEIT:
28+
ffStrbufAppendS(&path, "&u");
29+
break;
30+
default:
31+
break;
32+
}
2233
status = ffNetworkingSendHttpRequest(&state, "wttr.in", path.chars, "User-Agent: curl/0.0.0\r\n");
2334
}
2435

src/options/display.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
130130
{
131131
int value;
132132
const char* error = ffJsonConfigParseEnum(unit, &value, (FFKeyValuePair[]) {
133+
{ "DEFAULT", FF_TEMPERATURE_UNIT_DEFAULT },
134+
{ "D", FF_TEMPERATURE_UNIT_DEFAULT },
133135
{ "CELSIUS", FF_TEMPERATURE_UNIT_CELSIUS },
134136
{ "C", FF_TEMPERATURE_UNIT_CELSIUS },
135137
{ "FAHRENHEIT", FF_TEMPERATURE_UNIT_FAHRENHEIT },
@@ -418,6 +420,8 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key
418420
if(ffStrEqualsIgnCase(subkey, "unit"))
419421
{
420422
options->tempUnit = (FFTemperatureUnit) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
423+
{ "DEFAULT", FF_TEMPERATURE_UNIT_DEFAULT },
424+
{ "D", FF_TEMPERATURE_UNIT_DEFAULT },
421425
{ "CELSIUS", FF_TEMPERATURE_UNIT_CELSIUS },
422426
{ "C", FF_TEMPERATURE_UNIT_CELSIUS },
423427
{ "FAHRENHEIT", FF_TEMPERATURE_UNIT_FAHRENHEIT },
@@ -513,7 +517,7 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options)
513517
options->keyPaddingLeft = 0;
514518
options->keyType = FF_MODULE_KEY_TYPE_STRING;
515519

516-
options->tempUnit = FF_TEMPERATURE_UNIT_CELSIUS;
520+
options->tempUnit = FF_TEMPERATURE_UNIT_DEFAULT;
517521
options->tempNdigits = 1;
518522
ffStrbufInitStatic(&options->tempColorGreen, FF_COLOR_FG_GREEN);
519523
ffStrbufInitStatic(&options->tempColorYellow, instance.state.terminalLightTheme ? FF_COLOR_FG_YELLOW : FF_COLOR_FG_LIGHT_YELLOW);
@@ -643,6 +647,9 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do
643647
{
644648
switch (options->tempUnit)
645649
{
650+
case FF_TEMPERATURE_UNIT_DEFAULT:
651+
yyjson_mut_obj_add_str(doc, temperature, "unit", "DEFAULT");
652+
break;
646653
case FF_TEMPERATURE_UNIT_CELSIUS:
647654
yyjson_mut_obj_add_str(doc, obj, "unit", "C");
648655
break;

src/options/display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef enum __attribute__((__packed__)) FFSizeBinaryPrefixType
1111

1212
typedef enum __attribute__((__packed__)) FFTemperatureUnit
1313
{
14+
FF_TEMPERATURE_UNIT_DEFAULT,
1415
FF_TEMPERATURE_UNIT_CELSIUS,
1516
FF_TEMPERATURE_UNIT_FAHRENHEIT,
1617
FF_TEMPERATURE_UNIT_KELVIN,

0 commit comments

Comments
 (0)