Compare commits

...

7 Commits

Author SHA1 Message Date
李通洲 7eb1f616d9 LocalIP (Windows): detect gateway ip 2024-03-05 10:59:05 +08:00
李通洲 b9dbb66bd7 fastfetch: revert changes of FASTFETCH_DATATEXT_STRUCTURE
Also add comments
2024-03-04 13:47:17 +08:00
李通洲 a01792c06c Doc: rename help.txt to help_footer.txt 2024-03-04 10:22:29 +08:00
李通洲 d707a67f89 Merge remote-tracking branch 'origin/master' into dev 2024-03-04 09:14:11 +08:00
李通洲 5d8aa11d81 Fastfetch: small performace optimization 2024-03-04 08:50:38 +08:00
李通洲 a87463fc09 Doc: fix truncated texts 2024-03-04 08:50:38 +08:00
李通洲 d0a4a012c4 Completions (Fish): fix old version compatibility
Fix #744
2024-03-03 18:48:05 +08:00
12 changed files with 80 additions and 30 deletions
+1 -2
View File
@@ -233,10 +233,9 @@ endif()
fastfetch_encode_c_string("${DATATEXT_JSON_HELP}" DATATEXT_JSON_HELP)
fastfetch_load_text(src/data/structure.txt DATATEXT_STRUCTURE)
fastfetch_load_text(src/data/help.txt DATATEXT_HELP)
fastfetch_load_text(src/data/help_footer.txt DATATEXT_HELP_FOOTER)
fastfetch_load_text(src/data/help_color.txt DATATEXT_HELP_COLOR)
fastfetch_load_text(src/data/help_format.txt DATATEXT_HELP_FORMAT)
fastfetch_load_text(src/data/help_config.txt DATATEXT_HELP_CONFIG)
configure_file(src/fastfetch_config.h.in fastfetch_config.h @ONLY)
configure_file(src/fastfetch_datatext.h.in fastfetch_datatext.h @ONLY)
+1 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env fish
if not type -q fastfetch
return
exit
end
complete -c fastfetch -f
+2 -2
View File
@@ -26,7 +26,7 @@ void ffPrepareCommandOption(FFdata* data)
FFOptionsModules* const options = &instance.config.modules;
//If we don't have a custom structure, use the default one
if(data->structure.length == 0)
ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE);
ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE); // Cannot use `ffStrbufSetStatic` here because we will modify the string
if(ffStrbufContainIgnCaseS(&data->structure, FF_CPUUSAGE_MODULE_NAME))
ffPrepareCPUUsage();
@@ -168,7 +168,7 @@ void ffMigrateCommandOptionToJsonc(FFdata* data, yyjson_mut_doc* jsonDoc)
{
//If we don't have a custom structure, use the default one
if(data->structure.length == 0)
ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE);
ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE); // Cannot use `ffStrbufSetStatic` here because we will modify the string
//Parse the structure and call the modules
uint32_t startIndex = 0;
-8
View File
@@ -1,8 +0,0 @@
Usage: fastfetch -c <file>
Loads a config file. A config file contains one flag per line. Empty lines or lines starting with # are ignored.
If the file is relative it looks in the following order:
- relative to the current working directory
- relative to ~/.local/share/fastfetch/presets/
- relative to /usr/share/fastfetch/presets/
Fastfetch provides some default presets. List them with "fastfetch --list-presets".
+6 -6
View File
@@ -1,15 +1,15 @@
A format string is a string that contains placeholders for values.
These placeholders begin with a '{', containing the index of the value, and end with a '}'.
For example the format string "Values: {1} ({2})", with the values "First" and "My second val", will produce
For example the format string "Values: {1} ({2})", with the values "First" and "My second val", will produce "Values: First (My second val)".
The format string can contain placeholders in any order and have multiple occurrences.
To include spaces when setting from the command line, surround the whole string with double quotes (").
If the value index is missing, meaning the placeholder is "{}", an internal counter sets the value index.
This means that the format string "Values: {1} ({2})" is equivalent to "Values: {} ({})".
Note that this counter only counts empty placeholders, so the format string "{2} {} {}" will contain the second v
Note that this counter only counts empty placeholders, so the format string "{2} {} {}" will contain the second value, then the first, and then the second again.
To make formatting easier, a double open curly brace ("{{") will be printed as a single open curly brace and not
If a value index is misformatted or wants a non-existing value, it will be printed as is, with the curly braces aro
To make formatting easier, a double open curly brace ("{{") will be printed as a single open curly brace and not counted as the beginning of a placeholder.
If a value index is misformatted or wants a non-existing value, it will be printed as is, with the curly braces around it.
If the last placeholder isn't closed, it will be treated like it was at the end of the format string.
To only print something if a variable is set, use "{?<index>} ... {?}".
@@ -17,7 +17,7 @@ For example, to only print a second value if it is set, use "{?2} Second value:
If a "{?}" is found without an opener, it is printed as is.
To only print something if a variable is not set, do the same as with if, just replace every '?' with a '!'.
For example to print a fallback for a second value if it is not set, use "{?2}{2}{?}{/2}Second value fallback{/}"
For example to print a fallback for a second value if it is not set, use "{?2}{2}{?}{/2}Second value fallback{/}".
To stop formatting at any point in the format string, use "{-}".
@@ -25,7 +25,7 @@ To print something with color, start a placeholder with a '#' and then the linux
"\033[" at the start, and an 'm' at the end is automatically added, so don't do that.
A "{#}" is equivalent to a "{#0}" and resets everything to normal.
For example to print something pink and underline, use "{#4;35}...{#}".
Information about what the numbers mean can be found here: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Sele
Information about what the numbers mean can be found here: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters.
Which escape codes are supported and how they look is defined by your terminal.
If a format string evaluates to an empty value, the whole line in the output will be discarded.
+2
View File
@@ -7,6 +7,8 @@ typedef struct FFLocalIpResult
FFstrbuf name;
FFstrbuf ipv4;
FFstrbuf ipv6;
FFstrbuf gateway4;
FFstrbuf gateway6;
FFstrbuf mac;
bool defaultRoute;
} FFLocalIpResult;
+29 -7
View File
@@ -6,7 +6,7 @@
#include "util/windows/unicode.h"
#include "localip.h"
static void addNewIp(FFlist* list, const char* name, const char* value, int type, bool newIp, bool defaultRoute)
static void addNewIp(FFlist* list, const char* name, const char* value, int type, bool newIp, bool gateway, bool defaultRoute)
{
FFLocalIpResult* ip = NULL;
@@ -17,6 +17,8 @@ static void addNewIp(FFlist* list, const char* name, const char* value, int type
ffStrbufInit(&ip->ipv4);
ffStrbufInit(&ip->ipv6);
ffStrbufInit(&ip->mac);
ffStrbufInit(&ip->gateway4);
ffStrbufInit(&ip->gateway6);
ip->defaultRoute = defaultRoute;
}
else
@@ -27,10 +29,10 @@ static void addNewIp(FFlist* list, const char* name, const char* value, int type
switch (type)
{
case AF_INET:
ffStrbufSetS(&ip->ipv4, value);
ffStrbufSetS(gateway ? &ip->gateway4 : &ip->ipv4, value);
break;
case AF_INET6:
ffStrbufSetS(&ip->ipv6, value);
ffStrbufSetS(gateway ? &ip->gateway6 : &ip->ipv6, value);
break;
case -1:
ffStrbufSetS(&ip->mac, value);
@@ -57,7 +59,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
options->showType & FF_LOCALIP_TYPE_IPV4_BIT
? options->showType & FF_LOCALIP_TYPE_IPV6_BIT ? AF_UNSPEC : AF_INET
: AF_INET6,
GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER,
GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER | (options->showType & FF_LOCALIP_TYPE_GATEWAY_BIT ? GAA_FLAG_INCLUDE_GATEWAYS : 0),
NULL,
adapter_addresses,
&adapter_addresses_buffer_size);
@@ -96,10 +98,30 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
uint8_t* ptr = adapter->PhysicalAddress;
snprintf(addressBuffer, sizeof(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
addNewIp(results, name, addressBuffer, -1, newIp, isDefaultRoute);
addNewIp(results, name, addressBuffer, -1, newIp, false, isDefaultRoute);
newIp = false;
}
for (IP_ADAPTER_GATEWAY_ADDRESS_LH* ifa = adapter->FirstGatewayAddress; ifa; ifa = ifa->Next)
{
if (ifa->Address.lpSockaddr->sa_family == AF_INET)
{
SOCKADDR_IN* ipv4 = (SOCKADDR_IN*) ifa->Address.lpSockaddr;
char addressBuffer[INET_ADDRSTRLEN + 4];
inet_ntop(AF_INET, &ipv4->sin_addr, addressBuffer, INET_ADDRSTRLEN);
addNewIp(results, name, addressBuffer, AF_INET, newIp, true, isDefaultRoute);
newIp = false;
}
else if (ifa->Address.lpSockaddr->sa_family == AF_INET6)
{
SOCKADDR_IN6* ipv6 = (SOCKADDR_IN6*) ifa->Address.lpSockaddr;
char addressBuffer[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &ipv6->sin6_addr, addressBuffer, INET6_ADDRSTRLEN);
addNewIp(results, name, addressBuffer, AF_INET6, newIp, true, isDefaultRoute);
newIp = false;
}
}
for (IP_ADAPTER_UNICAST_ADDRESS* ifa = adapter->FirstUnicastAddress; ifa; ifa = ifa->Next)
{
if (ifa->Address.lpSockaddr->sa_family == AF_INET)
@@ -114,7 +136,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
snprintf(addressBuffer + len, 4, "/%u", (unsigned) ifa->OnLinkPrefixLength);
}
addNewIp(results, name, addressBuffer, AF_INET, newIp, isDefaultRoute);
addNewIp(results, name, addressBuffer, AF_INET, newIp, false, isDefaultRoute);
newIp = false;
}
else if (ifa->Address.lpSockaddr->sa_family == AF_INET6)
@@ -122,7 +144,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
SOCKADDR_IN6* ipv6 = (SOCKADDR_IN6*) ifa->Address.lpSockaddr;
char addressBuffer[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &ipv6->sin6_addr, addressBuffer, INET6_ADDRSTRLEN);
addNewIp(results, name, addressBuffer, AF_INET6, newIp, isDefaultRoute);
addNewIp(results, name, addressBuffer, AF_INET6, newIp, false, isDefaultRoute);
newIp = false;
}
}
+1 -1
View File
@@ -135,7 +135,7 @@ static void printFullHelp()
}
yyjson_doc_free(doc);
puts("\n" FASTFETCH_DATATEXT_HELP);
puts("\n" FASTFETCH_DATATEXT_HELP_FOOTER);
}
static bool printSpecificCommandHelp(const char* command)
+1 -1
View File
@@ -5,7 +5,7 @@
#define FASTFETCH_DATATEXT_JSON_HELP @DATATEXT_JSON_HELP@
#define FASTFETCH_DATATEXT_STRUCTURE @DATATEXT_STRUCTURE@
#define FASTFETCH_DATATEXT_HELP @DATATEXT_HELP@
#define FASTFETCH_DATATEXT_HELP_FOOTER @DATATEXT_HELP_FOOTER@
#define FASTFETCH_DATATEXT_HELP_COLOR @DATATEXT_HELP_COLOR@
#define FASTFETCH_DATATEXT_HELP_FORMAT @DATATEXT_HELP_FORMAT@
#define FASTFETCH_DATATEXT_HELP_CONFIG @DATATEXT_HELP_CONFIG@
+36 -2
View File
@@ -5,7 +5,7 @@
#include "util/stringUtils.h"
#define FF_LOCALIP_DISPLAY_NAME "Local IP"
#define FF_LOCALIP_NUM_FORMAT_ARGS 5
#define FF_LOCALIP_NUM_FORMAT_ARGS 7
#pragma GCC diagnostic ignored "-Wsign-conversion"
static int sortIps(const FFLocalIpResult* left, const FFLocalIpResult* right)
@@ -40,12 +40,18 @@ static void printIp(FFLocalIpResult* ip, bool markDefaultRoute)
{
ffStrbufWriteTo(&ip->ipv4, stdout);
flag = true;
if (ip->gateway4.length)
printf(" [%s]", ip->gateway4.chars);
}
if (ip->ipv6.length)
{
if (flag) putchar(' ');
ffStrbufWriteTo(&ip->ipv6, stdout);
flag = true;
if (ip->gateway6.length)
printf(" [%s]", ip->gateway6.chars);
}
if (ip->mac.length)
{
@@ -116,6 +122,8 @@ void ffPrintLocalIp(FFLocalIpOptions* options)
{FF_FORMAT_ARG_TYPE_STRBUF, &ip->mac},
{FF_FORMAT_ARG_TYPE_STRBUF, &ip->name},
{FF_FORMAT_ARG_TYPE_BOOL, &ip->defaultRoute},
{FF_FORMAT_ARG_TYPE_STRBUF, &ip->gateway4},
{FF_FORMAT_ARG_TYPE_STRBUF, &ip->gateway6},
});
}
++index;
@@ -127,6 +135,8 @@ void ffPrintLocalIp(FFLocalIpOptions* options)
ffStrbufDestroy(&ip->name);
ffStrbufDestroy(&ip->ipv4);
ffStrbufDestroy(&ip->ipv6);
ffStrbufDestroy(&ip->gateway4);
ffStrbufDestroy(&ip->gateway6);
ffStrbufDestroy(&ip->mac);
}
}
@@ -165,6 +175,15 @@ bool ffParseLocalIpCommandOptions(FFLocalIpOptions* options, const char* key, co
return true;
}
if (ffStrEqualsIgnCase(subKey, "show-gateway"))
{
if (ffOptionParseBoolean(value))
options->showType |= FF_LOCALIP_TYPE_GATEWAY_BIT;
else
options->showType &= ~FF_LOCALIP_TYPE_GATEWAY_BIT;
return true;
}
if (ffStrEqualsIgnCase(subKey, "show-loop"))
{
if (ffOptionParseBoolean(value))
@@ -238,6 +257,15 @@ void ffParseLocalIpJsonObject(FFLocalIpOptions* options, yyjson_val* module)
continue;
}
if (ffStrEqualsIgnCase(key, "showGateway"))
{
if (yyjson_get_bool(val))
options->showType |= FF_LOCALIP_TYPE_GATEWAY_BIT;
else
options->showType &= ~FF_LOCALIP_TYPE_GATEWAY_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "showLoop"))
{
if (yyjson_get_bool(val))
@@ -329,6 +357,8 @@ void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjs
yyjson_mut_obj_add_bool(doc, obj, "defaultRoute", ip->defaultRoute);
yyjson_mut_obj_add_strbuf(doc, obj, "ipv4", &ip->ipv4);
yyjson_mut_obj_add_strbuf(doc, obj, "ipv6", &ip->ipv6);
yyjson_mut_obj_add_strbuf(doc, obj, "gateway4", &ip->gateway4);
yyjson_mut_obj_add_strbuf(doc, obj, "gateway6", &ip->gateway6);
yyjson_mut_obj_add_strbuf(doc, obj, "mac", &ip->mac);
yyjson_mut_obj_add_strbuf(doc, obj, "name", &ip->name);
}
@@ -339,6 +369,8 @@ exit:
ffStrbufDestroy(&ip->name);
ffStrbufDestroy(&ip->ipv4);
ffStrbufDestroy(&ip->ipv6);
ffStrbufDestroy(&ip->gateway4);
ffStrbufDestroy(&ip->gateway6);
ffStrbufDestroy(&ip->mac);
}
}
@@ -350,7 +382,9 @@ void ffPrintLocalIpHelpFormat(void)
"Local IPv6 address",
"Physical (MAC) address",
"Interface name",
"Is default route"
"Is default route",
"Gateway IPv4 address",
"Gateway IPv6 address",
});
}
+1
View File
@@ -11,6 +11,7 @@ typedef enum FFLocalIpType
FF_LOCALIP_TYPE_IPV4_BIT = 1 << 1,
FF_LOCALIP_TYPE_IPV6_BIT = 1 << 2,
FF_LOCALIP_TYPE_MAC_BIT = 1 << 3,
FF_LOCALIP_TYPE_GATEWAY_BIT = 1 << 4,
FF_LOCALIP_TYPE_COMPACT_BIT = 1 << 10,
} FFLocalIpType;