Merge pull request #315 from CarterLi/dev

Improvements and bug fix for terminal font detection
This commit is contained in:
Linus Dierheimer
2022-10-26 15:18:07 +02:00
committed by GitHub
15 changed files with 235 additions and 78 deletions
+5 -5
View File
@@ -302,6 +302,8 @@ endif()
if(BSD OR APPLE)
list(APPEND LIBFASTFETCH_SRC
src/common/sysctl.c
src/detection/uptime/uptime_bsd.c
src/detection/processes/processes_bsd.c
)
endif()
@@ -309,7 +311,9 @@ if(LINUX OR ANDROID)
list(APPEND LIBFASTFETCH_SRC
src/detection/cpu/cpu_linux.c
src/detection/memory/memory_linux.c
src/detection/processes/processes_linux.c
src/detection/swap/swap_linux.c
src/detection/uptime/uptime_linux.c
)
endif()
@@ -319,8 +323,6 @@ if(LINUX OR ANDROID OR BSD)
src/detection/disk/disk_linux.c
src/detection/temps/temps_linux.c
src/detection/opengl/opengl_linux.c
src/detection/processes/processes_linux.c
src/detection/uptime/uptime_linux.c
src/detection/packages/packages_linux.c
src/detection/poweradapter/poweradapter_nosupport.c
@@ -378,7 +380,7 @@ if(WIN32)
src/util/windows/wmi.cpp
src/util/windows/getline.c
src/util/windows/pwd.c
src/util/windows/utsname.cpp
src/util/windows/utsname.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/media/media_nosupport.c
@@ -406,8 +408,6 @@ if(APPLE)
src/detection/temps/temps_apple.c
src/detection/font/font_apple.m
src/detection/opengl/opengl_apple.c
src/detection/processes/processes_apple.c
src/detection/uptime/uptime_apple.c
src/detection/packages/packages_apple.c
src/detection/bios/bios_nosupport.c
+5 -5
View File
@@ -35,12 +35,12 @@ void ffDetectDisksImpl(FFDiskResult* disks)
NSError* error;
NSNumber* isBrowsable;
if(removable)
disk->type = FF_DISK_TYPE_EXTERNAL;
else if([url getResourceValue:&isBrowsable forKey:NSURLVolumeIsBrowsableKey error:&error] == YES && isBrowsable.boolValue)
disk->type = FF_DISK_TYPE_REGULAR;
else
if([url getResourceValue:&isBrowsable forKey:NSURLVolumeIsBrowsableKey error:&error] == YES && !isBrowsable.boolValue)
disk->type = FF_DISK_TYPE_HIDDEN;
else if(removable)
disk->type = FF_DISK_TYPE_EXTERNAL;
else
disk->type = FF_DISK_TYPE_REGULAR;
NSString* volumeName;
if([url getResourceValue:&volumeName forKey:NSURLVolumeNameKey error:&error] == YES)
+4 -16
View File
@@ -1,6 +1,8 @@
#include "packages.h"
#include "detection/internal.h"
#include <stddef.h>
void ffDetectPackagesImpl(const FFinstance* instance, FFPackagesResult* result);
const FFPackagesResult* ffDetectPackages(const FFinstance* instance)
@@ -11,21 +13,7 @@ const FFPackagesResult* ffDetectPackages(const FFinstance* instance)
ffDetectPackagesImpl(instance, &result);
result.all = 0
+ result.pacman
+ result.dpkg
+ result.rpm
+ result.emerge
+ result.xbps
+ result.nixSystem
+ result.nixUser
+ result.nixDefault
+ result.apk
+ result.pkg
+ result.flatpak
+ result.snap
+ result.brew
+ result.port
+ result.scoop;
for(uint32_t i = 0; i < offsetof(FFPackagesResult, all) / sizeof(uint32_t); ++i)
result.all += ((uint32_t *)&result)[i];
);
}
+3 -2
View File
@@ -7,10 +7,9 @@
typedef struct FFPackagesResult
{
uint32_t all;
uint32_t apk;
uint32_t brew;
uint32_t choco;
uint32_t dpkg;
uint32_t emerge;
uint32_t flatpak;
@@ -25,6 +24,8 @@ typedef struct FFPackagesResult
uint32_t snap;
uint32_t xbps;
uint32_t all; //Make sure this goes last
FFstrbuf pacmanBranch;
} FFPackagesResult;
+27 -8
View File
@@ -25,15 +25,34 @@ static uint32_t getNumElements(const char* searchPath /* including `\*` suffix *
return counter;
}
void ffDetectPackagesImpl(const FFinstance* instance, FFPackagesResult* result)
static void detectScoop(const FFinstance* instance, FFPackagesResult* result)
{
char scoopPath[MAX_PATH + 3];
strcpy(scoopPath, instance->state.passwd->pw_dir);
strncat(scoopPath, "/scoop/apps/*", sizeof(scoopPath) - 1 - strlen(scoopPath));
result->scoop = getNumElements(scoopPath, FILE_ATTRIBUTE_DIRECTORY);
if(result->scoop > 0)
result->scoop--; // scoop
}
static void detectChoco(const FFinstance* instance, FFPackagesResult* result)
{
FF_UNUSED(instance);
FFstrbuf scoopPath;
ffStrbufInitS(&scoopPath, instance->state.passwd->pw_dir);
ffStrbufAppendS(&scoopPath, "/scoop/apps/*");
result->scoop = getNumElements(scoopPath.chars, FILE_ATTRIBUTE_DIRECTORY);
if(result->scoop > 0)
result->scoop--; // scoop
ffStrbufDestroy(&scoopPath);
const char* chocoInstall = getenv("ChocolateyInstall");
if(!chocoInstall || chocoInstall[0] == '\0')
return;
char chocoPath[MAX_PATH + 3];
strcpy(chocoPath, chocoInstall);
strncat(chocoPath, "/lib/*", sizeof(chocoPath) - 1 - strlen(chocoPath));
result->choco = getNumElements(chocoPath, FILE_ATTRIBUTE_DIRECTORY);
if(result->choco > 0)
result->choco--; // choco
}
void ffDetectPackagesImpl(const FFinstance* instance, FFPackagesResult* result)
{
detectScoop(instance, result);
detectChoco(instance, result);
}
@@ -1,6 +1,10 @@
#include "processes.h"
#include <sys/sysctl.h>
#ifdef __FreeBSD__
#include <sys/types.h>
#include <sys/user.h>
#endif
uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error)
{
+3 -1
View File
@@ -1,6 +1,8 @@
#include "swap.h"
#include "common/sysctl.h"
void ffDetectSwapImpl(FFMemoryStorage* swap)
{
ffStrbufAppendS(&swap->error, "Not implemented");
swap->bytesTotal = (uint64_t)ffSysctlGetInt64("vm.swap_total", 0);
swap->bytesUsed = (uint64_t)ffSysctlGetInt64("vm.swap_reserved", 0);
}
+1 -1
View File
@@ -323,7 +323,7 @@ const FFTerminalFontResult* ffDetectTerminalFont(const FFinstance* instance)
if(terminalShell->terminalProcessName.length == 0)
ffStrbufAppendS(&result.error, "Terminal font needs successfull terminal detection");
else if(detectTerminalFontCommon(instance, terminalShell, &result))
else if(!detectTerminalFontCommon(instance, terminalShell, &result))
ffDetectTerminalFontPlatform(instance, terminalShell, &result);
if(result.error.length == 0 && result.font.pretty.length == 0)
@@ -13,6 +13,10 @@
#ifdef __APPLE__
#include <libproc.h>
#elif defined(__FreeBSD__)
#include <sys/types.h>
#include <sys/user.h>
#include <sys/sysctl.h>
#endif
static void setExeName(FFstrbuf* exe, const char** exeName)
@@ -47,7 +51,13 @@ static void getProcessInformation(pid_t pid, FFstrbuf* processName, FFstrbuf* ex
#else
//TODO: support bsd (https://www.freebsd.org/cgi/man.cgi?query=kinfo_getproc)
size_t size = exe->allocated;
if(!sysctl(
(int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid}, 4,
exe->chars, &size,
NULL, 0
))
exe->length = (uint32_t)size;
#endif
@@ -92,8 +102,19 @@ static const char* getProcessNameAndPpid(pid_t pid, char* name, pid_t* ppid)
#else
//TODO: support bsd (https://www.freebsd.org/cgi/man.cgi?query=kinfo_getproc)
error = "unimplemented";
struct kinfo_proc proc;
size_t size = sizeof(proc);
if(sysctl(
(int[]){CTL_KERN, KERN_PROC, KERN_PROC_PID, pid}, 4,
&proc, &size,
NULL, 0
))
error = "sysctl(KERN_PROC_PID) failed";
else
{
*ppid = (pid_t)proc.ki_ppid;
strncpy(name, proc.ki_comm, COMMLEN);
}
#endif
@@ -2,6 +2,7 @@
#include <time.h>
#include <sys/sysctl.h>
#include <sys/time.h>
uint64_t ffDetectUptime(const FFinstance* instance)
{
+34 -1
View File
@@ -1300,6 +1300,38 @@ static const FFlogo* getLogoWindows11()
{
FF_LOGO_INIT
FF_LOGO_NAMES("Windows 11", "Windows Server 2022")
FF_LOGO_LINES(
"$1\n"
",,**************/ ///////////////()\n"
"****************/ ///////////////((\n"
"***************// //////////////(((\n"
"**************/// ////////////(((((\n"
"************///// /////////((((((((\n"
"*********//////// /////((((((((((((\n"
"*******////////// ///((((((((((((((\n"
"****///////////// (((((((((((((((((\n"
"\n"
"/////////////(((( (((((((((((((((((\n"
"////////////((((( (((((((((((((((((\n"
"///////////(((((( (((((((((((((((((\n"
"/////////(((((((( (((((((((((((((((\n"
"///////(((((((((( (((((((((((((((((\n"
"////((((((((((((( (((((((((((((((((\n"
"((((((((((((((((( (((((((((((((((((\n"
"((((((((((((((((( (((((((((((((((()"
)
FF_LOGO_COLORS(
"34" //blue
)
FF_LOGO_COLOR_KEYS("33"); //yellow
FF_LOGO_COLOR_TITLE("36"); //cyan
FF_LOGO_RETURN
}
static const FFlogo* getLogoWindows11Old()
{
FF_LOGO_INIT
FF_LOGO_NAMES("Windows 11_old")
FF_LOGO_LINES(
"$1\n"
"################ ################\n"
@@ -1354,7 +1386,7 @@ static const FFlogo* getLogoWindows8()
FF_LOGO_COLORS(
"36" //cyan
)
FF_LOGO_COLOR_KEYS("36"); //cyan
FF_LOGO_COLOR_KEYS("33"); //yellow
FF_LOGO_COLOR_TITLE("37"); //white
FF_LOGO_RETURN
}
@@ -2133,6 +2165,7 @@ GetLogoMethod* ffLogoBuiltinGetAll()
getLogoMintOld,
getLogoMsys2,
getLogoWindows11,
getLogoWindows11Old,
getLogoWindows8,
getLogoWindows,
getLogoNixOS,
+9 -1
View File
@@ -9,7 +9,15 @@ void ffPrintKernel(FFinstance* instance)
if(instance->config.kernel.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernel.key);
puts(instance->state.utsname.release);
#ifdef _WIN32
if(instance->state.utsname.version[0] != '\0')
printf("%s (%s)\n", instance->state.utsname.release, instance->state.utsname.version);
else
puts(instance->state.utsname.release);
#else
puts(instance->state.utsname.release);
#endif
}
else
{
+1
View File
@@ -53,6 +53,7 @@ void ffPrintPackages(FFinstance* instance)
FF_PRINT_PACKAGE(brew)
FF_PRINT_PACKAGE(port)
FF_PRINT_PACKAGE(scoop)
FF_PRINT_PACKAGE(choco)
//Fix linter warning of unused value of all
(void) all;
+114
View File
@@ -0,0 +1,114 @@
#include "fastfetch.h"
#include "utsname.h"
#define WIN32_LEAN_AND_MEAN 1
#include <Windows.h>
static int detectSysname(struct utsname *name)
{
strncpy(name->sysname, "Windows_NT", UTSNAME_MAXLENGTH);
return 0;
}
static int detectNodename(struct utsname *name)
{
DWORD bufSize = UTSNAME_MAXLENGTH - 1;
if(!GetComputerNameA(name->nodename, &bufSize))
return 1;
name->nodename[bufSize] = '\0';
return 0;
}
static int detectVersion(struct utsname *name)
{
HKEY hKey;
if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
return 1;
DWORD bufSize;
DWORD currentMajorVersionNumber;
bufSize = sizeof(currentMajorVersionNumber);
if(RegGetValueA(hKey, NULL, "CurrentMajorVersionNumber", RRF_RT_REG_DWORD, NULL, &currentMajorVersionNumber, &bufSize) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return 1;
}
DWORD currentMinorVersionNumber;
bufSize = sizeof(currentMinorVersionNumber);
if(RegGetValueA(hKey, NULL, "CurrentMinorVersionNumber", RRF_RT_REG_DWORD, NULL, &currentMinorVersionNumber, &bufSize) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return 1;
}
char currentBuildNumber[32];
bufSize = sizeof(currentBuildNumber);
if(RegGetValueA(hKey, NULL, "CurrentBuildNumber", RRF_RT_REG_SZ, NULL, currentBuildNumber, &bufSize) != ERROR_SUCCESS)
strcpy(currentBuildNumber, "0");
DWORD ubr;
bufSize = sizeof(ubr);
if(RegGetValueA(hKey, NULL, "UBR", RRF_RT_REG_DWORD, NULL, &ubr, &bufSize) != ERROR_SUCCESS || bufSize != sizeof(ubr))
ubr = 0;
snprintf(name->release, sizeof(name->release), "%u.%u.%s.%u", (unsigned)currentMajorVersionNumber, (unsigned)currentMinorVersionNumber, currentBuildNumber, (unsigned)ubr);
bufSize = sizeof(name->version);
RegGetValueA(hKey, NULL, "DisplayVersion", RRF_RT_REG_SZ, NULL, name->version, &bufSize);
RegCloseKey(hKey);
return 0;
}
static int detectMachine(struct utsname *name)
{
// Get hardware info
SYSTEM_INFO sysInfo = {0};
GetNativeSystemInfo(&sysInfo);
// Set processor architecture
switch(sysInfo.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
strcpy(name->machine, "x86_64");
break;
case PROCESSOR_ARCHITECTURE_IA64:
strcpy(name->machine, "ia64");
break;
case PROCESSOR_ARCHITECTURE_INTEL:
strcpy(name->machine, "x86");
break;
case PROCESSOR_ARCHITECTURE_ARM64:
strcpy(name->machine, "aarch64");
break;
case PROCESSOR_ARCHITECTURE_ARM:
strcpy(name->machine, "arm");
break;
case PROCESSOR_ARCHITECTURE_PPC:
strcpy(name->machine, "ppc");
break;
case PROCESSOR_ARCHITECTURE_MIPS:
strcpy(name->machine, "mips");
break;
case PROCESSOR_ARCHITECTURE_UNKNOWN:
default:
strcpy(name->machine, "unknown");
break;
}
return 0;
}
int uname(struct utsname *name)
{
memset(name, 0, sizeof(*name));
int sysnameResult = detectSysname(name);
int nodenameResult = detectNodename(name);
int versionResult = detectVersion(name);
int machineResult = detectMachine(name);
return sysnameResult || nodenameResult || versionResult || machineResult;
}
-35
View File
@@ -1,35 +0,0 @@
#include "util/windows/wmi.hpp"
extern "C" {
#include "utsname.h"
}
int uname(struct utsname *name)
{
memset(name, 0, sizeof(*name));
strncpy(name->sysname, "Windows_NT", UTSNAME_MAXLENGTH);
FFWmiQuery query(L"SELECT Version, CSName, OSArchitecture FROM Win32_OperatingSystem");
if(!query)
return -1;
if(FFWmiRecord record = query.next())
{
FFstrbuf value;
ffStrbufInit(&value);
record.getString(L"Version", &value);
strncpy(name->release, value.chars, UTSNAME_MAXLENGTH);
ffStrbufClear(&value);
record.getString(L"CSName", &value);
strncpy(name->nodename, value.chars, UTSNAME_MAXLENGTH);
ffStrbufClear(&value);
record.getString(L"OSArchitecture", &value);
strncpy(name->machine, value.chars, UTSNAME_MAXLENGTH);
ffStrbufDestroy(&value);
}
return 0;
}