Skip to content

Commit b4f2991

Browse files
committed
NetUsage: finish docs
1 parent b29b78b commit b4f2991

File tree

9 files changed

+38
-15
lines changed

9 files changed

+38
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Features:
2727
* Add `-c` as a shortcut of `--load-config`. Note it was used as the shortcut of `--color` before 2.0.5
2828
* Support Windows Service Pack version detection (Kernel, Windows)
2929
* Support Debian point releases detection (OS, Linux)
30+
* Add new module `NetUsage` which prints network throughput (usage) of specified interface. Note this module costs about 1 second to finish.
3031

3132
Bugfixes:
3233
* Fix fastfetch hanging in specific environment (#561)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ All categories not listed here should work without needing a specific implementa
108108

109109
##### Available Modules
110110
```
111-
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
111+
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
112112
```
113113

114114
##### Builtin logos

presets/all

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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
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:NetUsage:Version:Break:Colors

presets/all.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"sound",
5252
"gamepad",
5353
"weather",
54+
"netusage",
5455
"version",
5556
"break",
5657
"colors"

src/data/config_user.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@
370370
#--lm-key LM
371371
#--locale-key Locale
372372
#--localip-key Local IP ({1})
373+
#--netusage-key Net Usage ({1})
373374
#--publicip-key Public IP
374375
#--wifi-key Wifi
375376
#--weather-key Weather
@@ -422,6 +423,7 @@
422423
#--lm-format
423424
#--locale-format
424425
#--localip-format
426+
#--netusage-format
425427
#--publicip-format
426428
#--weather-format
427429
#--monitor-format
@@ -471,6 +473,7 @@
471473
#--lm-key-color
472474
#--locale-key-color
473475
#--localip-key-color
476+
#--netusage-key-color
474477
#--publicip-key-color
475478
#--weather-key-color
476479
#--monitor-key-color

src/data/help.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,11 @@ Module specific options:
147147
--localip-show-ipv6 <?value>: Show IPv6 addresses in local ip module. Default is false
148148
--localip-show-mac <?value>: Show mac addresses in local ip module. Default is false
149149
--localip-show-loop <?value>: Show loop back addresses (127.0.0.1) in local ip module. Default is false
150-
--localip-name-prefix <str>: Show IPs with given name prefix only. Default is empty
151-
--localip-default-route-only <?value>: Show ips that are used for default routing only. Default is false
150+
--localip-name-prefix <str>: Show interfaces with given interface name prefix only. Default is empty
151+
--localip-default-route-only <?value>: Show the interface that is used for default routing only. Default is false
152152
--localip-compact <?value>: Show all IPs in one line. Default is false
153+
--netusage-name-prefix <str>: Show interfaces with given name prefix only. Default is empty
154+
--netusage-default-route-only <?value>: Show the interfac that is used for default routing only. Default is false
153155
--publicip-timeout: Time in milliseconds to wait for the public ip server to respond. Default is disabled (0)
154156
--publicip-url: The URL of public IP detection server to be used.
155157
--weather-location: Set the location to be used. It must be URI encoded (eg a whitespace must be encoded as `+`).

src/fastfetch.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,18 +381,31 @@ static inline void printCommandHelp(const char* command)
381381
"Locale code"
382382
);
383383
}
384-
else if(ffStrEqualsIgnCase(command, "local-ip-format"))
385-
{
386-
constructAndPrintCommandHelpFormat("local-ip", "{}", 1,
387-
"Local IP address"
384+
else if(ffStrEqualsIgnCase(command, "localip-format"))
385+
{
386+
constructAndPrintCommandHelpFormat("localip", "{}", 5,
387+
"Local IPv4 address",
388+
"Local IPv6 address",
389+
"Physical (MAC) address",
390+
"Interface name",
391+
"Is default route"
388392
);
389393
}
390-
else if(ffStrEqualsIgnCase(command, "public-ip-format"))
394+
else if(ffStrEqualsIgnCase(command, "publicip-format"))
391395
{
392-
constructAndPrintCommandHelpFormat("public-ip", "{}", 1,
396+
constructAndPrintCommandHelpFormat("publicip", "{}", 1,
393397
"Public IP address"
394398
);
395399
}
400+
else if(ffStrEqualsIgnCase(command, "netusage-format"))
401+
{
402+
constructAndPrintCommandHelpFormat("netusage", "{}", 3,
403+
"Size of data received per second (formatted)",
404+
"Size of data sent per second (formatted)",
405+
"Interface name",
406+
"Is default route"
407+
);
408+
}
396409
else if(ffStrEqualsIgnCase(command, "wifi-format"))
397410
{
398411
constructAndPrintCommandHelpFormat("wifi", "{4} - {6}", 3,

src/modules/localip/localip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "util/stringUtils.h"
66

77
#define FF_LOCALIP_DISPLAY_NAME "Local IP"
8-
#define FF_LOCALIP_NUM_FORMAT_ARGS 2
8+
#define FF_LOCALIP_NUM_FORMAT_ARGS 5
99
#pragma GCC diagnostic ignored "-Wsign-conversion"
1010

1111
static int sortIps(const FFLocalIpResult* left, const FFLocalIpResult* right)

src/modules/netusage/netusage.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "util/stringUtils.h"
77

88
#define FF_NETUSAGE_DISPLAY_NAME "Net Usage"
9-
#define FF_NETUSAGE_NUM_FORMAT_ARGS 1
9+
#define FF_NETUSAGE_NUM_FORMAT_ARGS 12
1010

1111
static int sortInfs(const FFNetUsageIoCounters* left, const FFNetUsageIoCounters* right)
1212
{
@@ -71,11 +71,15 @@ void ffPrintNetUsage(FFNetUsageOptions* options)
7171
{
7272
ffStrbufClear(&buffer2);
7373
ffParseSize(inf->rxBytes, &buffer);
74+
ffStrbufAppendS(&buffer, "/s");
7475
ffParseSize(inf->txBytes, &buffer2);
76+
ffStrbufAppendS(&buffer2, "/s");
77+
7578
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_NETUSAGE_NUM_FORMAT_ARGS, (FFformatarg[]){
76-
{FF_FORMAT_ARG_TYPE_STRBUF, &inf->name},
7779
{FF_FORMAT_ARG_TYPE_STRBUF, &buffer},
7880
{FF_FORMAT_ARG_TYPE_STRBUF, &buffer2},
81+
{FF_FORMAT_ARG_TYPE_STRBUF, &inf->name},
82+
{FF_FORMAT_ARG_TYPE_BOOL, &inf->defaultRoute},
7983
{FF_FORMAT_ARG_TYPE_UINT64, &inf->txBytes},
8084
{FF_FORMAT_ARG_TYPE_UINT64, &inf->rxBytes},
8185
{FF_FORMAT_ARG_TYPE_UINT64, &inf->txPackets},
@@ -84,7 +88,6 @@ void ffPrintNetUsage(FFNetUsageOptions* options)
8488
{FF_FORMAT_ARG_TYPE_UINT64, &inf->txErrors},
8589
{FF_FORMAT_ARG_TYPE_UINT64, &inf->rxDrops},
8690
{FF_FORMAT_ARG_TYPE_UINT64, &inf->txDrops},
87-
{FF_FORMAT_ARG_TYPE_BOOL, &inf->defaultRoute},
8891
});
8992
}
9093
++index;
@@ -178,6 +181,7 @@ void ffGenerateNetUsageJson(FFNetUsageOptions* options, yyjson_mut_doc* doc, yyj
178181
{
179182
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
180183
yyjson_mut_obj_add_strbuf(doc, obj, "name", &counter->name);
184+
yyjson_mut_obj_add_bool(doc, obj, "defaultRoute", counter->defaultRoute);
181185
yyjson_mut_obj_add_uint(doc, obj, "txBytes", counter->txBytes);
182186
yyjson_mut_obj_add_uint(doc, obj, "rxBytes", counter->rxBytes);
183187
yyjson_mut_obj_add_uint(doc, obj, "txPackets", counter->txPackets);
@@ -186,7 +190,6 @@ void ffGenerateNetUsageJson(FFNetUsageOptions* options, yyjson_mut_doc* doc, yyj
186190
yyjson_mut_obj_add_uint(doc, obj, "txErrors", counter->txErrors);
187191
yyjson_mut_obj_add_uint(doc, obj, "rxDrops", counter->rxDrops);
188192
yyjson_mut_obj_add_uint(doc, obj, "txDrops", counter->txDrops);
189-
yyjson_mut_obj_add_bool(doc, obj, "defaultRoute", counter->defaultRoute);
190193
}
191194

192195
FF_LIST_FOR_EACH(FFNetUsageIoCounters, inf, result)

0 commit comments

Comments
 (0)