diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index 7b3260a5e..a8884aa15 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -19,7 +19,10 @@ assignees: ''
# Often helpful information:
-The content of the configuration file you use (if any)
+Screenshot:
+
+
+The content of the configuration file you use (if any):
```
//paste here
```
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index cdbf5e67d..94dbc2ee0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -402,6 +402,9 @@ jobs:
echo -e "\n---\n\nSHA256SUMs
\n\n\`\`\`" >> fastfetch-release-notes.md
sha256sum fastfetch-*/* >> fastfetch-release-notes.md
echo -e "\`\`\`\n " >> fastfetch-release-notes.md
+ echo -e "\nSHA512SUMs
\n\n\`\`\`" >> fastfetch-release-notes.md
+ sha512sum fastfetch-*/* >> fastfetch-release-notes.md
+ echo -e "\`\`\`\n " >> fastfetch-release-notes.md
- name: update release body
if: needs.linux.outputs.ffversion != steps.get_version_release.outputs.release
diff --git a/CHANGELOG.md b/CHANGELOG.md
index de29ac606..4f9813b64 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,20 @@
+# 2.7.0
+
+Features:
+* Add new module `TerminalTheme`, which prints the foreground and background color of the current terminal window. Currently doesn't work on Windows.
+* Allow command substitution when expanding paths. For example, now it's possible to use `"source": "$(ls ~/path/to/images/*.png | shuf -n 1)"` in JSONC config file to randomly choose an image to display. (#698)
+* Use native methods instead of pciutils to detect GPUs in FreeBSD. (GPU, FreeBSD)
+
+Bugfixes:
+* Fix text formatting (Wifi, Linux)
+* Fix terminal detection in some cases (Terminal)
+* Remove trailing `\0` in JSON results (FreeBSD)
+* Fix uninitialized variables (GPU, Linux)
+* Fix a possible segfault (OpenCL)
+
+Logo:
+* Add ASCII logos for fedora immutable variants (#700)
+
# 2.6.3
Bugfixes:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0834a2d6c..7889e3c42 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url
project(fastfetch
- VERSION 2.6.3
+ VERSION 2.7.0
LANGUAGES C
DESCRIPTION "Fast neofetch-like system information tool"
HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
@@ -293,6 +293,7 @@ set(LIBFASTFETCH_SRC
src/detection/os/os.c
src/detection/packages/packages.c
src/detection/publicip/publicip.c
+ src/detection/terminaltheme/terminaltheme.c
src/detection/terminalfont/terminalfont.c
src/detection/terminalshell/terminalshell.c
src/detection/version/version.c
@@ -348,6 +349,7 @@ set(LIBFASTFETCH_SRC
src/modules/swap/swap.c
src/modules/media/media.c
src/modules/terminal/terminal.c
+ src/modules/terminaltheme/terminaltheme.c
src/modules/terminalfont/terminalfont.c
src/modules/terminalsize/terminalsize.c
src/modules/theme/theme.c
@@ -514,7 +516,7 @@ elseif(BSD)
src/detection/displayserver/linux/xcb.c
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
- src/detection/gpu/gpu_linux.c
+ src/detection/gpu/gpu_bsd.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_bsd.c
src/detection/lm/lm_linux.c
diff --git a/doc/json_schema.json b/doc/json_schema.json
index 88ffbec0b..ce10159d8 100644
--- a/doc/json_schema.json
+++ b/doc/json_schema.json
@@ -648,6 +648,7 @@
"terminal",
"terminalfont",
"terminalsize",
+ "terminaltheme",
"title",
"theme",
"uptime",
@@ -772,6 +773,10 @@
"const": "terminalsize",
"description": "Print current terminal size"
},
+ {
+ "const": "terminaltheme",
+ "description": "Print current terminal theme (foreground and background colors)"
+ },
{
"const": "theme",
"description": "Print current theme of desktop environment"
diff --git a/presets/all.jsonc b/presets/all.jsonc
index 53b553aea..06a415963 100644
--- a/presets/all.jsonc
+++ b/presets/all.jsonc
@@ -28,6 +28,7 @@
"terminal",
"terminalfont",
"terminalsize",
+ "terminaltheme",
"cpu",
"cpuusage",
"gpu",
diff --git a/presets/ci.jsonc b/presets/ci.jsonc
index 0283d9ec2..833f8a4d7 100644
--- a/presets/ci.jsonc
+++ b/presets/ci.jsonc
@@ -34,6 +34,7 @@
"terminal",
"terminalfont",
"terminalsize",
+ "terminaltheme",
"cpu",
"cpuusage",
"gpu",
diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c
index 029aaab62..2f1205260 100644
--- a/src/common/io/io_unix.c
+++ b/src/common/io/io_unix.c
@@ -115,7 +115,7 @@ bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* o
#if __has_include() // https://github.com/termux/termux-packages/pull/7056
wordexp_t exp;
- if(wordexp(in, &exp, WRDE_NOCMD) != 0)
+ if(wordexp(in, &exp, 0) != 0)
return false;
if (exp.we_wordc == 1)
diff --git a/src/common/modules.c b/src/common/modules.c
index 580e946f6..fa486261f 100644
--- a/src/common/modules.c
+++ b/src/common/modules.c
@@ -124,6 +124,7 @@ static FFModuleBaseInfo* T[] = {
(void*) &instance.config.modules.terminal,
(void*) &instance.config.modules.terminalFont,
(void*) &instance.config.modules.terminalSize,
+ (void*) &instance.config.modules.terminalTheme,
(void*) &instance.config.modules.title,
(void*) &instance.config.modules.theme,
NULL,
diff --git a/src/detection/gpu/gpu_bsd.c b/src/detection/gpu/gpu_bsd.c
new file mode 100644
index 000000000..a75f6cc27
--- /dev/null
+++ b/src/detection/gpu/gpu_bsd.c
@@ -0,0 +1,160 @@
+#include "gpu_driver_specific.h"
+
+#include "common/io/io.h"
+#include "3rdparty/nvml/nvml.h"
+#include "util/mallocHelper.h"
+#include "common/io/io.h"
+
+#include
+#include
+#include
+#include
+
+static bool loadPciIds(FFstrbuf* pciids)
+{
+ // https://github.com/freebsd/freebsd-src/blob/main/usr.sbin/pciconf/pathnames.h
+
+ ffReadFileBuffer(_PATH_LOCALBASE "/share/pciids/pci.ids", pciids);
+ if (pciids->length > 0) return true;
+
+ ffReadFileBuffer("/usr/share/pciids/pci.ids", pciids);
+ if (pciids->length > 0) return true;
+
+ return false;
+}
+
+const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
+{
+ FF_AUTO_CLOSE_FD int fd = open("/dev/pci", O_RDONLY, 0);
+ struct pci_conf confs[128];
+ struct pci_match_conf match = {
+ .pc_class = PCIC_DISPLAY,
+ .flags = PCI_GETCONF_MATCH_CLASS,
+ };
+ struct pci_conf_io pcio = {
+ .pat_buf_len = sizeof(match),
+ .num_patterns = 1,
+ .patterns = &match,
+ .match_buf_len = sizeof(confs),
+ .matches = confs,
+ };
+
+ if (ioctl(fd, PCIOCGETCONF, &pcio) < 0)
+ return "ioctl(fd, PCIOCGETCONF, &pc) failed";
+
+ if (pcio.status == PCI_GETCONF_ERROR)
+ return "ioctl(fd, PCIOCGETCONF, &pc) returned error";
+
+ FF_STRBUF_AUTO_DESTROY pciids = ffStrbufCreate();
+ loadPciIds(&pciids);
+
+ for (uint32_t i = 0; i < pcio.num_matches; ++i)
+ {
+ struct pci_conf* pc = &confs[i];
+
+ FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
+ ffStrbufInitStatic(&gpu->vendor, ffGetGPUVendorString(pc->pc_vendor));
+ ffStrbufInit(&gpu->name);
+ ffStrbufInitS(&gpu->driver, pc->pd_name);
+ ffStrbufInit(&gpu->platformApi);
+ gpu->temperature = FF_GPU_TEMP_UNSET;
+ gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
+ gpu->type = FF_GPU_TYPE_UNKNOWN;
+ gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
+ gpu->deviceId = ((uint64_t) pc->pc_vendor << 16) + pc->pc_device;
+ gpu->frequency = FF_GPU_FREQUENCY_UNSET;
+
+ if (pciids.length)
+ {
+ char buffer[32];
+ uint32_t len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n%04x ", pc->pc_vendor);
+ char* start = (char*) memmem(pciids.chars, pciids.length, buffer, len);
+ char* end = pciids.chars + pciids.length;
+ if (start)
+ {
+ start += len;
+ end = memchr(start, '\n', (uint32_t) (end - start));
+ if (!end)
+ end = pciids.chars + pciids.length;
+ if (!gpu->vendor.length)
+ ffStrbufSetNS(&gpu->vendor, (uint32_t) (end - start), start);
+
+ start = end; // point to '\n' of vendor
+ end = start + 1; // point to start of devices
+ // find the start of next vendor
+ while (end[0] == '\t' || end[0] == '#')
+ {
+ end = strchr(end, '\n');
+ if (!end)
+ {
+ end = pciids.chars + pciids.length;
+ break;
+ }
+ else
+ end++;
+ }
+
+ len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n\t%04x ", pc->pc_device);
+ start = memmem(start, (size_t) (end - start), buffer, len);
+ if (start)
+ {
+ start += len;
+ end = memchr(start, '\n', (uint32_t) (end - start));
+ if (!end)
+ end = pciids.chars + pciids.length;
+
+ char* openingBracket = memchr(start, '[', (uint32_t) (end - start));
+ if (openingBracket)
+ {
+ openingBracket++;
+ char* closingBracket = memchr(openingBracket, ']', (uint32_t) (end - openingBracket));
+ if (closingBracket)
+ ffStrbufSetNS(&gpu->name, (uint32_t) (closingBracket - openingBracket), openingBracket);
+ }
+ if (!gpu->name.length)
+ ffStrbufSetNS(&gpu->name, (uint32_t) (end - start), start);
+ }
+ }
+ }
+
+ if (!gpu->name.length)
+ {
+ const char* subclass;
+ switch (pc->pc_subclass)
+ {
+ case PCIS_DISPLAY_VGA: subclass = " (VGA compatible)"; break;
+ case PCIS_DISPLAY_XGA: subclass = " (XGA compatible)"; break;
+ case PCIS_DISPLAY_3D: subclass = " (3D)"; break;
+ default: subclass = ""; break;
+ }
+
+ ffStrbufSetF(&gpu->name, "%s Device %04X%s", gpu->vendor.length ? gpu->vendor.chars : "Unknown", pc->pc_device, subclass);
+ }
+
+ #ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
+ if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->driverSpecific))
+ {
+ ffDetectNvidiaGpuInfo(&(FFGpuDriverCondition) {
+ .type = FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID,
+ .pciBusId = {
+ .domain = (uint32_t) pc->pc_sel.pc_domain,
+ .bus = pc->pc_sel.pc_bus,
+ .device = pc->pc_sel.pc_dev,
+ .func = pc->pc_sel.pc_func,
+ },
+ }, (FFGpuDriverResult) {
+ .temp = options->temp ? &gpu->temperature : NULL,
+ .memory = options->driverSpecific ? &gpu->dedicated : NULL,
+ .coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL,
+ .type = &gpu->type,
+ .frequency = &gpu->frequency,
+ }, "libnvidia-ml.so");
+
+ if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET)
+ gpu->type = gpu->dedicated.total > (uint64_t)1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
+ }
+ #endif // FF_USE_PROPRIETARY_GPU_DRIVER_API
+ }
+
+ return NULL;
+}
diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c
index 340893090..1775295f7 100644
--- a/src/detection/gpu/gpu_linux.c
+++ b/src/detection/gpu/gpu_linux.c
@@ -209,16 +209,8 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
{
pci->ffpci_fill_info(device, PCI_FILL_CLASS);
- char class[1024];
- pci->ffpci_lookup_name(pci->access, class, sizeof(class) - 1, PCI_LOOKUP_CLASS, device->device_class);
-
- if(
- //https://pci-ids.ucw.cz/read/PD/03
- strcasecmp("VGA compatible controller", class) != 0 &&
- strcasecmp("XGA compatible controller", class) != 0 &&
- strcasecmp("3D controller", class) != 0 &&
- strcasecmp("Display controller", class) != 0
- ) return;
+ if (device->device_class >> 8 != PCI_BASE_CLASS_DISPLAY)
+ return;
pci->ffpci_fill_info(device, PCI_FILL_IDENT);
diff --git a/src/detection/gpu/gpu_wsl.cpp b/src/detection/gpu/gpu_wsl.cpp
index 91d67e54a..22bab850b 100644
--- a/src/detection/gpu/gpu_wsl.cpp
+++ b/src/detection/gpu/gpu_wsl.cpp
@@ -68,6 +68,7 @@ const char* ffGPUDetectByDirectX(FF_MAYBE_UNUSED const FFGPUOptions* options, FF
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
gpu->temperature = FF_GPU_TEMP_UNSET;
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
+ ffStrbufInitStatic(&gpu->platformApi, "DXCore");
ffStrbufInit(&gpu->driver);
uint64_t value = 0;
diff --git a/src/detection/opencl/opencl.c b/src/detection/opencl/opencl.c
index 3402c9311..957c1c1dc 100644
--- a/src/detection/opencl/opencl.c
+++ b/src/detection/opencl/opencl.c
@@ -23,15 +23,15 @@ typedef struct OpenCLData
static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result)
{
- cl_platform_id platformID;
- cl_uint numPlatforms;
+ cl_platform_id platformID = NULL;
+ cl_uint numPlatforms = 0;
data->ffclGetPlatformIDs(1, &platformID, &numPlatforms);
if(numPlatforms == 0)
return "clGetPlatformIDs returned 0 platforms";
- cl_device_id deviceID;
- cl_uint numDevices;
+ cl_device_id deviceID = NULL;
+ cl_uint numDevices = 0;
data->ffclGetDeviceIDs(platformID, CL_DEVICE_TYPE_GPU, 1, &deviceID, &numDevices);
if(numDevices == 0)
@@ -40,7 +40,7 @@ static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result)
if(numDevices == 0)
return "clGetDeviceIDs returned 0 devices";
- char version[64];
+ char version[64] = "";
data->ffclGetDeviceInfo(deviceID, CL_DEVICE_VERSION, sizeof(version), version, NULL);
if(!ffStrSet(version))
return "clGetDeviceInfo returned NULL or empty string";
diff --git a/src/detection/terminalfont/terminalfont_linux.c b/src/detection/terminalfont/terminalfont_linux.c
index 8f163418e..b4bd5e36f 100644
--- a/src/detection/terminalfont/terminalfont_linux.c
+++ b/src/detection/terminalfont/terminalfont_linux.c
@@ -315,7 +315,7 @@ void ffDetectTerminalFontPlatform(const FFTerminalResult* terminal, FFTerminalFo
detectFromConfigFile("lxterminal/lxterminal.conf", "fontname =", terminalFont);
else if(ffStrbufIgnCaseEqualS(&terminal->processName, "tilix"))
detectFromGSettings("/com/gexperts/Tilix/profiles/", "com.gexperts.Tilix.ProfilesList", "com.gexperts.Tilix.Profile", "default", terminalFont);
- else if(ffStrbufStartsWithIgnCaseS(&terminal->processName, "gnome-terminal-"))
+ else if(ffStrbufStartsWithIgnCaseS(&terminal->processName, "gnome-terminal"))
detectFromGSettings("/org/gnome/terminal/legacy/profiles:/:", "org.gnome.Terminal.ProfilesList", "org.gnome.Terminal.Legacy.Profile", "default", terminalFont);
else if(ffStrbufIgnCaseEqualS(&terminal->processName, "kgx"))
detectKgx(terminalFont);
diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c
index 78c309766..f4e56a124 100644
--- a/src/detection/terminalshell/terminalshell.c
+++ b/src/detection/terminalshell/terminalshell.c
@@ -281,7 +281,7 @@ FF_MAYBE_UNUSED static bool getTerminalVersionGnome(FFstrbuf* version)
FF_MAYBE_UNUSED static bool getTerminalVersionKgx(FFstrbuf* version)
{
if(ffProcessAppendStdOut(version, (char* const[]){
- "gnome-terminal",
+ "kgx",
"--version",
NULL
})) return false;
@@ -400,6 +400,15 @@ static bool getTerminalVersionContour(FFstrbuf* exe, FFstrbuf* version)
return version->length > 0;
}
+static bool getTerminalVersionScreen(FFstrbuf* exe, FFstrbuf* version)
+{
+ if(!getExeVersionRaw(exe, version)) return false;
+ // Screen version 4.09.01 (GNU) 20-Aug-23
+ ffStrbufSubstrAfter(version, strlen("Screen version ") - 1);
+ ffStrbufSubstrBeforeFirstC(version, ' ');
+ return version->length > 0;
+}
+
#ifdef _WIN32
static bool getTerminalVersionWindowsTerminal(FFstrbuf* exe, FFstrbuf* version)
@@ -440,7 +449,7 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
#if defined(__linux__) || defined(__FreeBSD__)
- if(ffStrbufStartsWithIgnCaseS(processName, "gnome-terminal-"))
+ if(ffStrbufStartsWithIgnCaseS(processName, "gnome-terminal"))
return getTerminalVersionGnome(version);
if(ffStrbufIgnCaseEqualS(processName, "konsole"))
@@ -511,6 +520,9 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
if(ffStrbufStartsWithIgnCaseS(processName, "contour"))
return getTerminalVersionContour(exe, version);
+ if(ffStrbufStartsWithIgnCaseS(processName, "screen"))
+ return getTerminalVersionScreen(exe, version);
+
const char* termProgramVersion = getenv("TERM_PROGRAM_VERSION");
if(termProgramVersion)
{
diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c
index c83dffde4..32ded8311 100644
--- a/src/detection/terminalshell/terminalshell_linux.c
+++ b/src/detection/terminalshell/terminalshell_linux.c
@@ -86,7 +86,7 @@ static void getProcessInformation(pid_t pid, FFstrbuf* processName, FFstrbuf* ex
args, &size,
NULL, 0
) == 0)
- ffStrbufSetS(exePath, args);
+ ffStrbufSetNS(exePath, (uint32_t) (size - 1), args);
size = ARG_MAX;
if(sysctl(
@@ -123,6 +123,9 @@ static void getProcessInformation(pid_t pid, FFstrbuf* processName, FFstrbuf* ex
static const char* getProcessNameAndPpid(pid_t pid, char* name, pid_t* ppid, int32_t* tty)
{
+ if (pid <= 0)
+ return "Invalid pid";
+
#ifdef __linux__
char statFilePath[64];
@@ -144,8 +147,13 @@ static const char* getProcessNameAndPpid(pid_t pid, char* name, pid_t* ppid, int
)
return "sscanf(stat) failed";
- if (tty && (tty_ >> 8) == 0x88)
- *tty = tty_ & 0xFF;
+ if (tty)
+ {
+ if ((tty_ >> 8) == 0x88)
+ *tty = tty_ & 0xFF;
+ else
+ *tty = -1;
+ }
#elif defined(__APPLE__)
@@ -209,11 +217,13 @@ static pid_t getShellInfo(FFShellResult* result, pid_t pid)
name[0] = '\0';
pid_t ppid = 0;
+ int32_t tty = -1;
- while (getProcessNameAndPpid(pid, name, &ppid, &result->tty) == NULL)
+ while (getProcessNameAndPpid(pid, name, &ppid, &tty) == NULL)
{
//Common programs that are between terminal and own process, but are not the shell
if(
+ // tty < 0 || //A shell should connect to a tty
ffStrEquals(name, "sh") || //This prevents us from detecting things like pipes and redirects, i hope nobody uses plain `sh` as shell
ffStrEquals(name, "sudo") ||
ffStrEquals(name, "su") ||
@@ -237,6 +247,7 @@ static pid_t getShellInfo(FFShellResult* result, pid_t pid)
result->pid = (uint32_t) pid;
result->ppid = (uint32_t) ppid;
+ result->tty = tty;
ffStrbufSetS(&result->processName, name);
getProcessInformation(pid, &result->processName, &result->exe, &result->exeName, &result->exePath);
break;
@@ -255,6 +266,7 @@ static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid)
{
//Known shells
if (
+ ffStrEquals(name, "sh") ||
ffStrEquals(name, "ash") ||
ffStrEquals(name, "bash") ||
ffStrEquals(name, "zsh") ||
@@ -272,6 +284,7 @@ static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid)
ffStrEquals(name, "oil.ovm") ||
ffStrEquals(name, "xonsh") || // works in Linux but not in macOS because kernel returns `Python` in this case
ffStrEquals(name, "login") ||
+ ffStrEquals(name, "sshd") ||
ffStrEndsWith(name, ".sh")
)
{
@@ -297,6 +310,21 @@ static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid)
return ppid;
}
+static bool getTerminalInfoByPidEnv(FFTerminalResult* result, const char* pidEnv)
+{
+ pid_t pid = (pid_t) strtol(getenv(pidEnv), NULL, 10);
+ result->pid = (uint32_t) pid;
+ char name[256];
+ if (getProcessNameAndPpid(pid, name, (pid_t*) &result->ppid, NULL) == NULL)
+ {
+ ffStrbufSetS(&result->processName, name);
+ getProcessInformation(pid, &result->processName, &result->exe, &result->exeName, &result->exePath);
+ return true;
+ }
+
+ return false;
+}
+
static void getTerminalFromEnv(FFTerminalResult* result)
{
if(
@@ -319,58 +347,80 @@ static void getTerminalFromEnv(FFTerminalResult* result)
const char* term = NULL;
//SSH
- if(getenv("SSH_CONNECTION") != NULL)
+ if(
+ getenv("SSH_TTY") != NULL
+ )
term = getenv("SSH_TTY");
+ else if(
+ getenv("KITTY_PID") != NULL ||
+ getenv("KITTY_INSTALLATION_DIR") != NULL
+ )
+ {
+ if (getTerminalInfoByPidEnv(result, "KITTY_PID"))
+ return;
+ term = "kitty";
+ }
- #ifdef __linux__
+ #ifdef __linux__ // WSL
//Windows Terminal
- if(!ffStrSet(term) && (
+ else if(
getenv("WT_SESSION") != NULL ||
getenv("WT_PROFILE_ID") != NULL
- )) term = "Windows Terminal";
+ ) term = "Windows Terminal";
//ConEmu
- if(!ffStrSet(term) && (
+ else if(
getenv("ConEmuPID") != NULL
- )) term = "ConEmu";
+ ) term = "ConEmu";
#endif
//Alacritty
- if(!ffStrSet(term) && (
+ else if(
getenv("ALACRITTY_SOCKET") != NULL ||
getenv("ALACRITTY_LOG") != NULL ||
getenv("ALACRITTY_WINDOW_ID") != NULL
- )) term = "Alacritty";
+ ) term = "Alacritty";
#ifdef __ANDROID__
//Termux
- if(!ffStrSet(term) && (
+ else if(
getenv("TERMUX_VERSION") != NULL ||
getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL
- )) term = "com.termux";
+ )
+ {
+ if (getTerminalInfoByPidEnv(result, "TERMUX_APP__PID"))
+ return;
+ term = "com.termux";
+ }
#endif
- #ifdef __linux__
+ #if defined(__linux__) || defined(__FreeBSD__)
//Konsole
- if(!ffStrSet(term) && (
+ else if(
getenv("KONSOLE_VERSION") != NULL
- )) term = "konsole";
+ ) term = "konsole";
+
+ else if(
+ getenv("GNOME_TERMINAL_SCREEN") != NULL ||
+ getenv("GNOME_TERMINAL_SERVICE") != NULL
+ ) term = "gnome-terminal";
#endif
//MacOS, mintty
- if(!ffStrSet(term))
+ else if(getenv("TERM_PROGRAM") != NULL)
term = getenv("TERM_PROGRAM");
- if(!ffStrSet(term))
+ else if(getenv("LC_TERMINAL") != NULL)
term = getenv("LC_TERMINAL");
//Normal Terminal
- if(!ffStrSet(term))
+ else
+ {
term = getenv("TERM");
-
- //TTY
- if(!ffStrSet(term) || ffStrEquals(term, "linux"))
- term = ttyname(STDIN_FILENO);
+ //TTY
+ if(!ffStrSet(term) || ffStrEquals(term, "linux"))
+ term = ttyname(STDIN_FILENO);
+ }
if(ffStrSet(term))
{
@@ -429,6 +479,8 @@ static void setTerminalInfoDetails(FFTerminalResult* result)
ffStrbufInitStatic(&result->prettyName, "WezTerm");
else if(ffStrbufStartsWithS(&result->processName, "tmux:"))
ffStrbufInitStatic(&result->prettyName, "tmux");
+ else if(ffStrbufStartsWithS(&result->processName, "screen-"))
+ ffStrbufInitStatic(&result->prettyName, "screen");
#if defined(__ANDROID__)
@@ -437,7 +489,7 @@ static void setTerminalInfoDetails(FFTerminalResult* result)
#elif defined(__linux__) || defined(__FreeBSD__)
- else if(ffStrbufStartsWithS(&result->processName, "gnome-terminal-"))
+ else if(ffStrbufStartsWithS(&result->processName, "gnome-terminal"))
ffStrbufInitStatic(&result->prettyName, "GNOME Terminal");
else if(ffStrbufStartsWithS(&result->processName, "kgx"))
ffStrbufInitStatic(&result->prettyName, "GNOME Console");
diff --git a/src/detection/terminalsize/terminalsize_linux.c b/src/detection/terminalsize/terminalsize_linux.c
index 68a75cbb2..b15939661 100644
--- a/src/detection/terminalsize/terminalsize_linux.c
+++ b/src/detection/terminalsize/terminalsize_linux.c
@@ -10,10 +10,10 @@ bool ffDetectTerminalSize(FFTerminalSizeResult* result)
ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize);
if (winsize.ws_row == 0 || winsize.ws_col == 0)
- ffGetTerminalResponse("\033[18t", "\033[8;%hu;%hut", &winsize.ws_row, &winsize.ws_col);
+ ffGetTerminalResponse("\e[18t", "\e[8;%hu;%hut", &winsize.ws_row, &winsize.ws_col);
if (winsize.ws_ypixel == 0 || winsize.ws_xpixel == 0)
- ffGetTerminalResponse("\033[14t", "\033[4;%hu;%hut", &winsize.ws_ypixel, &winsize.ws_xpixel);
+ ffGetTerminalResponse("\e[14t", "\e[4;%hu;%hut", &winsize.ws_ypixel, &winsize.ws_xpixel);
if (winsize.ws_row == 0 && winsize.ws_col == 0)
return false;
diff --git a/src/detection/terminalsize/terminalsize_windows.c b/src/detection/terminalsize/terminalsize_windows.c
index a0b554517..4d2f6c83d 100644
--- a/src/detection/terminalsize/terminalsize_windows.c
+++ b/src/detection/terminalsize/terminalsize_windows.c
@@ -14,7 +14,7 @@ bool ffDetectTerminalSize(FFTerminalSizeResult* result)
}
else
{
- ffGetTerminalResponse("\033[18t", "\033[8;%hu;%hut", &result->rows, &result->columns);
+ ffGetTerminalResponse("\e[18t", "\e[8;%hu;%hut", &result->rows, &result->columns);
}
}
diff --git a/src/detection/terminaltheme/terminaltheme.c b/src/detection/terminaltheme/terminaltheme.c
new file mode 100644
index 000000000..845eec637
--- /dev/null
+++ b/src/detection/terminaltheme/terminaltheme.c
@@ -0,0 +1,91 @@
+#include "terminaltheme.h"
+#include "common/io/io.h"
+#include "util/stringUtils.h"
+
+#include
+
+static bool detectByEscapeCode(FFTerminalThemeResult* result)
+{
+ int command = 0;
+
+ if (ffGetTerminalResponse("\e]10;?\e\\", "\e]%d;rgb:%" SCNx16 "/%" SCNx16 "/%" SCNx16 "\e\\", &command, &result->fg.r, &result->fg.g, &result->fg.b) == NULL)
+ {
+ if (command != 10)
+ return false;
+ if (result->fg.r > 0x0100 || result->fg.g > 0x0100 || result->fg.b > 0x0100)
+ result->fg.r /= 0x0100, result->fg.g /= 0x0100, result->fg.b /= 0x0100;
+ }
+ else
+ return false;
+
+ if (ffGetTerminalResponse("\e]11;?\e\\", "\e]%d;rgb:%" SCNx16 "/%" SCNx16 "/%" SCNx16 "\e\\", &command, &result->bg.r, &result->bg.g, &result->bg.b) == NULL)
+ {
+ if (command != 11)
+ return false;
+ if (result->bg.r > 0x0100 || result->bg.g > 0x0100 || result->bg.b > 0x0100)
+ result->bg.r /= 0x0100, result->bg.g /= 0x0100, result->bg.b /= 0x0100;
+ }
+ else
+ return false;
+
+ return true;
+}
+
+static FFTerminalThemeColor fgbgToColor(int num)
+{
+ // https://github.com/dalance/termbg/blob/13c478a433fa182e65c401d26a1e7792a7f7f453/src/lib.rs#L251
+ switch (num)
+ {
+ case 0: return (FFTerminalThemeColor){ 0, 0, 0, false}; // black
+ case 1: return (FFTerminalThemeColor){205, 0, 0, false}; // red
+ case 2: return (FFTerminalThemeColor){ 0, 205, 0, false}; // green
+ case 3: return (FFTerminalThemeColor){205, 205, 0, false}; // yellow
+ case 4: return (FFTerminalThemeColor){ 0, 0, 238, false}; // blue
+ case 5: return (FFTerminalThemeColor){205, 0, 205, false}; // magenta
+ case 6: return (FFTerminalThemeColor){ 0, 205, 205, false}; // cyan
+ case 7: return (FFTerminalThemeColor){229, 229, 229, false}; // white
+
+ case 8: return (FFTerminalThemeColor){127, 127, 127, false}; // bright black
+ case 9: return (FFTerminalThemeColor){255, 0, 0, false}; // bright red
+ case 10: return (FFTerminalThemeColor){ 0, 255, 0, false}; // bright green
+ case 11: return (FFTerminalThemeColor){255, 255, 0, false}; // bright yellow
+ case 12: return (FFTerminalThemeColor){ 92, 92, 255, false}; // bright blue
+ case 13: return (FFTerminalThemeColor){255, 0, 255, false}; // bright magenta
+ case 14: return (FFTerminalThemeColor){ 0, 255, 255, false}; // bright cyan
+ case 15: return (FFTerminalThemeColor){255, 255, 255, false}; // bright white
+
+ default: return (FFTerminalThemeColor){ 0, 0, 0, false}; // invalid
+ }
+}
+
+static bool detectByEnv(FFTerminalThemeResult* result)
+{
+ const char* color = getenv("COLORFGBG"); // 7;0
+
+ if (!ffStrSet(color))
+ return false;
+
+ int f, g;
+ if (sscanf(color, "%d;%d", &f, &g) != 2)
+ return false;
+
+ result->fg = fgbgToColor(f);
+ result->bg = fgbgToColor(g);
+ return true;
+}
+
+static inline bool detectColor(FFTerminalThemeResult* result)
+{
+ if (detectByEscapeCode(result))
+ return true;
+
+ return detectByEnv(result);
+}
+
+bool ffDetectTerminalTheme(FFTerminalThemeResult* result)
+{
+ if (!detectColor(result)) return false;
+ result->fg.dark = result->fg.r * 299 + result->fg.g * 587 + result->fg.b * 114 < 128000;
+ result->bg.dark = result->bg.r * 299 + result->bg.g * 587 + result->bg.b * 114 < 128000;
+ return true;
+}
diff --git a/src/detection/terminaltheme/terminaltheme.h b/src/detection/terminaltheme/terminaltheme.h
new file mode 100644
index 000000000..08bb4ea0f
--- /dev/null
+++ b/src/detection/terminaltheme/terminaltheme.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "fastfetch.h"
+
+typedef struct FFTerminalThemeColor
+{
+ uint16_t r;
+ uint16_t g;
+ uint16_t b;
+ bool dark;
+} FFTerminalThemeColor;
+
+typedef struct FFTerminalThemeResult
+{
+ FFTerminalThemeColor fg;
+ FFTerminalThemeColor bg;
+} FFTerminalThemeResult;
+
+bool ffDetectTerminalTheme(FFTerminalThemeResult* result);
diff --git a/src/detection/wifi/wifi_linux.c b/src/detection/wifi/wifi_linux.c
index 34af04fd4..d9788c994 100644
--- a/src/detection/wifi/wifi_linux.c
+++ b/src/detection/wifi/wifi_linux.c
@@ -250,7 +250,11 @@ static const char* detectWifiWithIoctls(FFlist* result)
item->conn.txRate = 0.0/0.0;
ffStrbufSetF(&path, "/sys/class/net/%s/operstate", i->if_name);
- if (!ffAppendFileBuffer(path.chars, &item->inf.status) || !ffStrbufEqualS(&item->inf.status, "up\n"))
+ if (!ffAppendFileBuffer(path.chars, &item->inf.status))
+ continue;
+
+ ffStrbufTrimRightSpace(&item->inf.status);
+ if (!ffStrbufEqualS(&item->inf.status, "up"))
continue;
FF_AUTO_CLOSE_FD int sock = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
diff --git a/src/fastfetch.c b/src/fastfetch.c
index 68bcea67f..affd59aad 100644
--- a/src/fastfetch.c
+++ b/src/fastfetch.c
@@ -300,7 +300,7 @@ static void listModules(bool pretty)
{
++count;
if (pretty)
- printf("%d)%s%-13s: %s\n", count, count > 9 ? " " : " ", (*modules)->name, (*modules)->description);
+ printf("%d)%s%-14s: %s\n", count, count > 9 ? " " : " ", (*modules)->name, (*modules)->description);
else
printf("%s:%s\n", (*modules)->name, (*modules)->description);
}
@@ -483,10 +483,8 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
if(isJsonConfig ? parseJsoncFile(value) : parseConfigFile(data, value))
return;
- FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128);
- if (ffPathExpandEnv(value, &absolutePath))
{
- bool success = isJsonConfig ? parseJsoncFile(absolutePath.chars) : parseConfigFile(data, absolutePath.chars);
+ bool success = isJsonConfig ? parseJsoncFile(value) : parseConfigFile(data, value);
if(success)
return;
@@ -494,6 +492,7 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
//Try to load as a relative path
+ FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128);
FF_LIST_FOR_EACH(FFstrbuf, path, instance.state.platform.dataDirs)
{
//We need to copy it, because if a config file loads a config file, the value of path must be unchanged
diff --git a/src/logo/ascii/container_linux.txt b/src/logo/ascii/fedora_coreos.txt
similarity index 100%
rename from src/logo/ascii/container_linux.txt
rename to src/logo/ascii/fedora_coreos.txt
diff --git a/src/logo/ascii/fedora_kinoite.txt b/src/logo/ascii/fedora_kinoite.txt
new file mode 100644
index 000000000..1d21a87b9
--- /dev/null
+++ b/src/logo/ascii/fedora_kinoite.txt
@@ -0,0 +1,18 @@
+ ,clll:.$2 .,::::::::::::'
+$1:ooooooo$2 .;::::::::::::::
+$1looooooo$2 ,:::::::::::::::'
+$1looooooo$2 .::::::::::::::::
+$1looooooo$2 ;:::::::::::::::.
+$1looooooo$2 .::::::::::::::::
+$1looooool$2;;;;,::::::::::::::::
+$1looool$2::, .::::::::::::::
+$1looooc$2:: ;::
+$1looooc$2::;. .::;
+$1loooool$2:::::::::::.
+$1looooooo$2. .::::::'
+$1looooooo$2 .::::::,;,..
+$1looooooo$2 :::;' ';:;.
+$1looooooo$2 ::: :::
+$1cooooooo$2 .::' '::.
+$1 .ooooc $2 ::, ,::
+ ''''
diff --git a/src/logo/ascii/fedora_sericea.txt b/src/logo/ascii/fedora_sericea.txt
new file mode 100644
index 000000000..69f01778c
--- /dev/null
+++ b/src/logo/ascii/fedora_sericea.txt
@@ -0,0 +1,17 @@
+ :oooo, .','
+ .';;;.;oooooooolooooo'
+ coooooooooooooooooooooooolc'
+ .':oooooooooooo$2ll$1ooooooooooooool
+.oooooooooooooooo$2ll$1oooooooooooo$2l$1ool
+ooooooooooooooooo$2ll$1ooooooooooo$2ll$1oo'
+ oooo$2l$1oooooooooo$2lll$1ooooooooo$2lll$1oo
+ .ooooo$2lll$1ooooo$2lll$1ooooooooo$2lll$1ool
+ .ooooooo$2lll$1oo$2llll$1oooo$2lllll$1ooooo:
+ 'oooooooo$2llllllllllll$1oooooooo'
+ .c,.oo$2lllll$1oooooooo.$2
+ 'll;
+ 'll.
+ lll
+ lll
+ ;ll,
+ .l:
diff --git a/src/logo/ascii/fedora_silverblue.txt b/src/logo/ascii/fedora_silverblue.txt
new file mode 100644
index 000000000..af96ca6cb
--- /dev/null
+++ b/src/logo/ascii/fedora_silverblue.txt
@@ -0,0 +1,17 @@
+ .;ooooooooooooooooooooooooooo.
+ ,dddddddddddddddddddddddddddddd'$3;
+$1 lddddddddddddddddddddddddddddd'$3;;;
+$1ddddd$2,XXX.$1ddddd$2,XXX.$1dddd'$2,XXX.$3;;;;;
+$1ddddd$2XX$1x$2XX$1ddddd$2XX$1x$2XX$1ddd'$2,XX$3x$2XX$3;;;;;
+$1ddddd$2'XXX'$1ddddd$2'XXX'$1dd'$2XXXXXX'$3;;;;;
+$1dddddd$2;X;$1ddddddd$2;X:$1d'$2XXX$3;;;;;;;;;;;
+$1dddddd$2;X;$1ddddddd$2;X:$2XXX$3;;;;;;;;;;;;;
+$1dddddd$2;X;$1dddddd'$2;XXX,,,,,,XXX.$3;;;;;
+$1dddddd$2;X;$1dddd'$2XXXX$2XXXXXXXXX$3x$2XX$3;;;;;
+$1dddddd$2;X;$1dd'$2XXX$3;;;;;;;;;;;$2XXX$3;;;;;;
+$1dddddd$2;X;$1'$2XXX$3;;;;;;;;;;;;;;;;;;;;;;
+$1dddddd$2;XXXXX,,,,,,,,,,,,,;XXX:$3;;;;;
+$1dddddd$2:XXXXXXXXXXXXXXXXXXXX$3x$2XX$3;;;;;
+$1ddddd'$3;;;;;;;;;;;;;;;;;;;$2'XXX'$3;;;;'
+$1ddd'$3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+$1o'$3;;;;;;;;;;;;;;;;;;;;;;;;;;;;'
diff --git a/src/logo/builtin.c b/src/logo/builtin.c
index 62d141fd1..42bddf865 100644
--- a/src/logo/builtin.c
+++ b/src/logo/builtin.c
@@ -974,7 +974,7 @@ static const FFlogo C[] = {
// ContainerLinux
{
.names = {"ContainerLinux", "Container Linux", "Container Linux by CoreOS"},
- .lines = FASTFETCH_DATATEXT_LOGO_CONTAINER_LINUX,
+ .lines = FASTFETCH_DATATEXT_LOGO_FEDORA_COREOS,
.colors = {
FF_COLOR_FG_BLUE,
FF_COLOR_FG_WHITE,
@@ -1468,6 +1468,68 @@ static const FFlogo F[] = {
.colorKeys = FF_COLOR_FG_BLUE,
.colorTitle = FF_COLOR_FG_BLUE,
},
+ // FedoraSilverblue
+ {
+ .names = {"Fedora_silverblue", "fedora-silverblue", "fedora-linux-silverblue", "fedora-linux_silverblue"},
+ .type = FF_LOGO_LINE_TYPE_ALTER_BIT,
+ .lines = FASTFETCH_DATATEXT_LOGO_FEDORA_SILVERBLUE,
+ .colors = {
+ FF_COLOR_FG_BLUE,
+ FF_COLOR_FG_WHITE,
+ FF_COLOR_FG_CYAN,
+ },
+ .colorKeys = FF_COLOR_FG_BLUE,
+ .colorTitle = FF_COLOR_FG_BLUE,
+ },
+ // FedoraKinoite
+ {
+ .names = {"Fedora_kinoite", "fedora-kinoite", "fedora-linux-kinoite", "fedora-linux_kinoite"},
+ .type = FF_LOGO_LINE_TYPE_ALTER_BIT,
+ .lines = FASTFETCH_DATATEXT_LOGO_FEDORA_KINOITE,
+ .colors = {
+ FF_COLOR_FG_BLUE,
+ FF_COLOR_FG_WHITE,
+ },
+ .colorKeys = FF_COLOR_FG_BLUE,
+ .colorTitle = FF_COLOR_FG_BLUE,
+ },
+ // FedoraSericea
+ {
+ .names = {"Fedora_sericea", "fedora-sericea", "fedora-linux-sericea", "fedora-linux_sericea"},
+ .type = FF_LOGO_LINE_TYPE_ALTER_BIT,
+ .lines = FASTFETCH_DATATEXT_LOGO_FEDORA_SERICEA,
+ .colors = {
+ FF_COLOR_FG_BLUE,
+ FF_COLOR_FG_WHITE,
+ },
+ .colorKeys = FF_COLOR_FG_BLUE,
+ .colorTitle = FF_COLOR_FG_BLUE,
+ },
+ // FedoraOnyx placeholder - Currently does not have a logo
+ //{
+ //.names = {"Fedora_onyx", "fedora-onyx", "fedora-linux-onyx", "fedora-linux_onyx"},
+ //.type = FF_LOGO_LINE_TYPE_ALTER_BIT,
+ //.lines = FASTFETCH_DATATEXT_LOGO_FEDORA_ONYX,
+ //.colors = {
+ //FF_COLOR_FG_BLUE,
+ //FF_COLOR_FG_WHITE,
+ //},
+ //.colorKeys = FF_COLOR_FG_BLUE,
+ //.colorTitle = FF_COLOR_FG_BLUE,
+ //},
+ // FedoraCoreOS
+ {
+ .names = {"Fedora_coreos", "fedora-coreos", "fedora-linux-coreos", "fedora-linux_coreos"},
+ .type = FF_LOGO_LINE_TYPE_ALTER_BIT,
+ .lines = FASTFETCH_DATATEXT_LOGO_FEDORA_COREOS,
+ .colors = {
+ FF_COLOR_FG_BLUE,
+ FF_COLOR_FG_WHITE,
+ FF_COLOR_FG_RED,
+ },
+ .colorKeys = FF_COLOR_FG_BLUE,
+ .colorTitle = FF_COLOR_FG_WHITE,
+ },
// FemboyOS
{
.names = {"FemboyOS"},
diff --git a/src/modules/modules.h b/src/modules/modules.h
index 35d6523c4..78fe2f33b 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -49,6 +49,7 @@
#include "modules/terminal/terminal.h"
#include "modules/terminalfont/terminalfont.h"
#include "modules/terminalsize/terminalsize.h"
+#include "modules/terminaltheme/terminaltheme.h"
#include "modules/theme/theme.h"
#include "modules/title/title.h"
#include "modules/uptime/uptime.h"
diff --git a/src/modules/options.h b/src/modules/options.h
index aa124c24a..54dd7ca15 100644
--- a/src/modules/options.h
+++ b/src/modules/options.h
@@ -49,6 +49,7 @@
#include "modules/terminal/option.h"
#include "modules/terminalfont/option.h"
#include "modules/terminalsize/option.h"
+#include "modules/terminaltheme/option.h"
#include "modules/theme/option.h"
#include "modules/title/option.h"
#include "modules/uptime/option.h"
diff --git a/src/modules/terminaltheme/option.h b/src/modules/terminaltheme/option.h
new file mode 100644
index 000000000..aecbe18d7
--- /dev/null
+++ b/src/modules/terminaltheme/option.h
@@ -0,0 +1,11 @@
+#pragma once
+
+// This file will be included in "fastfetch.h", do NOT put unnecessary things here
+
+#include "common/option.h"
+
+typedef struct FFTerminalThemeOptions
+{
+ FFModuleBaseInfo moduleInfo;
+ FFModuleArgs moduleArgs;
+} FFTerminalThemeOptions;
diff --git a/src/modules/terminaltheme/terminaltheme.c b/src/modules/terminaltheme/terminaltheme.c
new file mode 100644
index 000000000..43e76c65c
--- /dev/null
+++ b/src/modules/terminaltheme/terminaltheme.c
@@ -0,0 +1,134 @@
+#include "common/printing.h"
+#include "common/jsonconfig.h"
+#include "detection/terminaltheme/terminaltheme.h"
+#include "modules/terminaltheme/terminaltheme.h"
+#include "util/stringUtils.h"
+
+#include
+
+#define FF_TERMINALTHEME_DISPLAY_NAME "Terminal Theme"
+#define FF_TERMINALTHEME_NUM_FORMAT_ARGS 4
+
+void ffPrintTerminalTheme(FFTerminalThemeOptions* options)
+{
+ FFTerminalThemeResult result = {};
+
+ if(!ffDetectTerminalTheme(&result))
+ {
+ ffPrintError(FF_TERMINALTHEME_DISPLAY_NAME, 0, &options->moduleArgs, "Failed to detect terminal theme");
+ }
+ else
+ {
+ if(options->moduleArgs.outputFormat.length == 0)
+ {
+ ffPrintLogoAndKey(FF_TERMINALTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
+ printf("#%02" PRIX16 "%02" PRIX16 "%02" PRIX16 " (FG) - #%02" PRIX16 "%02" PRIX16 "%02" PRIX16 " (BG) [%s]\n",
+ result.fg.r, result.fg.g, result.fg.b,
+ result.bg.r, result.bg.g, result.bg.b,
+ result.bg.dark ? "Dark" : "Light");
+ }
+ else
+ {
+ char fg[32], bg[32];
+ snprintf(fg, sizeof(fg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.fg.r, result.fg.g, result.fg.b);
+ snprintf(bg, sizeof(bg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.bg.r, result.bg.g, result.bg.b);
+ ffPrintFormat(FF_TERMINALTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_TERMINALTHEME_NUM_FORMAT_ARGS, (FFformatarg[]){
+ {FF_FORMAT_ARG_TYPE_STRING, fg},
+ {FF_FORMAT_ARG_TYPE_STRING, result.fg.dark ? "Dark" : "Light"},
+ {FF_FORMAT_ARG_TYPE_STRING, bg},
+ {FF_FORMAT_ARG_TYPE_STRING, result.bg.dark ? "Dark" : "Light"},
+ });
+ }
+ }
+}
+
+bool ffParseTerminalThemeCommandOptions(FFTerminalThemeOptions* options, const char* key, const char* value)
+{
+ const char* subKey = ffOptionTestPrefix(key, FF_TERMINALTHEME_MODULE_NAME);
+ if (!subKey) return false;
+ if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
+ return true;
+
+ return false;
+}
+
+void ffParseTerminalThemeJsonObject(FFTerminalThemeOptions* options, yyjson_val* module)
+{
+ yyjson_val *key_, *val;
+ size_t idx, max;
+ yyjson_obj_foreach(module, idx, max, key_, val)
+ {
+ const char* key = yyjson_get_str(key_);
+ if(ffStrEqualsIgnCase(key, "type"))
+ continue;
+
+ if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
+ continue;
+
+ ffPrintError(FF_TERMINALTHEME_DISPLAY_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
+ }
+}
+
+void ffGenerateTerminalThemeJsonConfig(FFTerminalThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
+{
+ __attribute__((__cleanup__(ffDestroyTerminalThemeOptions))) FFTerminalThemeOptions defaultOptions;
+ ffInitTerminalThemeOptions(&defaultOptions);
+
+ ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
+}
+
+void ffGenerateTerminalThemeJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
+{
+ FFTerminalThemeResult result = {};
+
+ if(!ffDetectTerminalTheme(&result))
+ {
+ yyjson_mut_obj_add_str(doc, module, "error", "Failed to detect terminal theme");
+ return;
+ }
+
+ yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
+
+ yyjson_mut_val* fg = yyjson_mut_obj_add_obj(doc, obj, "fg");
+ yyjson_mut_obj_add_uint(doc, fg, "r", result.fg.r);
+ yyjson_mut_obj_add_uint(doc, fg, "g", result.fg.g);
+ yyjson_mut_obj_add_uint(doc, fg, "b", result.fg.b);
+ yyjson_mut_obj_add_bool(doc, fg, "dark", result.fg.dark);
+
+ yyjson_mut_val* bg = yyjson_mut_obj_add_obj(doc, obj, "bg");
+ yyjson_mut_obj_add_uint(doc, bg, "r", result.bg.r);
+ yyjson_mut_obj_add_uint(doc, bg, "g", result.bg.g);
+ yyjson_mut_obj_add_uint(doc, bg, "b", result.bg.b);
+ yyjson_mut_obj_add_bool(doc, bg, "dark", result.bg.dark);
+}
+
+void ffPrintTerminalThemeHelpFormat(void)
+{
+ ffPrintModuleFormatHelp(FF_TERMINALTHEME_MODULE_NAME, "{1} (FG) {3} (BG) [{4}]", FF_TERMINALTHEME_NUM_FORMAT_ARGS, (const char* []) {
+ "Terminal foreground color",
+ "Terminal foreground type (Dark / Light)",
+ "Terminal background color",
+ "Terminal background type (Dark / Light)",
+ });
+}
+
+void ffInitTerminalThemeOptions(FFTerminalThemeOptions* options)
+{
+ ffOptionInitModuleBaseInfo(
+ &options->moduleInfo,
+ FF_TERMINALTHEME_MODULE_NAME,
+ "Print current terminal theme (foreground and background colors)",
+ ffParseTerminalThemeCommandOptions,
+ ffParseTerminalThemeJsonObject,
+ ffPrintTerminalTheme,
+ ffGenerateTerminalThemeJsonResult,
+ ffPrintTerminalThemeHelpFormat,
+ ffGenerateTerminalThemeJsonConfig
+ );
+ ffOptionInitModuleArg(&options->moduleArgs);
+}
+
+void ffDestroyTerminalThemeOptions(FFTerminalThemeOptions* options)
+{
+ ffOptionDestroyModuleArg(&options->moduleArgs);
+}
diff --git a/src/modules/terminaltheme/terminaltheme.h b/src/modules/terminaltheme/terminaltheme.h
new file mode 100644
index 000000000..fb5cbb58a
--- /dev/null
+++ b/src/modules/terminaltheme/terminaltheme.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "fastfetch.h"
+
+#define FF_TERMINALTHEME_MODULE_NAME "TerminalTheme"
+
+void ffPrintTerminalTheme(FFTerminalThemeOptions* options);
+void ffInitTerminalThemeOptions(FFTerminalThemeOptions* options);
+void ffDestroyTerminalThemeOptions(FFTerminalThemeOptions* options);
diff --git a/src/options/modules.c b/src/options/modules.c
index 68b835d82..bc636ff0c 100644
--- a/src/options/modules.c
+++ b/src/options/modules.c
@@ -47,9 +47,10 @@ void ffOptionsInitModules(FFOptionsModules* options)
ffInitShellOptions(&options->shell);
ffInitSoundOptions(&options->sound);
ffInitSwapOptions(&options->swap);
- ffInitTerminalFontOptions(&options->terminalFont);
ffInitTerminalOptions(&options->terminal);
+ ffInitTerminalFontOptions(&options->terminalFont);
ffInitTerminalSizeOptions(&options->terminalSize);
+ ffInitTerminalThemeOptions(&options->terminalTheme);
ffInitThemeOptions(&options->theme);
ffInitTitleOptions(&options->title);
ffInitUptimeOptions(&options->uptime);
@@ -109,9 +110,10 @@ void ffOptionsDestroyModules(FFOptionsModules* options)
ffDestroyShellOptions(&options->shell);
ffDestroySoundOptions(&options->sound);
ffDestroySwapOptions(&options->swap);
- ffDestroyTerminalFontOptions(&options->terminalFont);
ffDestroyTerminalOptions(&options->terminal);
+ ffDestroyTerminalFontOptions(&options->terminalFont);
ffDestroyTerminalSizeOptions(&options->terminalSize);
+ ffDestroyTerminalThemeOptions(&options->terminalTheme);
ffDestroyThemeOptions(&options->theme);
ffDestroyTitleOptions(&options->title);
ffDestroyUptimeOptions(&options->uptime);
diff --git a/src/options/modules.h b/src/options/modules.h
index e9836e140..7a96a0f40 100644
--- a/src/options/modules.h
+++ b/src/options/modules.h
@@ -48,9 +48,10 @@ typedef struct FFOptionsModules
FFShellOptions shell;
FFSoundOptions sound;
FFSwapOptions swap;
- FFTerminalFontOptions terminalFont;
FFTerminalOptions terminal;
+ FFTerminalFontOptions terminalFont;
FFTerminalSizeOptions terminalSize;
+ FFTerminalThemeOptions terminalTheme;
FFThemeOptions theme;
FFTitleOptions title;
FFUptimeOptions uptime;
diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c
index f224c84eb..a233c3bc4 100644
--- a/src/util/platform/FFPlatform_unix.c
+++ b/src/util/platform/FFPlatform_unix.c
@@ -29,8 +29,10 @@ static void getExePath(FFPlatform* platform)
(int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, (int) getpid()}, 4,
exePath->chars, &exePathLen,
NULL, 0
- ))
+ ) < 0)
exePathLen = 0;
+ else
+ exePathLen--; // remove terminating NUL
#endif
if (exePathLen > 0)
exePath->length = (uint32_t) exePathLen;