diff --git a/CHANGELOG.md b/CHANGELOG.md index 1167b9e1b..f133d5449 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Features: * Add `-c` as a shortcut of `--load-config`. Note it was used as the shortcut of `--color` before 2.0.5 * Support Windows Service Pack version detection (Kernel, Windows) * Support Debian point releases detection (OS, Linux) +* Add new module `NetUsage` which prints network throughput (usage) of specified interface. Note this module costs about 1 second to finish. Bugfixes: * Fix fastfetch hanging in specific environment (#561) diff --git a/README.md b/README.md index 2233edf42..5aefedd3a 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ All categories not listed here should work without needing a specific implementa ##### Available Modules ``` -Battery, Bios, Bluetooth, Board, Break, Brightness, Colors, Command, CPU, CPUUsage, Cursor, Custom, Date, DateTime, DE, Disk, Display, Font, Gamepad, GPU, Host, Icons, Kernel, LM, Locale, LocalIP, Media, Memory, Monitor, OpenCL, OpenGL, OS, Packages, Player, Power Adapter, Processes, PublicIP, Separator, Shell, Sound, Swap, Terminal, Terminal Font, Terminal Size, Theme, Time, Title, Uptime, Version, Vulkan, Wallpaper, Weather, Wifi, WM, WMTheme +Battery, Bios, Bluetooth, Board, Break, Brightness, Colors, Command, CPU, CPUUsage, Cursor, Custom, Date, DateTime, DE, Disk, Display, Font, Gamepad, GPU, Host, Icons, Kernel, LM, Locale, LocalIP, Media, Memory, Monitor, NetUsage, OpenCL, OpenGL, OS, Packages, Player, Power Adapter, Processes, PublicIP, Separator, Shell, Sound, Swap, Terminal, Terminal Font, Terminal Size, Theme, Time, Title, Uptime, Version, Vulkan, Wallpaper, Weather, Wifi, WM, WMTheme ``` ##### Builtin logos diff --git a/presets/all b/presets/all index 1841c47ca..804589d81 100644 --- a/presets/all +++ b/presets/all @@ -1 +1 @@ ---structure Title:Separator:OS:Host:Bios:Board:Chassis:Kernel:Uptime:Processes:Packages:Shell:Display:Brightness:Monitor:LM:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Wallpaper:Terminal:TerminalFont:TerminalSize:CPU:CPUUsage:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Media:PublicIP:LocalIP:Wifi:DateTime:Locale:Vulkan:OpenGL:OpenCL:Users:Bluetooth:Sound:Gamepad:Weather:Version:Break:Colors +--structure Title:Separator:OS:Host:Bios:Board:Chassis:Kernel:Uptime:Processes:Packages:Shell:Display:Brightness:Monitor:LM:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Wallpaper:Terminal:TerminalFont:TerminalSize:CPU:CPUUsage:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Media:PublicIP:LocalIP:Wifi:DateTime:Locale:Vulkan:OpenGL:OpenCL:Users:Bluetooth:Sound:Gamepad:Weather:NetUsage:Version:Break:Colors diff --git a/presets/all.jsonc b/presets/all.jsonc index b3e9c30d9..27c9f6d42 100644 --- a/presets/all.jsonc +++ b/presets/all.jsonc @@ -51,6 +51,7 @@ "sound", "gamepad", "weather", + "netusage", "version", "break", "colors" diff --git a/src/data/config_user.txt b/src/data/config_user.txt index 9d3be5796..aed51c723 100644 --- a/src/data/config_user.txt +++ b/src/data/config_user.txt @@ -370,6 +370,7 @@ #--lm-key LM #--locale-key Locale #--localip-key Local IP ({1}) +#--netusage-key Net Usage ({1}) #--publicip-key Public IP #--wifi-key Wifi #--weather-key Weather @@ -422,6 +423,7 @@ #--lm-format #--locale-format #--localip-format +#--netusage-format #--publicip-format #--weather-format #--monitor-format @@ -471,6 +473,7 @@ #--lm-key-color #--locale-key-color #--localip-key-color +#--netusage-key-color #--publicip-key-color #--weather-key-color #--monitor-key-color diff --git a/src/data/help.txt b/src/data/help.txt index eb975f786..36617c00a 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -147,9 +147,11 @@ Module specific options: --localip-show-ipv6 : Show IPv6 addresses in local ip module. Default is false --localip-show-mac : Show mac addresses in local ip module. Default is false --localip-show-loop : Show loop back addresses (127.0.0.1) in local ip module. Default is false - --localip-name-prefix : Show IPs with given name prefix only. Default is empty - --localip-default-route-only : Show ips that are used for default routing only. Default is false + --localip-name-prefix : Show interfaces with given interface name prefix only. Default is empty + --localip-default-route-only : Show the interface that is used for default routing only. Default is false --localip-compact : Show all IPs in one line. Default is false + --netusage-name-prefix : Show interfaces with given name prefix only. Default is empty + --netusage-default-route-only : Show the interfac that is used for default routing only. Default is false --publicip-timeout: Time in milliseconds to wait for the public ip server to respond. Default is disabled (0) --publicip-url: The URL of public IP detection server to be used. --weather-location: Set the location to be used. It must be URI encoded (eg a whitespace must be encoded as `+`). diff --git a/src/fastfetch.c b/src/fastfetch.c index eafb1de61..bdd2fdf52 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -381,18 +381,31 @@ static inline void printCommandHelp(const char* command) "Locale code" ); } - else if(ffStrEqualsIgnCase(command, "local-ip-format")) + else if(ffStrEqualsIgnCase(command, "localip-format")) { - constructAndPrintCommandHelpFormat("local-ip", "{}", 1, - "Local IP address" + constructAndPrintCommandHelpFormat("localip", "{}", 5, + "Local IPv4 address", + "Local IPv6 address", + "Physical (MAC) address", + "Interface name", + "Is default route" ); } - else if(ffStrEqualsIgnCase(command, "public-ip-format")) + else if(ffStrEqualsIgnCase(command, "publicip-format")) { - constructAndPrintCommandHelpFormat("public-ip", "{}", 1, + constructAndPrintCommandHelpFormat("publicip", "{}", 1, "Public IP address" ); } + else if(ffStrEqualsIgnCase(command, "netusage-format")) + { + constructAndPrintCommandHelpFormat("netusage", "{}", 3, + "Size of data received per second (formatted)", + "Size of data sent per second (formatted)", + "Interface name", + "Is default route" + ); + } else if(ffStrEqualsIgnCase(command, "wifi-format")) { constructAndPrintCommandHelpFormat("wifi", "{4} - {6}", 3, diff --git a/src/modules/localip/localip.c b/src/modules/localip/localip.c index c96b09806..36013d505 100644 --- a/src/modules/localip/localip.c +++ b/src/modules/localip/localip.c @@ -5,7 +5,7 @@ #include "util/stringUtils.h" #define FF_LOCALIP_DISPLAY_NAME "Local IP" -#define FF_LOCALIP_NUM_FORMAT_ARGS 2 +#define FF_LOCALIP_NUM_FORMAT_ARGS 5 #pragma GCC diagnostic ignored "-Wsign-conversion" static int sortIps(const FFLocalIpResult* left, const FFLocalIpResult* right) diff --git a/src/modules/netusage/netusage.c b/src/modules/netusage/netusage.c index 75e0bfdf2..2ae67a704 100644 --- a/src/modules/netusage/netusage.c +++ b/src/modules/netusage/netusage.c @@ -6,7 +6,7 @@ #include "util/stringUtils.h" #define FF_NETUSAGE_DISPLAY_NAME "Net Usage" -#define FF_NETUSAGE_NUM_FORMAT_ARGS 1 +#define FF_NETUSAGE_NUM_FORMAT_ARGS 12 static int sortInfs(const FFNetUsageIoCounters* left, const FFNetUsageIoCounters* right) { @@ -71,11 +71,15 @@ void ffPrintNetUsage(FFNetUsageOptions* options) { ffStrbufClear(&buffer2); ffParseSize(inf->rxBytes, &buffer); + ffStrbufAppendS(&buffer, "/s"); ffParseSize(inf->txBytes, &buffer2); + ffStrbufAppendS(&buffer2, "/s"); + ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_NETUSAGE_NUM_FORMAT_ARGS, (FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &inf->name}, {FF_FORMAT_ARG_TYPE_STRBUF, &buffer}, {FF_FORMAT_ARG_TYPE_STRBUF, &buffer2}, + {FF_FORMAT_ARG_TYPE_STRBUF, &inf->name}, + {FF_FORMAT_ARG_TYPE_BOOL, &inf->defaultRoute}, {FF_FORMAT_ARG_TYPE_UINT64, &inf->txBytes}, {FF_FORMAT_ARG_TYPE_UINT64, &inf->rxBytes}, {FF_FORMAT_ARG_TYPE_UINT64, &inf->txPackets}, @@ -84,7 +88,6 @@ void ffPrintNetUsage(FFNetUsageOptions* options) {FF_FORMAT_ARG_TYPE_UINT64, &inf->txErrors}, {FF_FORMAT_ARG_TYPE_UINT64, &inf->rxDrops}, {FF_FORMAT_ARG_TYPE_UINT64, &inf->txDrops}, - {FF_FORMAT_ARG_TYPE_BOOL, &inf->defaultRoute}, }); } ++index; @@ -178,6 +181,7 @@ void ffGenerateNetUsageJson(FFNetUsageOptions* options, yyjson_mut_doc* doc, yyj { yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr); yyjson_mut_obj_add_strbuf(doc, obj, "name", &counter->name); + yyjson_mut_obj_add_bool(doc, obj, "defaultRoute", counter->defaultRoute); yyjson_mut_obj_add_uint(doc, obj, "txBytes", counter->txBytes); yyjson_mut_obj_add_uint(doc, obj, "rxBytes", counter->rxBytes); yyjson_mut_obj_add_uint(doc, obj, "txPackets", counter->txPackets); @@ -186,7 +190,6 @@ void ffGenerateNetUsageJson(FFNetUsageOptions* options, yyjson_mut_doc* doc, yyj yyjson_mut_obj_add_uint(doc, obj, "txErrors", counter->txErrors); yyjson_mut_obj_add_uint(doc, obj, "rxDrops", counter->rxDrops); yyjson_mut_obj_add_uint(doc, obj, "txDrops", counter->txDrops); - yyjson_mut_obj_add_bool(doc, obj, "defaultRoute", counter->defaultRoute); } FF_LIST_FOR_EACH(FFNetUsageIoCounters, inf, result)