2021-04-09 14:07:05 +02:00
|
|
|
#include "fastfetch.h"
|
2022-07-30 23:30:46 +02:00
|
|
|
#include "common/parsing.h"
|
2022-10-12 14:13:20 +08:00
|
|
|
#include "common/thread.h"
|
2022-09-06 15:42:37 +02:00
|
|
|
#include "detection/displayserver/displayserver.h"
|
2022-12-06 17:03:31 +08:00
|
|
|
#include "util/textModifier.h"
|
2023-03-10 17:49:03 +08:00
|
|
|
#include "logo/logo.h"
|
2021-04-09 14:07:05 +02:00
|
|
|
|
2022-06-18 14:25:31 +02:00
|
|
|
#include <stdlib.h>
|
2021-04-09 14:07:05 +02:00
|
|
|
#include <unistd.h>
|
2023-07-31 14:10:53 +08:00
|
|
|
#include <locale.h>
|
2022-10-13 18:12:54 +08:00
|
|
|
#ifdef _WIN32
|
2023-03-24 23:21:39 +08:00
|
|
|
#include <windows.h>
|
2023-01-02 11:49:41 +08:00
|
|
|
#include "util/windows/unicode.h"
|
2022-10-13 18:12:54 +08:00
|
|
|
#else
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#endif
|
2021-04-09 14:07:05 +02:00
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
FFinstance instance; // Global singleton
|
|
|
|
|
|
2021-04-09 14:07:05 +02:00
|
|
|
static void initState(FFstate* state)
|
|
|
|
|
{
|
2022-04-06 14:02:05 +02:00
|
|
|
state->logoWidth = 0;
|
2022-04-02 14:35:43 +02:00
|
|
|
state->logoHeight = 0;
|
|
|
|
|
state->keysHeight = 0;
|
2023-01-14 16:38:34 +01:00
|
|
|
|
2023-01-15 15:57:26 +01:00
|
|
|
ffPlatformInit(&state->platform);
|
2023-06-11 00:51:29 +08:00
|
|
|
state->configDoc = NULL;
|
2023-08-29 11:13:55 +08:00
|
|
|
state->resultDoc = NULL;
|
2021-04-09 14:07:05 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static void defaultConfig(void)
|
2021-04-09 14:07:05 +02:00
|
|
|
{
|
2023-10-25 14:43:46 +08:00
|
|
|
ffOptionsInitLogo(&instance.config.logo);
|
2023-10-25 14:37:48 +08:00
|
|
|
ffOptionsInitGeneral(&instance.config.general);
|
2023-10-25 15:38:46 +08:00
|
|
|
ffOptionsInitModules(&instance.config.modules);
|
2023-10-26 10:26:15 +08:00
|
|
|
ffOptionsInitDisplay(&instance.config.display);
|
2023-10-25 16:24:24 +08:00
|
|
|
ffOptionsInitLibrary(&instance.config.library);
|
2021-04-09 14:07:05 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
void ffInitInstance(void)
|
2021-04-09 14:07:05 +02:00
|
|
|
{
|
2023-01-15 15:57:26 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
|
//https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale?source=recommendations&view=msvc-170#utf-8-support
|
|
|
|
|
setlocale(LC_ALL, ".UTF8");
|
2023-07-31 14:10:53 +08:00
|
|
|
#else
|
|
|
|
|
// used for mbsrtowcs in Module `separator`
|
|
|
|
|
setlocale(LC_ALL, "");
|
2023-01-15 15:57:26 +01:00
|
|
|
#endif
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
initState(&instance.state);
|
|
|
|
|
defaultConfig();
|
2021-04-09 14:07:05 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-06 14:02:21 +02:00
|
|
|
static volatile bool ffDisableLinewrap = true;
|
|
|
|
|
static volatile bool ffHideCursor = true;
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static void resetConsole(void)
|
2021-10-23 15:48:24 +02:00
|
|
|
{
|
2022-06-06 14:02:21 +02:00
|
|
|
if(ffDisableLinewrap)
|
2021-10-23 15:48:24 +02:00
|
|
|
fputs("\033[?7h", stdout);
|
|
|
|
|
|
2022-06-06 14:02:21 +02:00
|
|
|
if(ffHideCursor)
|
2021-10-23 15:48:24 +02:00
|
|
|
fputs("\033[?25h", stdout);
|
2023-01-14 17:31:04 +08:00
|
|
|
|
2023-06-13 11:08:49 +08:00
|
|
|
#if defined(_WIN32)
|
2023-01-14 17:31:04 +08:00
|
|
|
fflush(stdout);
|
|
|
|
|
#endif
|
2021-10-23 15:48:24 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-13 18:12:54 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
BOOL WINAPI consoleHandler(DWORD signal)
|
|
|
|
|
{
|
2022-11-12 23:30:34 +08:00
|
|
|
FF_UNUSED(signal);
|
2023-02-24 17:45:04 +08:00
|
|
|
resetConsole();
|
2022-11-12 23:30:34 +08:00
|
|
|
exit(0);
|
2022-10-13 18:12:54 +08:00
|
|
|
}
|
|
|
|
|
#else
|
2021-10-23 15:48:24 +02:00
|
|
|
static void exitSignalHandler(int signal)
|
|
|
|
|
{
|
|
|
|
|
FF_UNUSED(signal);
|
2022-06-06 14:02:21 +02:00
|
|
|
resetConsole();
|
2021-10-23 15:48:24 +02:00
|
|
|
exit(0);
|
|
|
|
|
}
|
2022-10-13 18:12:54 +08:00
|
|
|
#endif
|
2021-10-23 15:48:24 +02:00
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
void ffStart(void)
|
2021-06-17 13:49:25 +02:00
|
|
|
{
|
2023-02-24 17:45:04 +08:00
|
|
|
#ifdef FF_START_DETECTION_THREADS
|
2023-10-25 13:39:13 +08:00
|
|
|
if(instance.config.general.multithreading)
|
2023-06-24 10:59:53 +08:00
|
|
|
startDetectionThreads();
|
2023-02-24 17:45:04 +08:00
|
|
|
#endif
|
2022-07-25 15:01:11 +02:00
|
|
|
|
2023-10-26 10:26:15 +08:00
|
|
|
ffDisableLinewrap = instance.config.display.disableLinewrap && !instance.config.display.pipe && !instance.state.resultDoc;
|
|
|
|
|
ffHideCursor = instance.config.display.hideCursor && !instance.config.display.pipe && !instance.state.resultDoc;
|
2021-10-23 15:48:24 +02:00
|
|
|
|
2022-10-13 18:12:54 +08:00
|
|
|
#ifdef _WIN32
|
2023-12-17 19:04:26 +08:00
|
|
|
if (instance.config.display.noBuffer)
|
|
|
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
|
|
|
|
else
|
|
|
|
|
setvbuf(stdout, NULL, _IOFBF, 4096);
|
2022-10-13 18:12:54 +08:00
|
|
|
SetConsoleCtrlHandler(consoleHandler, TRUE);
|
2022-11-12 23:30:34 +08:00
|
|
|
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
DWORD mode = 0;
|
|
|
|
|
GetConsoleMode(hStdout, &mode);
|
|
|
|
|
SetConsoleMode(hStdout, mode | ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
|
2022-12-10 22:21:11 +08:00
|
|
|
SetConsoleOutputCP(CP_UTF8);
|
2022-10-13 18:12:54 +08:00
|
|
|
#else
|
2023-10-26 10:26:15 +08:00
|
|
|
if (instance.config.display.noBuffer) setvbuf(stdout, NULL, _IONBF, 0);
|
2022-10-13 18:12:54 +08:00
|
|
|
struct sigaction action = { .sa_handler = exitSignalHandler };
|
2021-10-23 15:48:24 +02:00
|
|
|
sigaction(SIGINT, &action, NULL);
|
|
|
|
|
sigaction(SIGTERM, &action, NULL);
|
|
|
|
|
sigaction(SIGQUIT, &action, NULL);
|
2022-10-13 18:12:54 +08:00
|
|
|
#endif
|
2021-10-23 15:48:24 +02:00
|
|
|
|
2022-04-02 14:35:43 +02:00
|
|
|
//reset everything to default before we start printing
|
2023-10-26 10:26:15 +08:00
|
|
|
if(!instance.config.display.pipe && !instance.state.resultDoc)
|
2022-06-06 14:02:21 +02:00
|
|
|
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
|
2022-04-02 14:35:43 +02:00
|
|
|
|
2022-06-06 14:02:21 +02:00
|
|
|
if(ffHideCursor)
|
2021-06-17 13:49:25 +02:00
|
|
|
fputs("\033[?25l", stdout);
|
|
|
|
|
|
2022-06-06 14:02:21 +02:00
|
|
|
if(ffDisableLinewrap)
|
2021-06-17 13:49:25 +02:00
|
|
|
fputs("\033[?7l", stdout);
|
2022-04-02 14:35:43 +02:00
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
ffLogoPrint();
|
2021-06-17 13:49:25 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
void ffFinish(void)
|
2021-04-09 14:07:05 +02:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
if(instance.config.logo.printRemaining)
|
|
|
|
|
ffLogoPrintRemaining();
|
2022-06-06 14:02:21 +02:00
|
|
|
|
|
|
|
|
resetConsole();
|
2022-09-22 22:02:58 +02:00
|
|
|
}
|
2022-09-22 21:28:20 +08:00
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static void destroyConfig(void)
|
2022-10-09 13:34:55 +02:00
|
|
|
{
|
2023-10-25 14:43:46 +08:00
|
|
|
ffOptionsDestroyLogo(&instance.config.logo);
|
|
|
|
|
ffOptionsDestroyGeneral(&instance.config.general);
|
2023-10-25 15:38:46 +08:00
|
|
|
ffOptionsDestroyModules(&instance.config.modules);
|
2023-10-26 10:26:15 +08:00
|
|
|
ffOptionsDestroyDisplay(&instance.config.display);
|
2023-10-25 16:24:24 +08:00
|
|
|
ffOptionsDestroyLibrary(&instance.config.library);
|
2022-10-09 13:34:55 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static void destroyState(void)
|
2022-10-09 13:34:55 +02:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
ffPlatformDestroy(&instance.state.platform);
|
|
|
|
|
yyjson_doc_free(instance.state.configDoc);
|
2023-08-29 11:13:55 +08:00
|
|
|
yyjson_mut_doc_free(instance.state.resultDoc);
|
2023-11-10 15:47:09 +08:00
|
|
|
ffStrbufDestroy(&instance.state.genConfigPath);
|
2022-10-09 13:34:55 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
void ffDestroyInstance(void)
|
2022-10-09 13:34:55 +02:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
destroyConfig();
|
|
|
|
|
destroyState();
|
2021-04-09 14:07:05 +02:00
|
|
|
}
|
2022-02-13 23:51:13 +01:00
|
|
|
|
2022-04-02 14:35:43 +02:00
|
|
|
//Must be in a file compiled with the libfastfetch target, because the FF_HAVE* macros are not defined for the executable targets
|
2023-06-24 10:59:53 +08:00
|
|
|
void ffListFeatures(void)
|
2022-02-13 23:51:13 +01:00
|
|
|
{
|
|
|
|
|
fputs(
|
2023-02-25 15:29:12 +08:00
|
|
|
#ifdef FF_HAVE_THREADS
|
|
|
|
|
"threads\n"
|
|
|
|
|
#endif
|
2022-02-13 23:51:13 +01:00
|
|
|
#ifdef FF_HAVE_VULKAN
|
|
|
|
|
"vulkan\n"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef FF_HAVE_WAYLAND
|
|
|
|
|
"wayland\n"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef FF_HAVE_XCB_RANDR
|
|
|
|
|
"xcb-randr\n"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef FF_HAVE_XCB
|
|
|
|
|
"xcb\n"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef FF_HAVE_XRANDR
|
|
|
|
|
"xrandr\n"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef FF_HAVE_X11
|
|
|
|
|
"x11\n"
|
|
|
|
|
#endif
|
2023-11-29 14:55:40 +08:00
|
|
|
#ifdef FF_HAVE_DRM
|
|
|
|
|
"drm\n"
|
|
|
|
|
#endif
|
2022-02-13 23:51:13 +01:00
|
|
|
#ifdef FF_HAVE_GIO
|
|
|
|
|
"gio\n"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef FF_HAVE_DCONF
|
|
|
|
|
"dconf\n"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef FF_HAVE_DBUS
|
|
|
|
|
"dbus\n"
|
|
|
|
|
#endif
|
2022-04-11 16:19:02 +02:00
|
|
|
#ifdef FF_HAVE_IMAGEMAGICK7
|
|
|
|
|
"imagemagick7\n"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef FF_HAVE_IMAGEMAGICK6
|
|
|
|
|
"imagemagick6\n"
|
2022-04-06 14:54:39 +02:00
|
|
|
#endif
|
2022-04-29 14:11:22 +02:00
|
|
|
#ifdef FF_HAVE_CHAFA
|
|
|
|
|
"chafa\n"
|
|
|
|
|
#endif
|
2022-04-14 15:11:14 +02:00
|
|
|
#ifdef FF_HAVE_ZLIB
|
|
|
|
|
"zlib\n"
|
|
|
|
|
#endif
|
2022-02-13 23:51:13 +01:00
|
|
|
#ifdef FF_HAVE_XFCONF
|
|
|
|
|
"xfconf\n"
|
|
|
|
|
#endif
|
2022-05-23 19:30:02 +02:00
|
|
|
#ifdef FF_HAVE_SQLITE3
|
|
|
|
|
"sqlite3\n"
|
2022-02-13 23:51:13 +01:00
|
|
|
#endif
|
2022-05-24 13:36:33 +02:00
|
|
|
#ifdef FF_HAVE_RPM
|
|
|
|
|
"rpm\n"
|
|
|
|
|
#endif
|
2022-06-04 15:21:34 +02:00
|
|
|
#ifdef FF_HAVE_EGL
|
|
|
|
|
"egl\n"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef FF_HAVE_GLX
|
|
|
|
|
"glx\n"
|
|
|
|
|
#endif
|
2022-06-04 19:30:26 +02:00
|
|
|
#ifdef FF_HAVE_OSMESA
|
|
|
|
|
"osmesa\n"
|
|
|
|
|
#endif
|
2022-06-05 00:18:40 +02:00
|
|
|
#ifdef FF_HAVE_OPENCL
|
|
|
|
|
"opencl\n"
|
|
|
|
|
#endif
|
2022-09-27 13:59:26 +08:00
|
|
|
#ifdef FF_HAVE_FREETYPE
|
2023-01-17 15:54:06 +08:00
|
|
|
"freetype\n"
|
|
|
|
|
#endif
|
2023-01-26 15:48:28 +01:00
|
|
|
#ifdef FF_HAVE_PULSE
|
|
|
|
|
"libpulse\n"
|
2023-01-26 00:49:43 +08:00
|
|
|
#endif
|
2023-01-17 15:54:06 +08:00
|
|
|
#ifdef FF_HAVE_LIBNM
|
|
|
|
|
"libnm\n"
|
2022-09-27 13:59:26 +08:00
|
|
|
#endif
|
2023-07-09 17:22:04 +08:00
|
|
|
#ifdef FF_HAVE_DDCUTIL
|
|
|
|
|
"libddcutil\n"
|
|
|
|
|
#endif
|
2023-10-02 23:19:44 +08:00
|
|
|
#ifdef FF_HAVE_DIRECTX_HEADERS
|
|
|
|
|
"Directx Headers\n"
|
|
|
|
|
#endif
|
2024-01-02 10:24:19 +08:00
|
|
|
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
|
|
|
|
|
"Proprietary GPU driver API\n"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef FF_USE_SYSTEM_YYJSON
|
|
|
|
|
"System yyjson\n"
|
|
|
|
|
#endif
|
2024-04-27 16:36:33 +08:00
|
|
|
#if __has_include(<linux/videodev2.h>)
|
|
|
|
|
"linux/videodev2\n"
|
|
|
|
|
#endif
|
|
|
|
|
#if __has_include(<linux/wireless.h>)
|
|
|
|
|
"linux/wireless\n"
|
2024-01-02 10:24:19 +08:00
|
|
|
#endif
|
2022-02-13 23:51:13 +01:00
|
|
|
""
|
|
|
|
|
, stdout);
|
|
|
|
|
}
|