Skip to content

Commit cb48c12

Browse files
committed
Chassis: seperate module
It's only supported on Linux
1 parent 3c18fd8 commit cb48c12

File tree

20 files changed

+171
-36
lines changed

20 files changed

+171
-36
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ set(LIBFASTFETCH_SRC
257257
src/modules/bios.c
258258
src/modules/board.c
259259
src/modules/break.c
260+
src/modules/chassis.c
260261
src/modules/colors.c
261262
src/modules/cpu.c
262263
src/modules/cpuUsage.c
@@ -310,6 +311,7 @@ if(LINUX)
310311
src/detection/battery/battery_linux.c
311312
src/detection/bios/bios_linux.c
312313
src/detection/board/board_linux.c
314+
src/detection/chassis/chassis_linux.c
313315
src/detection/cpu/cpu_linux.c
314316
src/detection/cpuUsage/cpuUsage_linux.c
315317
src/detection/cursor/cursor_linux.c
@@ -348,6 +350,7 @@ elseif(ANDROID)
348350
src/detection/battery/battery_nosupport.c
349351
src/detection/bios/bios_nosupport.c
350352
src/detection/board/board_nosupport.c
353+
src/detection/chassis/chassis_nosupport.c
351354
src/detection/cpu/cpu_linux.c
352355
src/detection/cursor/cursor_nosupport.c
353356
src/detection/cpuUsage/cpuUsage_linux.c
@@ -381,6 +384,7 @@ elseif(BSD)
381384
src/detection/battery/battery_nosupport.c
382385
src/detection/bios/bios_nosupport.c
383386
src/detection/board/board_nosupport.c
387+
src/detection/chassis/chassis_nosupport.c
384388
src/detection/cpu/cpu_bsd.c
385389
src/detection/cpuUsage/cpuUsage_bsd.c
386390
src/detection/cursor/cursor_linux.c
@@ -420,6 +424,7 @@ elseif(APPLE)
420424
src/detection/battery/battery_apple.c
421425
src/detection/bios/bios_nosupport.c
422426
src/detection/board/board_nosupport.c
427+
src/detection/chassis/chassis_nosupport.c
423428
src/detection/cpu/cpu_apple.c
424429
src/detection/cpuUsage/cpuUsage_apple.c
425430
src/detection/cursor/cursor_nosupport.c
@@ -455,6 +460,7 @@ elseif(WIN32)
455460
src/detection/battery/battery_windows.c
456461
src/detection/bios/bios_windows.c
457462
src/detection/board/board_windows.c
463+
src/detection/chassis/chassis_nosupport.c
458464
src/detection/cpu/cpu_windows.c
459465
src/detection/cpuUsage/cpuUsage_windows.c
460466
src/detection/cursor/cursor_windows.c

presets/all

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

presets/verbose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--os-format System: {}; Name: {}; Pretty name: {}; ID: {}; ID like: {}; Variant: {}; Variant ID: {}; Version: {}; Version ID: {}; Version codename: {}; Build ID: {}; Architecture: {}
2-
--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: {}
2+
--host-format Family: product_family: {}; product_name: {}; product_version: {}; product_sku: {}; sys_vendor: {}
33
--kernel-format Sysname: {}; Release: {}; Version: {}
44
--uptime-format Days: {}; Hours: {}; Minutes: {}; Seconds: {}
55
--processes-format Count: {}

src/common/init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ static void defaultConfig(FFinstance* instance)
167167
initModuleArg(&instance->config.host);
168168
initModuleArg(&instance->config.bios);
169169
initModuleArg(&instance->config.board);
170+
initModuleArg(&instance->config.chassis);
170171
initModuleArg(&instance->config.kernel);
171172
initModuleArg(&instance->config.uptime);
172173
initModuleArg(&instance->config.processes);

src/data/config_user.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@
217217
# Can be any string. Some of theme take an argument like a format string. See "fastfetch --help format" for help.
218218
#--os-key OS
219219
#--host-key Host
220+
#--chassis-key Chassis
220221
#--kernel-key Kernel
221222
#--uptime-key Uptime
222223
#--processes-key Processes
@@ -260,6 +261,7 @@
260261
# An empty format string (As they are currently below) will behave as if it was not set.
261262
#--os-format
262263
#--host-format
264+
#--chassis-format
263265
#--kernel-format
264266
#--uptime-format
265267
#--processes-format
@@ -302,6 +304,7 @@
302304
# If one of them is set, the module will appear, even if --show-errors is not given.
303305
#--os-error
304306
#--host-error
307+
#--chassis-error
305308
#--kernel-error
306309
#--uptime-error
307310
#--processes-error

src/data/modules.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Battery
2+
Bios
3+
Board
24
Break
5+
Chassis
36
Colors
47
CPU
58
CPUUsage
@@ -15,19 +18,18 @@ Icons
1518
Kernel
1619
Locale
1720
LocalIP
18-
Media
1921
Memory
20-
OS
21-
OpenCL
2222
OpenGL
23+
OS
2324
Packages
2425
Player
26+
PowerAdapter
2527
Processes
2628
PublicIP
27-
PowerAdapter
2829
Resolution
2930
Separator
3031
Shell
32+
Song
3133
Swap
3234
Terminal
3335
TerminalFont
@@ -36,5 +38,7 @@ Time
3638
Title
3739
Uptime
3840
Vulkan
41+
Weather
42+
Wifi
3943
WM
4044
WMTheme

src/detection/chassis/chassis.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#ifndef FF_INCLUDED_detection_chassis_chassis
4+
#define FF_INCLUDED_detection_chassis_chassis
5+
6+
#include "fastfetch.h"
7+
8+
typedef struct FFChassisResult
9+
{
10+
FFstrbuf chassisType;
11+
FFstrbuf chassisVendor;
12+
FFstrbuf chassisVersion;
13+
FFstrbuf error;
14+
} FFChassisResult;
15+
16+
void ffDetectChassis(FFChassisResult* result);
17+
18+
#endif
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "chassis.h"
2+
#include "common/io.h"
3+
4+
#include <stdlib.h>
5+
6+
static bool hostValueSet(FFstrbuf* value)
7+
{
8+
return
9+
value->length > 0 &&
10+
ffStrbufStartsWithIgnCaseS(value, "To be filled") != true &&
11+
ffStrbufStartsWithIgnCaseS(value, "To be set") != true &&
12+
ffStrbufStartsWithIgnCaseS(value, "OEM") != true &&
13+
ffStrbufStartsWithIgnCaseS(value, "O.E.M.") != true &&
14+
ffStrbufIgnCaseCompS(value, "None") != 0 &&
15+
ffStrbufIgnCaseCompS(value, "System Product") != 0 &&
16+
ffStrbufIgnCaseCompS(value, "System Product Name") != 0 &&
17+
ffStrbufIgnCaseCompS(value, "System Product Version") != 0 &&
18+
ffStrbufIgnCaseCompS(value, "System Name") != 0 &&
19+
ffStrbufIgnCaseCompS(value, "System Version") != 0 &&
20+
ffStrbufIgnCaseCompS(value, "Default string") != 0 &&
21+
ffStrbufIgnCaseCompS(value, "Undefined") != 0 &&
22+
ffStrbufIgnCaseCompS(value, "Not Specified") != 0 &&
23+
ffStrbufIgnCaseCompS(value, "Not Applicable") != 0 &&
24+
ffStrbufIgnCaseCompS(value, "INVALID") != 0 &&
25+
ffStrbufIgnCaseCompS(value, "Type1ProductConfigId") != 0 &&
26+
ffStrbufIgnCaseCompS(value, "All Series") != 0
27+
;
28+
}
29+
30+
static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
31+
{
32+
ffReadFileBuffer(devicesPath, buffer);
33+
if(hostValueSet(buffer))
34+
return;
35+
36+
ffReadFileBuffer(classPath, buffer);
37+
if(hostValueSet(buffer))
38+
return;
39+
40+
ffStrbufClear(buffer);
41+
}
42+
43+
void ffDetectChassis(FFChassisResult* result)
44+
{
45+
ffStrbufInit(&result->error);
46+
47+
ffStrbufInit(&result->chassisType);
48+
getHostValue("/sys/devices/virtual/dmi/id/chassis_type", "/sys/class/dmi/id/chassis_type", &result->chassisType);
49+
50+
ffStrbufInit(&result->chassisVendor);
51+
getHostValue("/sys/devices/virtual/dmi/id/chassis_vendor", "/sys/class/dmi/id/chassis_vendor", &result->chassisVendor);
52+
53+
ffStrbufInit(&result->chassisVersion);
54+
getHostValue("/sys/devices/virtual/dmi/id/chassis_version", "/sys/class/dmi/id/chassis_version", &result->chassisVersion);
55+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "chassis.h"
2+
3+
void ffDetectChassis(FFChassisResult* result)
4+
{
5+
ffStrbufInitS(&result->error, "Not supported on this platform");
6+
7+
ffStrbufInit(&result->chassisType);
8+
ffStrbufInit(&result->chassisVendor);
9+
ffStrbufInit(&result->chassisVersion);
10+
}

src/detection/host/host.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ typedef struct FFHostResult
1111
FFstrbuf productName;
1212
FFstrbuf productVersion;
1313
FFstrbuf productSku;
14-
FFstrbuf chassisType;
15-
FFstrbuf chassisVendor;
16-
FFstrbuf chassisVersion;
1714
FFstrbuf sysVendor;
1815
FFstrbuf error;
1916
} FFHostResult;

0 commit comments

Comments
 (0)