mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Weather: add option --weather-location
This commit is contained in:
@@ -25,6 +25,7 @@ Features:
|
||||
* Add option `--processing-timeout` to the timeout when waiting for child processes.
|
||||
* Public IP module prints the IP location if `--publicip-url` is not set (PublicIP)
|
||||
* Add option `--localip-default-route-only` (LocalIP)
|
||||
* Add option `--weather-location` (Weather)
|
||||
|
||||
Bugfixes:
|
||||
* Fix possible hanging (TerminalFont, #493)
|
||||
|
||||
@@ -1006,6 +1006,10 @@
|
||||
"type": {
|
||||
"const": "weather"
|
||||
},
|
||||
"location": {
|
||||
"title": "The location to display",
|
||||
"type": "string"
|
||||
},
|
||||
"timeout": {
|
||||
"title": "Time in milliseconds to wait for the weather server to respond",
|
||||
"type": "integer",
|
||||
|
||||
@@ -206,6 +206,11 @@
|
||||
# Default is 0 (disabled).
|
||||
#--publicip-timeout 0
|
||||
|
||||
# Weather location option:
|
||||
# Sets location to be used. It must be URI encoded.
|
||||
# Default is empty (guessing by public IP)
|
||||
#--weather-location "Location"
|
||||
|
||||
# Weather output format option:
|
||||
# Sets the weather format to be used. It must be URI encoded.
|
||||
# See: https://github.com/chubin/wttr.in#one-line-output
|
||||
|
||||
@@ -9,6 +9,7 @@ typedef struct FFWeatherOptions
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
|
||||
FFstrbuf location;
|
||||
FFstrbuf outputFormat;
|
||||
uint32_t timeout;
|
||||
} FFWeatherOptions;
|
||||
|
||||
@@ -11,7 +11,10 @@ static int status = -1;
|
||||
|
||||
void ffPrepareWeather(FFWeatherOptions* options)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/?format=");
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/");
|
||||
if (options->location.length)
|
||||
ffStrbufAppend(&path, &options->location);
|
||||
ffStrbufAppendS(&path, "?format=");
|
||||
ffStrbufAppend(&path, &options->outputFormat);
|
||||
status = ffNetworkingSendHttpRequest(&state, "wttr.in", path.chars, "User-Agent: curl/0.0.0\r\n");
|
||||
}
|
||||
@@ -55,6 +58,7 @@ void ffInitWeatherOptions(FFWeatherOptions* options)
|
||||
options->moduleName = FF_WEATHER_MODULE_NAME;
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
|
||||
ffStrbufInit(&options->location);
|
||||
ffStrbufInitS(&options->outputFormat, "%t+-+%C+(%l)");
|
||||
options->timeout = 0;
|
||||
}
|
||||
@@ -66,6 +70,12 @@ bool ffParseWeatherCommandOptions(FFWeatherOptions* options, const char* key, co
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
if (ffStrEqualsIgnCase(subKey, "location"))
|
||||
{
|
||||
ffOptionParseString(key, value, &options->location);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ffStrEqualsIgnCase(subKey, "output-format"))
|
||||
{
|
||||
ffOptionParseString(key, value, &options->outputFormat);
|
||||
@@ -106,6 +116,12 @@ void ffParseWeatherJsonObject(yyjson_val* module)
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
if (ffStrEqualsIgnCase(key, "location"))
|
||||
{
|
||||
ffStrbufSetS(&options.location, yyjson_get_str(val));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ffStrEqualsIgnCase(key, "outputFormat"))
|
||||
{
|
||||
ffStrbufSetS(&options.outputFormat, yyjson_get_str(val));
|
||||
|
||||
Reference in New Issue
Block a user