mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Disk / Users: support duration printing in custom format
This commit is contained in:
@@ -13,6 +13,20 @@ Features:
|
||||
* CMake: add option `-DCUSTOM_LSB_RELEASE_PATH` to specify the path of `lsb-release` file
|
||||
* `-DCUSTOM_OS_RELEASE_PATH` has been supported since `v2.11.4`
|
||||
* Report more SOC names on Android (CPU, Android)
|
||||
* Support duration printing in custom format (Disk / Users)
|
||||
* For example:
|
||||
```json
|
||||
{
|
||||
"modules": [
|
||||
{
|
||||
"key": "OS Age", // No longer need to write bash scripts
|
||||
"type": "disk",
|
||||
"folders": "/", // Different OSes may need to specify different folders
|
||||
"format": "{days} days"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Logo:
|
||||
* Add Arch_old
|
||||
|
||||
+21
-1
@@ -125,6 +125,17 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index
|
||||
bool isHidden = !!(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT);
|
||||
bool isReadOnly = !!(disk->type & FF_DISK_VOLUME_TYPE_READONLY_BIT);
|
||||
|
||||
uint64_t duration = ffTimeGetNow() - disk->createTime;
|
||||
uint32_t milliseconds = (uint32_t) (duration % 1000);
|
||||
duration /= 1000;
|
||||
uint32_t seconds = (uint32_t) (duration % 60);
|
||||
duration /= 60;
|
||||
uint32_t minutes = (uint32_t) (duration % 60);
|
||||
duration /= 60;
|
||||
uint32_t hours = (uint32_t) (duration % 24);
|
||||
duration /= 24;
|
||||
uint32_t days = (uint32_t) duration;
|
||||
|
||||
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, ((FFformatarg[]) {
|
||||
FF_FORMAT_ARG(usedPretty, "size-used"),
|
||||
FF_FORMAT_ARG(totalPretty, "size-total"),
|
||||
@@ -140,6 +151,11 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index
|
||||
{FF_FORMAT_ARG_TYPE_STRING, ffTimeToShortStr(disk->createTime), "create-time"},
|
||||
FF_FORMAT_ARG(bytesPercentageBar, "size-percentage-bar"),
|
||||
FF_FORMAT_ARG(filesPercentageBar, "files-percentage-bar"),
|
||||
FF_FORMAT_ARG(days, "days"),
|
||||
FF_FORMAT_ARG(hours, "hours"),
|
||||
FF_FORMAT_ARG(minutes, "minutes"),
|
||||
FF_FORMAT_ARG(seconds, "seconds"),
|
||||
FF_FORMAT_ARG(milliseconds, "milliseconds"),
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -462,7 +478,11 @@ static FFModuleBaseInfo ffModuleInfo = {
|
||||
{"Create time in local timezone", "create-time"},
|
||||
{"Size percentage bar", "size-percentage-bar"},
|
||||
{"Files percentage bar", "files-percentage-bar"},
|
||||
{},
|
||||
{"Days after creation", "days"},
|
||||
{"Hours after creation", "hours"},
|
||||
{"Minutes after creation", "minutes"},
|
||||
{"Seconds after creation", "seconds"},
|
||||
{"Milliseconds after creation", "milliseconds"},
|
||||
}))
|
||||
};
|
||||
|
||||
|
||||
@@ -62,16 +62,33 @@ void ffPrintUsers(FFUsersOptions* options)
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t now = ffTimeGetNow();
|
||||
for(uint32_t i = 0; i < users.length; ++i)
|
||||
{
|
||||
FFUserResult* user = FF_LIST_GET(FFUserResult, users, i);
|
||||
|
||||
uint64_t duration = now - user->loginTime;
|
||||
uint32_t milliseconds = (uint32_t) (duration % 1000);
|
||||
duration /= 1000;
|
||||
uint32_t seconds = (uint32_t) (duration % 60);
|
||||
duration /= 60;
|
||||
uint32_t minutes = (uint32_t) (duration % 60);
|
||||
duration /= 60;
|
||||
uint32_t hours = (uint32_t) (duration % 24);
|
||||
duration /= 24;
|
||||
uint32_t days = (uint32_t) duration;
|
||||
|
||||
FF_PRINT_FORMAT_CHECKED(FF_USERS_MODULE_NAME, users.length == 1 ? 0 : (uint8_t) (i + 1), &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){
|
||||
FF_FORMAT_ARG(user->name, "name"),
|
||||
FF_FORMAT_ARG(user->hostName, "host-name"),
|
||||
FF_FORMAT_ARG(user->sessionName, "session-name"),
|
||||
FF_FORMAT_ARG(user->clientIp, "client-ip"),
|
||||
{FF_FORMAT_ARG_TYPE_STRING, ffTimeToShortStr(user->loginTime), "login-time"},
|
||||
FF_FORMAT_ARG(days, "days"),
|
||||
FF_FORMAT_ARG(hours, "hours"),
|
||||
FF_FORMAT_ARG(minutes, "minutes"),
|
||||
FF_FORMAT_ARG(seconds, "seconds"),
|
||||
FF_FORMAT_ARG(milliseconds, "milliseconds"),
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -200,6 +217,11 @@ static FFModuleBaseInfo ffModuleInfo = {
|
||||
{"Session name", "session"},
|
||||
{"Client IP", "client-ip"},
|
||||
{"Login Time in local timezone", "login-time"},
|
||||
{"Days after login", "days"},
|
||||
{"Hours after login", "hours"},
|
||||
{"Minutes after login", "minutes"},
|
||||
{"Seconds after login", "seconds"},
|
||||
{"Milliseconds after login", "milliseconds"},
|
||||
}))
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user