Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d670a9a
Kernel: support Windows 7
CarterLi Nov 5, 2022
f889d91
TerminalShell: add basic support for ConEmu
CarterLi Nov 6, 2022
0605cb7
OS: fix Windows 7 detection
CarterLi Nov 6, 2022
1ea4441
TerminalFont: add support for ConEmu
CarterLi Nov 6, 2022
85a554b
CPU: support Windows 7
CarterLi Nov 6, 2022
f4666fc
README: document Windows 10- support
CarterLi Nov 6, 2022
e3de39d
Windows: add version info in binaries
CarterLi Nov 5, 2022
a5306d6
Windows: enable console processing, disable output buffer
CarterLi Nov 12, 2022
227eb70
CpuUsage: fix calucation on Windows
CarterLi Nov 15, 2022
3f008c4
CpuUsage: improve performance
CarterLi Nov 15, 2022
0bbecb3
Thread: silence compiler warnings
CarterLi Nov 16, 2022
8aca8a2
Temps: silence compiler warnings
CarterLi Nov 15, 2022
d0c18c4
DisplayServer: don't use private API (macOS)
CarterLi Nov 16, 2022
0361a30
Font: simplify code; fix memleaks (macOS)
CarterLi Nov 16, 2022
d0d6f48
osascript: simplify code (macOS)
CarterLi Nov 16, 2022
a498e9e
CPU: don't remove `(R)` in CPU name to be consistant with GPU name
CarterLi Nov 17, 2022
fb78d9b
TerminalFont: support Warp; improve performance of Apple Terminal (ma…
CarterLi Nov 17, 2022
e8e586c
Windows / macOS: simplify code
CarterLi Nov 12, 2022
fde9379
Android: simplify code; fix mistakes in terminal font detection code
CarterLi Nov 17, 2022
2a34978
Thread: silence compiler warnings
CarterLi Nov 16, 2022
7084785
GPU: remove special handling for WSL
CarterLi Nov 17, 2022
f1cc942
Host: detect WSL version
CarterLi Nov 17, 2022
859f645
Disk: fix size detection on 32bit Linux
CarterLi Nov 17, 2022
0a65867
Windows: fix memleaks
CarterLi Nov 19, 2022
55c6374
WmTheme: support Windows 7
CarterLi Nov 19, 2022
b6b9558
Windows: partially revert a5306d60eec383f0c697bd16ac308254dc1dce45 to…
CarterLi Nov 19, 2022
1c69d6c
Disk: use statvfs64 only when __USE_LARGEFILE64 is defined
CarterLi Nov 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ project(fastfetch
HOMEPAGE_URL "https://github.com/LinusDierheimer/fastfetch"
)

set(PROJECT_LICENSE "MIT license")

###################
# Target Platform #
###################
Expand Down Expand Up @@ -578,6 +580,26 @@ target_link_libraries(flashfetch
PRIVATE libfastfetch
)

if(WIN32)
if(PROJECT_VERSION_TWEAK)
string(REGEX MATCH "[0-9]+" PROJECT_VERSION_TWEAK_NUM "${PROJECT_VERSION_TWEAK}")
else()
set(PROJECT_VERSION_TWEAK_NUM "0")
endif()

set(TARGET_NAME fastfetch)
configure_file(src/util/windows/version.rc.in version.fastfetch.rc)
target_sources(fastfetch
PRIVATE version.fastfetch.rc
)

set(TARGET_NAME flashfetch)
configure_file(src/util/windows/version.rc.in version.flashfetch.rc)
target_sources(flashfetch
PRIVATE version.flashfetch.rc
)
endif()

###################
# Testing targets #
###################
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Fastfetch

Fastfetch is a [neofetch](https://github.com/dylanaraps/neofetch)-like tool for fetching system information and displaying them in a pretty way. It is written in pure c, with performance and customizability in mind. Currently Linux, Android, FreeBSD, MacOS and Windows are supported.
Fastfetch is a [neofetch](https://github.com/dylanaraps/neofetch)-like tool for fetching system information and displaying them in a pretty way. It is written in pure c, with performance and customizability in mind. Currently Linux, Android, FreeBSD, MacOS and Windows 7+ are supported.

<img src="screenshots/example1.png" width="49%" align="left" />
<img src="https://upload.wikimedia.org/wikipedia/commons/2/24/Transparent_Square_Tiles_Texture.png" width="49%" height="16px" align="left" />
Expand Down Expand Up @@ -61,6 +61,8 @@ The following libraries are used if present at runtime:
* [`libvulkan`](https://www.vulkan.org/): Vulkan module. Usually has been provided by GPU drivers.
* [`libOpenCL`](https://www.khronos.org/opencl/): OpenCL module

Note: On Windows 10-, [ConEmu](https://conemu.github.io/en/AnsiEscapeCodes.html) is required to run fastfetch due to [the lack of ASCII escape code native support](https://en.wikipedia.org/wiki/ANSI_escape_code#DOS,_OS/2,_and_Windows). Also make sure to [use `chcp 65001` to enable UTF-8 support](https://conemu.github.io/en/UnicodeSupport.html#utf-8) if you run Windows locale other than English.

### Android

* [`freetype`](https://www.freetype.org/): Used for Termux font detection.
Expand Down Expand Up @@ -101,7 +103,7 @@ KDE Plasma, Gnome, Cinnamon, Mate, XFCE4, LXQt

##### Terminal fonts
```
Konsole, Gnome Terminal, Tilix, XFCE4 Terminal, Alacritty, LXTerminal, iTerm2, Apple Terminal, TTY, Windows Terminal, Termux, mintty
Konsole, Gnome Terminal, Tilix, XFCE4 Terminal, Alacritty, LXTerminal, iTerm2, Apple Terminal, Warp, TTY, Windows Terminal, Termux, mintty, ConEmu
```

## Building
Expand Down
12 changes: 7 additions & 5 deletions src/common/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,9 @@ static void resetConsole()
#ifdef _WIN32
BOOL WINAPI consoleHandler(DWORD signal)
{
if(signal == CTRL_C_EVENT)
{
FF_UNUSED(signal);
resetConsole();
return TRUE;
}
return false;
exit(0);
}
#else
static void exitSignalHandler(int signal)
Expand All @@ -360,6 +357,11 @@ void ffStart(FFinstance* instance)

#ifdef _WIN32
SetConsoleCtrlHandler(consoleHandler, TRUE);
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD mode = 0;
GetConsoleMode(hStdout, &mode);
SetConsoleMode(hStdout, mode | ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
// SetConsoleOutputCP(CP_UTF8);
#else
struct sigaction action = { .sa_handler = exitSignalHandler };
sigaction(SIGINT, &action, NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/common/networking_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* host, con

#ifdef FF_HAVE_THREADS
state->thread = ffThreadCreate(connectAndSendThreadMain, state);
return state->thread != NULL;
return !!state->thread;
#else
connectAndSend(state);
return state->sockfd != -1;
Expand Down
4 changes: 1 addition & 3 deletions src/common/networking_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* host, con
}
}

FFstrbuf command;
FF_STRBUF_AUTO_DESTROY command;
ffStrbufInitA(&command, 64);
ffStrbufAppendS(&command, "GET ");
ffStrbufAppendS(&command, path);
Expand All @@ -87,15 +87,13 @@ bool ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* host, con

BOOL result = ConnectEx(state->sockfd, addr->ai_addr, (int)addr->ai_addrlen, command.chars, command.length, NULL, &state->overlapped);
freeaddrinfo(addr);
ffStrbufDestroy(&command);

if(!result && WSAGetLastError() != WSA_IO_PENDING)
{
closesocket(state->sockfd);
return false;
}

ffStrbufDestroy(&command);
return true;
}

Expand Down
41 changes: 22 additions & 19 deletions src/common/processing_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,30 @@ const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
.hStdOutput = hChildStdoutWrite,
};

FFstrbuf cmdline;
ffStrbufInitF(&cmdline, "\"%s\"", argv[0]);
for(char* const* parg = &argv[1]; *parg; ++parg)
{
ffStrbufAppendC(&cmdline, ' ');
ffStrbufAppendS(&cmdline, *parg);
}
BOOL success;

BOOL success = CreateProcessA(
NULL, // application name
cmdline.chars, // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
{
FF_STRBUF_AUTO_DESTROY cmdline;
ffStrbufInitF(&cmdline, "\"%s\"", argv[0]);
for(char* const* parg = &argv[1]; *parg; ++parg)
{
ffStrbufAppendC(&cmdline, ' ');
ffStrbufAppendS(&cmdline, *parg);
}

ffStrbufDestroy(&cmdline);
success = CreateProcessA(
NULL, // application name
cmdline.chars, // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo // receives PROCESS_INFORMATION
);
}

CloseHandle(hChildStdoutWrite);
if(!success)
Expand Down
2 changes: 1 addition & 1 deletion src/common/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
static inline void ffThreadMutexLock(FFThreadMutex* mutex) { pthread_mutex_lock(mutex); }
static inline void ffThreadMutexUnlock(FFThreadMutex* mutex) { pthread_mutex_unlock(mutex); }
static inline FFThreadType ffThreadCreate(void* (* func)(void*), void* data) {
FFThreadType newThread = NULL;
FFThreadType newThread = 0;
pthread_create(&newThread, NULL, func, data);
return newThread;
}
Expand Down
3 changes: 1 addition & 2 deletions src/detection/battery/battery_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

static double detectBatteryTemp()
{
FFlist temps;
FF_LIST_AUTO_DESTROY temps;
ffListInit(&temps, sizeof(FFTempValue));

ffDetectCoreTemps(FF_TEMP_BATTERY, &temps);
Expand All @@ -25,7 +25,6 @@ static double detectBatteryTemp()
ffStrbufDestroy(&tempValue->deviceClass);
}
result /= temps.length;
ffListDestroy(&temps);
return result;
}

Expand Down
1 change: 0 additions & 1 deletion src/detection/cpu/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ static void detectCPU(const FFinstance* instance, FFCPUResult* cpu)
return;

const char* removeStrings[] = {
"(R)", "(r)", "(TM)", "(tm)",
" CPU", " FPU", " APU", " Processor",
" Dual-Core", " Quad-Core", " Six-Core", " Eight-Core", " Ten-Core",
" 2-Core", " 4-Core", " 6-Core", " 8-Core", " 10-Core", " 12-Core", " 14-Core", " 16-Core",
Expand Down
3 changes: 1 addition & 2 deletions src/detection/cpu/cpu_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static double getFrequency(const char* propName)

static double detectCpuTemp(const FFstrbuf* cpuName)
{
FFlist temps;
FF_LIST_AUTO_DESTROY temps;
ffListInit(&temps, sizeof(FFTempValue));

if(ffStrbufStartsWithS(cpuName, "Apple M1"))
Expand All @@ -38,7 +38,6 @@ static double detectCpuTemp(const FFstrbuf* cpuName)
ffStrbufDestroy(&tempValue->deviceClass);
}
result /= temps.length;
ffListDestroy(&temps);
return result;
}

Expand Down
17 changes: 13 additions & 4 deletions src/detection/cpu/cpu_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached)
ffStrbufInit(&cpu->name);
ffStrbufInit(&cpu->vendor);

FFWmiQuery query(L"SELECT Name, Manufacturer, NumberOfCores, NumberOfLogicalProcessors, ThreadCount, CurrentClockSpeed, MaxClockSpeed FROM Win32_Processor WHERE ProcessorType = 3");
FFWmiQuery query(L"SELECT Name, Manufacturer, NumberOfCores, NumberOfLogicalProcessors, NumberOfEnabledCore, CurrentClockSpeed, MaxClockSpeed FROM Win32_Processor WHERE ProcessorType = 3");
if(!query)
return;

if(FFWmiRecord record = query.next())
FFWmiRecord record = query.next();
if(!record)
{
//NumberOfEnabledCore is not supported on Windows 10-
query = FFWmiQuery(L"SELECT Name, Manufacturer, NumberOfCores, NumberOfLogicalProcessors, CurrentClockSpeed, MaxClockSpeed FROM Win32_Processor WHERE ProcessorType = 3");
if(!query)
return;
record = query.next();
}

if(record)
{
record.getString(L"Name", &cpu->name);
record.getString(L"Manufacturer", &cpu->vendor);
Expand All @@ -32,8 +42,7 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached)
cpu->coresPhysical = (uint16_t)value;
record.getUnsigned(L"NumberOfLogicalProcessors", &value);
cpu->coresLogical = (uint16_t)value;
record.getUnsigned(L"ThreadCount", &value);
cpu->coresOnline = (uint16_t)value;
cpu->coresOnline = record.getUnsigned(L"NumberOfEnabledCore", &value) ? (uint16_t)value : cpu->coresPhysical;
record.getUnsigned(L"CurrentClockSpeed", &value); //There's no MinClockSpeed in Win32_Processor
cpu->frequencyMin = (double)value / 1000.0;
record.getUnsigned(L"MaxClockSpeed", &value);
Expand Down
27 changes: 17 additions & 10 deletions src/detection/cpuUsage/cpuUsage.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,30 @@ const char* ffGetCpuUsageResult(double* result)
error = ffGetCpuUsageInfo(&inUseAll1, &totalAll1);
if(error)
return error;
ffTimeSleep(1000);
ffTimeSleep(250);
}
else
{
uint64_t duration = ffTimeGetTick() - startTime;
if(duration < 1000)
ffTimeSleep(1000 - (uint32_t) duration);
if(duration < 250)
ffTimeSleep(250 - (uint32_t) duration);
}

uint64_t inUseAll2, totalAll2;
error = ffGetCpuUsageInfo(&inUseAll2, &totalAll2);
if(error)
return error;

*result = (double)(inUseAll2 - inUseAll1) / (double)(totalAll2 - totalAll1) * 100;
while(true)
{
uint64_t inUseAll2, totalAll2;
error = ffGetCpuUsageInfo(&inUseAll2, &totalAll2);
if(error)
return error;

return NULL;
if(inUseAll2 != inUseAll1)
{
*result = (double)(inUseAll2 - inUseAll1) / (double)(totalAll2 - totalAll1) * 100;
return NULL;
}
else
ffTimeSleep(250);
}
}

#endif //FF_DETECTION_CPUUSAGE_NOWAIT
11 changes: 6 additions & 5 deletions src/detection/cpuUsage/cpuUsage_windows.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "fastfetch.h"
#include "cpuUsage.h"

#define WIN32_LEAN_AND_MEAN 1
#include <Windows.h>
#include <processthreadsapi.h>

static inline uint64_t fileTimeToUint64(const FILETIME* ft) {
return (((uint64_t)ft->dwHighDateTime) << 32) | ((uint64_t)ft->dwLowDateTime);
Expand All @@ -11,10 +10,12 @@ static inline uint64_t fileTimeToUint64(const FILETIME* ft) {
const char* ffGetCpuUsageInfo(uint64_t* inUseAll, uint64_t* totalAll)
{
FILETIME idleTime, kernelTime, userTime;
if(GetSystemTimes(&idleTime, &kernelTime, &userTime) == 0)
if(!GetSystemTimes(&idleTime, &kernelTime, &userTime))
return "GetSystemTimes() failed";

*inUseAll = fileTimeToUint64(&userTime) + fileTimeToUint64(&kernelTime);
*totalAll = *inUseAll + fileTimeToUint64(&idleTime);
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getsystemtimes
// `kernelTime` also includes the amount of time the system has been idle.
*totalAll = fileTimeToUint64(&userTime) + fileTimeToUint64(&kernelTime);
*inUseAll = *totalAll - fileTimeToUint64(&idleTime);
return NULL;
}
12 changes: 9 additions & 3 deletions src/detection/disk/disk_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ void ffDetectDisksImpl(FFDiskResult* disks)
#endif

//Detects stats
struct statvfs fs;
if(statvfs(disk->mountpoint.chars, &fs) != 0)
memset(&fs, 0, sizeof(struct statvfs)); //Set all values to 0, so our values get initialized to 0 too
#ifdef __USE_LARGEFILE64
struct statvfs64 fs;
if(statvfs64(disk->mountpoint.chars, &fs) != 0)
memset(&fs, 0, sizeof(struct statvfs64)); //Set all values to 0, so our values get initialized to 0 too
#else
struct statvfs fs;
if(statvfs(disk->mountpoint.chars, &fs) != 0)
memset(&fs, 0, sizeof(struct statvfs)); //Set all values to 0, so our values get initialized to 0 too
#endif

disk->bytesTotal = fs.f_blocks * fs.f_frsize;
disk->bytesUsed = disk->bytesTotal - (fs.f_bavail * fs.f_frsize);
Expand Down
Loading