diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e6361229..8ce915f1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -257,6 +257,7 @@ set(LIBFASTFETCH_SRC src/modules/bios.c src/modules/board.c src/modules/break.c + src/modules/chassis.c src/modules/colors.c src/modules/cpu.c src/modules/cpuUsage.c @@ -310,6 +311,7 @@ if(LINUX) src/detection/battery/battery_linux.c src/detection/bios/bios_linux.c src/detection/board/board_linux.c + src/detection/chassis/chassis_linux.c src/detection/cpu/cpu_linux.c src/detection/cpuUsage/cpuUsage_linux.c src/detection/cursor/cursor_linux.c @@ -348,6 +350,7 @@ elseif(ANDROID) src/detection/battery/battery_nosupport.c src/detection/bios/bios_nosupport.c src/detection/board/board_nosupport.c + src/detection/chassis/chassis_nosupport.c src/detection/cpu/cpu_linux.c src/detection/cursor/cursor_nosupport.c src/detection/cpuUsage/cpuUsage_linux.c @@ -381,6 +384,7 @@ elseif(BSD) src/detection/battery/battery_nosupport.c src/detection/bios/bios_nosupport.c src/detection/board/board_nosupport.c + src/detection/chassis/chassis_nosupport.c src/detection/cpu/cpu_bsd.c src/detection/cpuUsage/cpuUsage_bsd.c src/detection/cursor/cursor_linux.c @@ -420,6 +424,7 @@ elseif(APPLE) src/detection/battery/battery_apple.c src/detection/bios/bios_nosupport.c src/detection/board/board_nosupport.c + src/detection/chassis/chassis_nosupport.c src/detection/cpu/cpu_apple.c src/detection/cpuUsage/cpuUsage_apple.c src/detection/cursor/cursor_nosupport.c @@ -455,6 +460,7 @@ elseif(WIN32) src/detection/battery/battery_windows.c src/detection/bios/bios_windows.c src/detection/board/board_windows.c + src/detection/chassis/chassis_nosupport.c src/detection/cpu/cpu_windows.c src/detection/cpuUsage/cpuUsage_windows.c src/detection/cursor/cursor_windows.c diff --git a/presets/all b/presets/all index ac42d20c6..d28a033a4 100644 --- a/presets/all +++ b/presets/all @@ -1 +1 @@ ---structure Title:Separator:OS:Host:Kernel:Uptime:Processes:Packages:Shell:Resolution:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:CPUUsage:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Song:PublicIP:LocalIP:Wifi:DateTime:Locale:Vulkan:OpenGL:OpenCL:Users:Weather:Break:Colors +--structure Title:Separator:OS:Host:Bios:Board:Chassis:Kernel:Uptime:Processes:Packages:Shell:Resolution:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:CPUUsage:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Song:PublicIP:LocalIP:Wifi:DateTime:Locale:Vulkan:OpenGL:OpenCL:Users:Weather:Break:Colors diff --git a/presets/verbose b/presets/verbose index e9f09e939..912e5baf4 100644 --- a/presets/verbose +++ b/presets/verbose @@ -1,5 +1,5 @@ --os-format System: {}; Name: {}; Pretty name: {}; ID: {}; ID like: {}; Variant: {}; Variant ID: {}; Version: {}; Version ID: {}; Version codename: {}; Build ID: {}; Architecture: {} ---host-format Family: product_family: {}; product_name: {}; product_version: {}; product_sku: {}; bios_date: {}; bios_release: {}; bios_vendor: {}; bios_version: {}; board_name: {}; board_vendor: {}; board_version: {}; chassis_type: {}; chassis_vendor: {}; chassis_version: {}; sys_vendor: {} +--host-format Family: product_family: {}; product_name: {}; product_version: {}; product_sku: {}; sys_vendor: {} --kernel-format Sysname: {}; Release: {}; Version: {} --uptime-format Days: {}; Hours: {}; Minutes: {}; Seconds: {} --processes-format Count: {} diff --git a/src/common/init.c b/src/common/init.c index 1e42252bc..88ad09a66 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -167,6 +167,7 @@ static void defaultConfig(FFinstance* instance) initModuleArg(&instance->config.host); initModuleArg(&instance->config.bios); initModuleArg(&instance->config.board); + initModuleArg(&instance->config.chassis); initModuleArg(&instance->config.kernel); initModuleArg(&instance->config.uptime); initModuleArg(&instance->config.processes); diff --git a/src/data/config_user.txt b/src/data/config_user.txt index 2fc0b41fa..acf7f2117 100644 --- a/src/data/config_user.txt +++ b/src/data/config_user.txt @@ -217,6 +217,7 @@ # Can be any string. Some of theme take an argument like a format string. See "fastfetch --help format" for help. #--os-key OS #--host-key Host +#--chassis-key Chassis #--kernel-key Kernel #--uptime-key Uptime #--processes-key Processes @@ -260,6 +261,7 @@ # An empty format string (As they are currently below) will behave as if it was not set. #--os-format #--host-format +#--chassis-format #--kernel-format #--uptime-format #--processes-format @@ -302,6 +304,7 @@ # If one of them is set, the module will appear, even if --show-errors is not given. #--os-error #--host-error +#--chassis-error #--kernel-error #--uptime-error #--processes-error diff --git a/src/data/modules.txt b/src/data/modules.txt index 0177c4b5d..4420e2c91 100644 --- a/src/data/modules.txt +++ b/src/data/modules.txt @@ -1,5 +1,8 @@ Battery +Bios +Board Break +Chassis Colors CPU CPUUsage @@ -15,19 +18,18 @@ Icons Kernel Locale LocalIP -Media Memory -OS -OpenCL OpenGL +OS Packages Player +PowerAdapter Processes PublicIP -PowerAdapter Resolution Separator Shell +Song Swap Terminal TerminalFont @@ -36,5 +38,7 @@ Time Title Uptime Vulkan +Weather +Wifi WM WMTheme diff --git a/src/detection/chassis/chassis.h b/src/detection/chassis/chassis.h new file mode 100644 index 000000000..eb6ce4c6c --- /dev/null +++ b/src/detection/chassis/chassis.h @@ -0,0 +1,18 @@ +#pragma once + +#ifndef FF_INCLUDED_detection_chassis_chassis +#define FF_INCLUDED_detection_chassis_chassis + +#include "fastfetch.h" + +typedef struct FFChassisResult +{ + FFstrbuf chassisType; + FFstrbuf chassisVendor; + FFstrbuf chassisVersion; + FFstrbuf error; +} FFChassisResult; + +void ffDetectChassis(FFChassisResult* result); + +#endif diff --git a/src/detection/chassis/chassis_linux.c b/src/detection/chassis/chassis_linux.c new file mode 100644 index 000000000..192747e7d --- /dev/null +++ b/src/detection/chassis/chassis_linux.c @@ -0,0 +1,55 @@ +#include "chassis.h" +#include "common/io.h" + +#include + +static bool hostValueSet(FFstrbuf* value) +{ + return + value->length > 0 && + ffStrbufStartsWithIgnCaseS(value, "To be filled") != true && + ffStrbufStartsWithIgnCaseS(value, "To be set") != true && + ffStrbufStartsWithIgnCaseS(value, "OEM") != true && + ffStrbufStartsWithIgnCaseS(value, "O.E.M.") != true && + ffStrbufIgnCaseCompS(value, "None") != 0 && + ffStrbufIgnCaseCompS(value, "System Product") != 0 && + ffStrbufIgnCaseCompS(value, "System Product Name") != 0 && + ffStrbufIgnCaseCompS(value, "System Product Version") != 0 && + ffStrbufIgnCaseCompS(value, "System Name") != 0 && + ffStrbufIgnCaseCompS(value, "System Version") != 0 && + ffStrbufIgnCaseCompS(value, "Default string") != 0 && + ffStrbufIgnCaseCompS(value, "Undefined") != 0 && + ffStrbufIgnCaseCompS(value, "Not Specified") != 0 && + ffStrbufIgnCaseCompS(value, "Not Applicable") != 0 && + ffStrbufIgnCaseCompS(value, "INVALID") != 0 && + ffStrbufIgnCaseCompS(value, "Type1ProductConfigId") != 0 && + ffStrbufIgnCaseCompS(value, "All Series") != 0 + ; +} + +static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer) +{ + ffReadFileBuffer(devicesPath, buffer); + if(hostValueSet(buffer)) + return; + + ffReadFileBuffer(classPath, buffer); + if(hostValueSet(buffer)) + return; + + ffStrbufClear(buffer); +} + +void ffDetectChassis(FFChassisResult* result) +{ + ffStrbufInit(&result->error); + + ffStrbufInit(&result->chassisType); + getHostValue("/sys/devices/virtual/dmi/id/chassis_type", "/sys/class/dmi/id/chassis_type", &result->chassisType); + + ffStrbufInit(&result->chassisVendor); + getHostValue("/sys/devices/virtual/dmi/id/chassis_vendor", "/sys/class/dmi/id/chassis_vendor", &result->chassisVendor); + + ffStrbufInit(&result->chassisVersion); + getHostValue("/sys/devices/virtual/dmi/id/chassis_version", "/sys/class/dmi/id/chassis_version", &result->chassisVersion); +} diff --git a/src/detection/chassis/chassis_nosupport.c b/src/detection/chassis/chassis_nosupport.c new file mode 100644 index 000000000..42c182567 --- /dev/null +++ b/src/detection/chassis/chassis_nosupport.c @@ -0,0 +1,10 @@ +#include "chassis.h" + +void ffDetectChassis(FFChassisResult* result) +{ + ffStrbufInitS(&result->error, "Not supported on this platform"); + + ffStrbufInit(&result->chassisType); + ffStrbufInit(&result->chassisVendor); + ffStrbufInit(&result->chassisVersion); +} diff --git a/src/detection/host/host.h b/src/detection/host/host.h index e49e8faad..c8b47b6b2 100644 --- a/src/detection/host/host.h +++ b/src/detection/host/host.h @@ -11,9 +11,6 @@ typedef struct FFHostResult FFstrbuf productName; FFstrbuf productVersion; FFstrbuf productSku; - FFstrbuf chassisType; - FFstrbuf chassisVendor; - FFstrbuf chassisVersion; FFstrbuf sysVendor; FFstrbuf error; } FFHostResult; diff --git a/src/detection/host/host_android.c b/src/detection/host/host_android.c index b45283eb3..edeb9cb47 100644 --- a/src/detection/host/host_android.c +++ b/src/detection/host/host_android.c @@ -34,7 +34,4 @@ void ffDetectHostImpl(FFHostResult* host) ffStrbufInitA(&host->productVersion, 0); ffStrbufInitA(&host->productSku, 0); - ffStrbufInitA(&host->chassisType, 0); - ffStrbufInitA(&host->chassisVendor, 0); - ffStrbufInitA(&host->chassisVersion, 0); } diff --git a/src/detection/host/host_apple.c b/src/detection/host/host_apple.c index a63976d10..d768d83e4 100644 --- a/src/detection/host/host_apple.c +++ b/src/detection/host/host_apple.c @@ -151,11 +151,7 @@ void ffDetectHostImpl(FFHostResult* host) ffStrbufInit(&host->productFamily); ffStrbufInit(&host->productVersion); ffStrbufInit(&host->productSku); - ffStrbufInitS(&host->sysVendor, "Apple"); - ffStrbufInit(&host->chassisType); - ffStrbufInit(&host->chassisVendor); - ffStrbufInit(&host->chassisVersion); ffStrbufAppendS(&host->error, ffSysctlGetString("hw.model", &host->productFamily)); if(host->error.length == 0) diff --git a/src/detection/host/host_bsd.c b/src/detection/host/host_bsd.c index 13a43acda..8be64b6c3 100644 --- a/src/detection/host/host_bsd.c +++ b/src/detection/host/host_bsd.c @@ -9,11 +9,7 @@ void ffDetectHostImpl(FFHostResult* host) ffStrbufInit(&host->productFamily); ffStrbufInit(&host->productVersion); ffStrbufInit(&host->productSku); - ffStrbufInit(&host->sysVendor); - ffStrbufInit(&host->chassisType); - ffStrbufInit(&host->chassisVendor); - ffStrbufInit(&host->chassisVersion); ffStrbufAppendS(&host->error, ffSysctlGetString("hw.fdt.model", &host->productName)); } diff --git a/src/detection/host/host_linux.c b/src/detection/host/host_linux.c index 483313103..e4e7dfef1 100644 --- a/src/detection/host/host_linux.c +++ b/src/detection/host/host_linux.c @@ -75,15 +75,6 @@ void ffDetectHostImpl(FFHostResult* host) ffStrbufInit(&host->productSku); getHostValue("/sys/devices/virtual/dmi/id/product_sku", "/sys/class/dmi/id/product_sku", &host->productSku); - ffStrbufInit(&host->chassisType); - getHostValue("/sys/devices/virtual/dmi/id/chassis_type", "/sys/class/dmi/id/chassis_type", &host->chassisType); - - ffStrbufInit(&host->chassisVendor); - getHostValue("/sys/devices/virtual/dmi/id/chassis_vendor", "/sys/class/dmi/id/chassis_vendor", &host->chassisVendor); - - ffStrbufInit(&host->chassisVersion); - getHostValue("/sys/devices/virtual/dmi/id/chassis_version", "/sys/class/dmi/id/chassis_version", &host->chassisVersion); - ffStrbufInit(&host->sysVendor); getHostValue("/sys/devices/virtual/dmi/id/sys_vendor", "/sys/class/dmi/id/sys_vendor", &host->sysVendor); diff --git a/src/detection/host/host_windows.c b/src/detection/host/host_windows.c index 5d0ae363b..75afd0563 100644 --- a/src/detection/host/host_windows.c +++ b/src/detection/host/host_windows.c @@ -10,9 +10,6 @@ void ffDetectHostImpl(FFHostResult* host) ffStrbufInit(&host->productVersion); ffStrbufInit(&host->productSku); ffStrbufInit(&host->sysVendor); - ffStrbufInit(&host->chassisType); - ffStrbufInit(&host->chassisVendor); - ffStrbufInit(&host->chassisVersion); FF_HKEY_AUTO_DESTROY hKey = NULL; diff --git a/src/fastfetch.c b/src/fastfetch.c index 8112b9a54..d38bc3d2e 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -106,6 +106,14 @@ static inline void printCommandHelp(const char* command) "board version" ); } + else if(strcasecmp(command, "chassis-format") == 0) + { + constructAndPrintCommandHelpFormat("chassis", "{2} {3}", 4, + "chassis type", + "chassis vendor", + "chassis version" + ); + } else if(strcasecmp(command, "kernel-format") == 0) { constructAndPrintCommandHelpFormat("kernel", "{2}", 3, @@ -1080,6 +1088,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con else if(optionParseModuleArgs(key, value, "host", &instance->config.host)) {} else if(optionParseModuleArgs(key, value, "bios", &instance->config.bios)) {} else if(optionParseModuleArgs(key, value, "board", &instance->config.board)) {} + else if(optionParseModuleArgs(key, value, "chassis", &instance->config.chassis)) {} else if(optionParseModuleArgs(key, value, "kernel", &instance->config.kernel)) {} else if(optionParseModuleArgs(key, value, "uptime", &instance->config.uptime)) {} else if(optionParseModuleArgs(key, value, "processes", &instance->config.processes)) {} @@ -1307,6 +1316,8 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char ffPrintBios(instance); else if(strcasecmp(line, "board") == 0) ffPrintBoard(instance); + else if(strcasecmp(line, "chassis") == 0) + ffPrintChassis(instance); else if(strcasecmp(line, "kernel") == 0) ffPrintKernel(instance); else if(strcasecmp(line, "uptime") == 0) diff --git a/src/fastfetch.h b/src/fastfetch.h index d38b9b48d..3f592156d 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -106,6 +106,7 @@ typedef struct FFconfig FFModuleArgs os; FFModuleArgs host; FFModuleArgs bios; + FFModuleArgs chassis; FFModuleArgs board; FFModuleArgs kernel; FFModuleArgs uptime; @@ -268,6 +269,7 @@ void ffPrintOS(FFinstance* instance); void ffPrintHost(FFinstance* instance); void ffPrintBios(FFinstance* instance); void ffPrintBoard(FFinstance* instance); +void ffPrintChassis(FFinstance* instance); void ffPrintKernel(FFinstance* instance); void ffPrintUptime(FFinstance* instance); void ffPrintProcesses(FFinstance* instance); diff --git a/src/flashfetch.c b/src/flashfetch.c index 6b961dfa3..769cdfc5d 100644 --- a/src/flashfetch.c +++ b/src/flashfetch.c @@ -24,6 +24,7 @@ int main(int argc, char** argv) ffPrintHost(&instance); //ffPrintBios(&instance); //ffPrintBoard(&instance); + //ffPrintChassis(&instance); ffPrintKernel(&instance); ffPrintUptime(&instance); //ffPrintProcesses(&instance); diff --git a/src/modules/chassis.c b/src/modules/chassis.c new file mode 100644 index 000000000..93d14eb52 --- /dev/null +++ b/src/modules/chassis.c @@ -0,0 +1,53 @@ +#include "fastfetch.h" +#include "common/printing.h" +#include "detection/chassis/chassis.h" + +#define FF_CHASSIS_MODULE_NAME "Chassis" +#define FF_CHASSIS_NUM_FORMAT_ARGS 3 + +void ffPrintChassis(FFinstance* instance) +{ + FFChassisResult result; + ffDetectChassis(&result); + + if(result.error.length > 0) + { + ffPrintError(instance, FF_CHASSIS_MODULE_NAME, 0, &instance->config.chassis, "%*s", result.error.length, result.error.chars); + goto exit; + } + + if(result.chassisType.length == 0) + { + ffPrintError(instance, FF_CHASSIS_MODULE_NAME, 0, &instance->config.host, "chassis_type is not set by O.E.M."); + return; + } + + if(instance->config.chassis.outputFormat.length == 0) + { + ffPrintLogoAndKey(instance, FF_CHASSIS_MODULE_NAME, 0, &instance->config.host.key); + + FFstrbuf output; + ffStrbufInitCopy(&output, &result.chassisType); + + if(result.chassisVersion.length > 0) + ffStrbufAppendF(&output, " (%s)", &result.chassisVersion); + + ffStrbufPutTo(&output, stdout); + + ffStrbufDestroy(&output); + } + else + { + ffPrintFormat(instance, FF_CHASSIS_MODULE_NAME, 0, &instance->config.chassis, FF_CHASSIS_NUM_FORMAT_ARGS, (FFformatarg[]) { + {FF_FORMAT_ARG_TYPE_STRBUF, &result.chassisType}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.chassisVendor}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.chassisVersion}, + }); + } + +exit: + ffStrbufDestroy(&result.chassisType); + ffStrbufDestroy(&result.chassisVendor); + ffStrbufDestroy(&result.chassisVersion); + ffStrbufDestroy(&result.error); +} diff --git a/src/modules/host.c b/src/modules/host.c index f253ceee4..e8d8e6044 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -3,7 +3,7 @@ #include "detection/host/host.h" #define FF_HOST_MODULE_NAME "Host" -#define FF_HOST_NUM_FORMAT_ARGS 8 +#define FF_HOST_NUM_FORMAT_ARGS 5 void ffPrintHost(FFinstance* instance) { @@ -49,9 +49,6 @@ void ffPrintHost(FFinstance* instance) {FF_FORMAT_ARG_TYPE_STRBUF, &host->productName}, {FF_FORMAT_ARG_TYPE_STRBUF, &host->productVersion}, {FF_FORMAT_ARG_TYPE_STRBUF, &host->productSku}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host->chassisType}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host->chassisVendor}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host->chassisVersion}, {FF_FORMAT_ARG_TYPE_STRBUF, &host->sysVendor} }); }