Compare commits

..

33 Commits

Author SHA1 Message Date
Carter Li ea162fd452 Merge pull request #734 from fastfetch-cli/dev
Release: v2.8.4
2024-02-23 16:09:51 +08:00
李通洲 b80391b183 Release: v2.8.4 2024-02-23 15:56:12 +08:00
李通洲 4c7a9e4394 Doc: update changelog 2024-02-23 10:01:05 +08:00
李通洲 4b747f70a4 Disk (Linux): ensure only physical devices are detected
Ref: https://github.com/fastfetch-cli/fastfetch/issues/731#issuecomment-1955814211
2024-02-23 09:29:39 +08:00
李通洲 5fb4b6dc04 Display: --display-compact-type support *-with-refresh-rate
Ref: https://github.com/fastfetch-cli/fastfetch/discussions/732
2024-02-22 18:45:57 +08:00
李通洲 5e7cfe2976 Display: add option --display-order 2024-02-22 10:47:13 +08:00
李通洲 77db2d84a3 FFstrbuf: remove ffStrbufCompAlphabetically 2024-02-22 10:38:33 +08:00
李通洲 15bb5bfb24 Packages: add ability to disable specified package manager
Fix #729
2024-02-22 10:03:38 +08:00
李通洲 4e9ee9aa03 Package: code cleanup 2024-02-21 15:40:04 +08:00
李通洲 6a0c7ca788 Disk (Linux): try fixing multidevice bcachefs filesystem compatibility
Ref: #731
2024-02-21 09:05:26 +08:00
李通洲 90e99bcf69 Doc: fix invalid commands 2024-02-21 09:05:26 +08:00
Lenny0939 5b20a86d53 Fix mistake in README.md (#730)
Sudo is not necessary to use nix-shell, and puts you in a shell as root which is not ideal
2024-02-20 18:42:59 -06:00
李通洲 6ad1262f4a NetIO: add option --netio-detect-total 2024-02-20 14:44:55 +08:00
李通洲 e0297e1dd1 DiskIO: add option --diskio-detect-total 2024-02-20 14:43:50 +08:00
李通洲 937611aa29 Colors: support JSON config generation 2024-02-15 22:05:34 +08:00
李通洲 eda38e16db Colors: don't print extra empty lines 2024-02-15 21:55:33 +08:00
李通洲 2731756c39 Platform (Windows): small optimization 2024-02-15 20:29:57 +08:00
李通洲 853ca0f608 Platform (Windows): don't assume x86 as i686 2024-02-15 20:29:34 +08:00
李通洲 17f4a6e055 Colors: support block related settings
Fix #721
2024-02-14 22:09:12 +08:00
李通洲 925dc6f681 TerminalFont (Windows): support portable Windows Terminal settings
Fix #720
2024-02-13 19:49:49 +08:00
李通洲 706527eab4 Github: update ISSUE_TEMPLATE 2024-02-13 19:19:29 +08:00
李通洲 3a96ade423 CPU (Linux): don't segfault if we fail to find Vendor ID in lscpu
Fix #718
2024-02-13 19:08:44 +08:00
李通洲 da9c928286 CMake: make artifact file names consistant
Fix #719
2024-02-13 19:02:03 +08:00
Carter Li 30d3d00900 Merge pull request #717 from fastfetch-cli/dev
Release v2.8.3
2024-02-12 10:59:30 +08:00
李通洲 99fce80d0d CI: fix windows artifacts generation 2024-02-12 10:46:57 +08:00
Herby Gillot a5a28e30a0 README: add MacPorts install info (#716)
Add info on installing `fastfetch` on macOS via MacPorts: https://ports.macports.org/port/fastfetch/
2024-02-12 10:43:23 +08:00
李通洲 7fe39353df Release: v2.8.3 2024-02-12 10:28:29 +08:00
李通洲 a3576b3154 CI: release file name without version
Fix #714
2024-02-12 10:28:29 +08:00
AlbydS c5d0d84001 Add installation instructions for even more Linux distributions (#715)
Added Alpine (now with the right command), ALT Linux and Arch AUR to the installation instructions.
2024-02-12 10:20:10 +08:00
李通洲 467ed54a3b GPU (Linux): lazy load pci.ids 2024-02-12 10:12:34 +08:00
Carter 7ea8882843 GPU (FreeBSD): detect correct AMD card names 2024-02-12 18:09:11 +08:00
李通洲 f4cb3bb33f GPU (Linux): use amdgpu.ids 2024-02-12 00:43:06 +08:00
李通洲 330eb9fa21 GPU: show sub-device if available
Try fixing #713
2024-02-11 23:01:14 +08:00
36 changed files with 895 additions and 252 deletions
+1 -3
View File
@@ -46,9 +46,7 @@ Output of `fastfetch --list-features`:
Paste the stacktrace here. You may get it with:
```
$ gdb /path/to/fastfetch
$ run
$ bt
$ gdb -q -ex 'set confirm off' -ex run -ex 'bt full' -ex quit --args /path/to/fastfetch
```
If you are able to identify which module crashed, the strace can be helpful too
+7 -6
View File
@@ -371,16 +371,16 @@ jobs:
run: ctest
- name: create zip archive
run: 7z a -tzip -mx9 -bd -y fastfetch-$(./fastfetch --version-raw)-windows-amd64.zip *.dll fastfetch.exe flashfetch.exe presets
run: 7z a -tzip -mx9 -bd -y fastfetch-windows-amd64.zip *.dll fastfetch.exe flashfetch.exe presets
- name: create 7z archive
run: 7z a -t7z -mx9 -bd -y fastfetch-$(./fastfetch --version-raw)-windows-amd64.7z *.dll fastfetch.exe flashfetch.exe presets
run: 7z a -t7z -mx9 -bd -y fastfetch-windows-amd64.7z *.dll fastfetch.exe flashfetch.exe presets
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: fastfetch-windows-amd64
path: ./fastfetch-*-windows-amd64.*
path: ./fastfetch-windows-amd64.*
windows-i686:
name: Windows-i686
@@ -438,16 +438,16 @@ jobs:
run: ctest
- name: create zip archive
run: 7z a -tzip -mx9 -bd -y fastfetch-$(./fastfetch --version-raw)-windows-i686.zip *.dll fastfetch.exe flashfetch.exe presets
run: 7z a -tzip -mx9 -bd -y fastfetch-windows-i686.zip *.dll fastfetch.exe flashfetch.exe presets
- name: create 7z archive
run: 7z a -t7z -mx9 -bd -y fastfetch-$(./fastfetch --version-raw)-windows-i686.7z *.dll fastfetch.exe flashfetch.exe presets
run: 7z a -t7z -mx9 -bd -y fastfetch-windows-i686.7z *.dll fastfetch.exe flashfetch.exe presets
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: fastfetch-windows-i686
path: ./fastfetch-*-windows-i686.*
path: ./fastfetch-windows-i686.*
release:
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'fastfetch-cli/fastfetch'
@@ -474,6 +474,7 @@ jobs:
uses: actions/download-artifact@v4
- name: rm old artifacts
if: needs.linux-amd64.outputs.ffversion != steps.get_version_release.outputs.release
run: |
rm -rf fastfetch-*-old-*
+20
View File
@@ -1,3 +1,23 @@
# 2.8.4
Bugfixes:
* Fix segfault if we fail to find `Vendor ID` in `lscpu` (#718, CPU, Linux)
* Fix multi-device bcachefs filesystem compatibility (#731, Disk, Linux)
Features:
* Support portable Windows Terminal settings (#720, Terminal, Windows)
* Support `--color-block-width` and `--color-block-range` (#721, Colors)
* Support `--diskio-detect-total` to show total bytes read/written (DiskIO)
* Support `--netio-detect-total` to show total bytes received/sent (NetIO)
* Support `--packages-disabled` to disable specified package manager (#729, Packages)
* Support `--display-order` to sort multiple displays in a specific order (Display)
* Support `--display-compact-type original-with-refresh-rate` to show refresh rates in compact (oneline) mode (Display)
# 2.8.3
Bugfixes:
* Fix GPU name detection for AMD graphic cards (GPU, Linux / FreeBSD)
# 2.8.2
Changes:
+8 -3
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url
project(fastfetch
VERSION 2.8.2
VERSION 2.8.4
LANGUAGES C
DESCRIPTION "Fast neofetch-like system information tool"
HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
@@ -401,6 +401,7 @@ if(LINUX)
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_linux.c
src/detection/gpu/gpu_pci.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_linux.c
src/detection/icons/icons_linux.c
@@ -518,6 +519,7 @@ elseif(BSD)
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_bsd.c
src/detection/gpu/gpu_pci.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_bsd.c
src/detection/lm/lm_linux.c
@@ -1108,9 +1110,12 @@ install(
set(CPACK_GENERATOR "TGZ;ZIP")
if(APPLE)
string(TOLOWER "${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-macos-universal" CPACK_PACKAGE_FILE_NAME)
string(TOLOWER "${CMAKE_PROJECT_NAME}-macos-universal" CPACK_PACKAGE_FILE_NAME)
else() # We don't use this in Windows
string(TOLOWER "${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" CPACK_PACKAGE_FILE_NAME)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(CMAKE_SYSTEM_PROCESSOR "amd64")
endif()
string(TOLOWER "${CMAKE_PROJECT_NAME}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" CPACK_PACKAGE_FILE_NAME)
endif()
if(LINUX)
+10 -2
View File
@@ -28,11 +28,13 @@ There are [screenshots on different platforms](https://github.com/fastfetch-cli/
### Linux
* Debian / Ubuntu: Download `fastfetch-<version>-Linux.deb` from [Github release page](https://github.com/fastfetch-cli/fastfetch/releases/latest) and `dpkg -i fastfetch-<version>-Linux.deb`
* Arch Linux: `sudo pacman -S fastfetch`
* Arch Linux: `sudo pacman -S fastfetch`. You can also find fastfetch [on the AUR](https://aur.archlinux.org/packages/fastfetch-git).
* Fedora: `sudo dnf install fastfetch`
* Gentoo: `sudo emerge --ask app-misc/fastfetch`
* NixOS: `sudo nix-shell -p fastfetch`
* Alpine: `apk add --upgrade fastfetch`
* NixOS: `nix-shell -p fastfetch`
* openSUSE: `sudo zypper install fastfetch`
* ALT Linux: `sudo apt-get install fastfetch`
Replace sudo with doas depending on what you use.
@@ -40,8 +42,14 @@ Replace sudo with doas depending on what you use.
### macOS
...via [HomeBrew](https://brew.sh):
`brew install fastfetch`
...via [MacPorts](https://www.macports.org):
`sudo port install fastfetch`
### Windows
`scoop install fastfetch`
+49 -5
View File
@@ -1007,6 +1007,29 @@
"type": "integer",
"minimum": 0,
"default": 0
},
"block": {
"description": "Set behavior of block printing",
"type": "object",
"properties": {
"width": {
"description": "Set the block width in spaces",
"type": "integer",
"minimum": 1,
"default": 3
},
"range": {
"description": "Set the range of colors in the blocks to print",
"type": "array",
"items": {
"type": "integer",
"minimum": 0,
"maximum": 15
},
"minItems": 2,
"maxItems": 2
}
}
}
}
},
@@ -1078,7 +1101,9 @@
"enum": [
"none",
"original",
"scaled"
"scaled",
"original-with-refresh-rate",
"scaled-with-refresh-rate"
],
"description": "Set if all displays should be printed in one line",
"default": "none"
@@ -1088,6 +1113,15 @@
"type": "boolean",
"default": false
},
"order": {
"description": "Set the order should be used when printing",
"enum": [
"none",
"asc",
"desc"
],
"default": "none"
},
"key": {
"$ref": "#/$defs/key"
},
@@ -1173,6 +1207,11 @@
"description": "Show disks with given name prefix only",
"type": "string"
},
"detectTotal": {
"description": "Detect total bytes instead of current rate",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
@@ -1382,6 +1421,11 @@
"type": "boolean",
"default": true
},
"detectTotal": {
"description": "Detect total bytes instead of current rate",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
@@ -1436,10 +1480,10 @@
"const": "packages",
"description": "List installed package managers and count of installed packages"
},
"winget": {
"description": "Set if winget package count should be detected.\nNote this is very slow operation. Please make sure `winget list` works before enable this option\nWindows only",
"type": "boolean",
"default": false
"disabled": {
"description": "A colon separated list of package managers to be disabled when detecting",
"type": "string",
"default": "winget"
},
"key": {
"$ref": "#/$defs/key"
+102 -12
View File
@@ -122,7 +122,10 @@
{
"long": "ds-force-drm",
"desc": "Set if only DRM should be used to detect displays",
"remark": "Use this option if you encountered problems with other detection method. Linux only",
"remark": [
"Use this option if you encountered problems with other detection method.",
"Linux only"
],
"arg": {
"type": "enum",
"optional": true,
@@ -537,7 +540,13 @@
{
"long": "percent-type",
"desc": "Set the percentage output type",
"remark": "1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number",
"remark": [
"1 for percentage number",
"2 for bar",
"3 for both",
"6 for bar only",
"9 for colored number"
],
"arg": {
"type": "num",
"default": 9
@@ -963,6 +972,14 @@
"default": false
}
},
{
"long": "diskio-detect-total",
"desc": "Detect total bytes instead of current rate",
"arg": {
"type": "bool",
"default": false
}
},
{
"long": "diskio-name-prefix",
"desc": "Show disks with given name prefix only",
@@ -996,13 +1013,16 @@
}
},
{
"long": "packages-winget",
"desc": "Set if winget package count should be detected",
"remark": "This option is extremely slow. You may need to increase value of '--processing-timeout' to make it actually work",
"long": "packages-disabled",
"desc": "A colon separated list of package managers to be disabled when detecting",
"remark": [
"Some detection methods can be very slow.",
"You may need to increase value of '--processing-timeout' to make it actually work.",
"Use `--packages-disabled none` to enable all."
],
"arg": {
"type": "bool",
"optional": true,
"default": false
"type": "string",
"default": "winget"
}
},
{
@@ -1013,7 +1033,9 @@
"enum": {
"none": "Disable this compact mode",
"original": "Print original resolutions",
"scaled": "Print scaled resolutions"
"scaled": "Print scaled resolutions",
"original-with-refresh-rate": "Print original resolutions with refresh rate",
"scaled-with-refresh-rate": "Print scaled resolutions with refresh rate"
},
"default": "none"
}
@@ -1027,6 +1049,19 @@
"default": false
}
},
{
"long": "display-order",
"desc": "Set the order should be used when printing displays",
"arg": {
"type": "enum",
"enum": {
"none": "Use the detected order",
"asc": "Sort by display name ascendingly",
"desc": "Sort by display name descendingly"
},
"default": "none"
}
},
{
"long": "brightness-ddcci-sleep",
"desc": "Set the sleep times (in ms) when sending DDC/CI requests",
@@ -1052,7 +1087,10 @@
{
"long": "battery-use-setup-api",
"desc": "Set if \"SetupAPI\" should be used on Windows to detect battery info",
"remark": "SetupAPI supports multi batteries, but slower. Windows only",
"remark": [
"SetupAPI supports multi batteries, but slower.",
"Windows only"
],
"arg": {
"type": "bool",
"optional": true,
@@ -1088,7 +1126,10 @@
{
"long": "de-slow-version-detection",
"desc": "Set if DE version should be detected with slow operations",
"remark": "Usually is not necessary. Linux only",
"remark": [
"It's only used as a fallback method. Please file a bug report if you encounter any issues.",
"Linux only"
],
"arg": {
"type": "bool",
"optional": true,
@@ -1107,7 +1148,10 @@
{
"long": "gpu-driver-specific",
"desc": "Use driver specific method to detect more detailed GPU information (memory usage, core count, etc)",
"remark": "Correctly NVML (NVIDIA) and IGCL (Intel, Windows only) are supported. Both require the latest proprietary driver to be installed",
"remark": [
"Correctly NVML (NVIDIA) and IGCL (Intel, Windows only) are supported.",
"Both require the latest proprietary driver to be installed."
],
"arg": {
"type": "bool",
"optional": true,
@@ -1225,6 +1269,14 @@
"default": true
}
},
{
"long": "netio-detect-total",
"desc": "Detect total bytes instead of current rate",
"arg": {
"type": "bool",
"default": false
}
},
{
"long": "publicip-timeout",
"desc": "Time in milliseconds to wait for the public ip server to respond",
@@ -1342,6 +1394,44 @@
"type": "num",
"default": 0
}
},
{
"long": "colors-block-width",
"desc": "Set the block width in spaces",
"arg": {
"type": "num",
"default": 3
}
},
{
"long": "colors-block-range-start",
"desc": "Set the start range of colors in the blocks to print",
"remark": [
"Display colors 0-15 in the blocks. (16 colors)",
"Display colors 0-7 in the blocks. (8 colors)",
"Only works for `--colors-symbol block`.",
"Must be in range 0-15",
"See also `--colors-range-end`"
],
"arg": {
"type": "num",
"default": 0
}
},
{
"long": "colors-block-range-end",
"desc": "Set the end range of colors in the blocks to print",
"remark": [
"Display colors 0-15 in the blocks. (16 colors)",
"Display colors 0-7 in the blocks. (8 colors)",
"Only works for `--colors-symbol block`.",
"Must be in range 0-15",
"See also `--colors-range-start`"
],
"arg": {
"type": "num",
"default": 15
}
}
],
"General module": [
+4
View File
@@ -266,6 +266,10 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
return NULL;
}
}
else
{
pstart = buffer.chars;
}
}
while ((pstart = strstr(pstart, "Model name:")))
+3 -3
View File
@@ -2,9 +2,9 @@
const char* ffDetectDisksImpl(FFlist* disks);
static int compareDisks(const void* disk1, const void* disk2)
static int compareDisks(const FFDisk* disk1, const FFDisk* disk2)
{
return ffStrbufCompAlphabetically(&((const FFDisk*) disk1)->mountpoint, &((const FFDisk*) disk2)->mountpoint);
return ffStrbufComp(&disk1->mountpoint, &disk2->mountpoint);
}
const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks)
@@ -18,7 +18,7 @@ const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks)
// For example for /boot/efi/bootmgr we need to check /boot/efi before /boot
//Note that we sort alphabetically here for a better ordering when printing the list,
// so the check must be done in reverse order
ffListSort(disks, compareDisks);
ffListSort(disks, (void*) compareDisks);
FF_LIST_FOR_EACH(FFDisk, disk, *disks)
{
if(disk->bytesTotal == 0)
+4
View File
@@ -41,6 +41,10 @@ static bool isPhysicalDevice(const struct mntent* device)
if(!ffStrStartsWith(device->mnt_fsname, "/dev/"))
return false;
//#731
if(ffStrEquals(device->mnt_type, "bcachefs"))
return true;
if(
ffStrStartsWith(device->mnt_fsname + 5, "loop") || //Ignore loop devices
ffStrStartsWith(device->mnt_fsname + 5, "ram") || //Ignore ram devices
+11
View File
@@ -9,6 +9,8 @@ static uint64_t time1;
void ffPrepareDiskIO(FFDiskIOOptions* options)
{
if (options->detectTotal) return;
ffListInit(&ioCounters1, sizeof(FFDiskIOResult));
ffDiskIOGetIoCounters(&ioCounters1, options);
time1 = ffTimeGetNow();
@@ -17,6 +19,15 @@ void ffPrepareDiskIO(FFDiskIOOptions* options)
const char* ffDetectDiskIO(FFlist* result, FFDiskIOOptions* options)
{
const char* error = NULL;
if (options->detectTotal)
{
error = ffDiskIOGetIoCounters(result, options);
if (error)
return error;
return NULL;
}
if (time1 == 0)
{
ffListInit(&ioCounters1, sizeof(FFDiskIOResult));
-72
View File
@@ -118,75 +118,3 @@ const char* ffDetectGPU(const FFGPUOptions* options, FFlist* result)
return "GPU detection failed";
}
#ifndef _WIN32
void ffGPUParsePciIds(FFstrbuf* content, uint8_t subclass, uint16_t vendor, uint16_t device, FFGPUResult* gpu)
{
if (content->length)
{
char buffer[32];
uint32_t len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n%04x ", vendor);
char* start = (char*) memmem(content->chars, content->length, buffer, len);
char* end = content->chars + content->length;
if (start)
{
start += len;
end = memchr(start, '\n', (uint32_t) (end - start));
if (!end)
end = content->chars + content->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 = content->chars + content->length;
break;
}
else
end++;
}
len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n\t%04x ", 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 = content->chars + content->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* subclassStr;
switch (subclass)
{
case 0 /*PCI_CLASS_DISPLAY_VGA*/: subclassStr = " (VGA compatible)"; break;
case 1 /*PCI_CLASS_DISPLAY_XGA*/: subclassStr = " (XGA compatible)"; break;
case 2 /*PCI_CLASS_DISPLAY_3D*/: subclassStr = " (3D)"; break;
default: subclassStr = ""; break;
}
ffStrbufSetF(&gpu->name, "%s Device %04X%s", gpu->vendor.length ? gpu->vendor.chars : "Unknown", device, subclassStr);
}
}
#endif
+2 -2
View File
@@ -43,6 +43,6 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus);
const char* ffGetGPUVendorString(unsigned vendorId);
#ifndef _WIN32
void ffGPUParsePciIds(FFstrbuf* content, uint8_t subclass, uint16_t vendor, uint16_t device, FFGPUResult* gpu);
#if defined(__linux__) || defined(__FreeBSD__)
void ffGPUParsePciIds(FFstrbuf* content, uint8_t subclass, uint16_t vendor, uint16_t device, uint16_t subVendor, uint16_t subDevice, FFGPUResult* gpu);
#endif
+14 -3
View File
@@ -1,9 +1,9 @@
#include "gpu_driver_specific.h"
#include "common/io/io.h"
#include "common/properties.h"
#include "3rdparty/nvml/nvml.h"
#include "util/mallocHelper.h"
#include "common/io/io.h"
#include <dev/pci/pcireg.h>
#include <sys/pciio.h>
@@ -46,7 +46,6 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
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)
{
@@ -64,7 +63,19 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
gpu->deviceId = ((uint64_t) pc->pc_sel.pc_domain << 6) | ((uint64_t) pc->pc_sel.pc_bus << 4) | ((uint64_t) pc->pc_sel.pc_dev << 2) | pc->pc_sel.pc_func;
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
ffGPUParsePciIds(&pciids, pc->pc_subclass, pc->pc_vendor, pc->pc_device, gpu);
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
{
char query[32];
snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) pc->pc_device, (unsigned) pc->pc_revid);
ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name);
}
if (gpu->name.length == 0)
{
if (pciids.length == 0)
loadPciIds(&pciids);
ffGPUParsePciIds(&pciids, pc->pc_subclass, pc->pc_vendor, pc->pc_device, pc->pc_subvendor, pc->pc_subdevice, gpu);
}
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->driverSpecific))
+26 -4
View File
@@ -2,6 +2,7 @@
#include "detection/vulkan/vulkan.h"
#include "detection/temps/temps_linux.h"
#include "common/io/io.h"
#include "common/properties.h"
#include "util/stringUtils.h"
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
@@ -80,7 +81,6 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus)
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
FF_STRBUF_AUTO_DESTROY pciids = ffStrbufCreate();
loadPciIds(&pciids);
struct dirent* entry;
while((entry = readdir(dirp)) != NULL)
@@ -98,9 +98,9 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus)
continue;
ffStrbufSubstrBefore(&pciDir, pciDevDirLength);
uint32_t vendorId, deviceId;
uint32_t vendorId, deviceId, subVendorId, subDeviceId;
uint8_t classId, subclassId;
if (sscanf(buffer.chars, "pci:v%8" SCNx32 "d%8" SCNx32 "sv%*8ssd%*8sbc%2" SCNx8 "sc%2" SCNx8, &vendorId, &deviceId, &classId, &subclassId) != 4)
if (sscanf(buffer.chars, "pci:v%8" SCNx32 "d%8" SCNx32 "sv%8" SCNx32 "sd%8" SCNx32 "bc%2" SCNx8 "sc%2" SCNx8, &vendorId, &deviceId, &subVendorId, &subDeviceId, &classId, &subclassId) != 6)
continue;
if (classId != 0x03 /*PCI_BASE_CLASS_DISPLAY*/)
@@ -122,7 +122,29 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus)
gpu->deviceId = ((uint64_t) pciDomain << 6) | ((uint64_t) pciBus << 4) | (deviceId << 2) | pciFunc;
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
ffGPUParsePciIds(&pciids, subclassId, (uint16_t) vendorId, (uint16_t) deviceId, gpu);
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
{
ffStrbufAppendS(&pciDir, "/revision");
if (ffReadFileBuffer(pciDir.chars, &buffer))
{
char* pend;
uint64_t revision = strtoul(buffer.chars, &pend, 16);
if (pend != buffer.chars)
{
char query[32];
snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) deviceId, (unsigned) revision);
ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name);
}
}
ffStrbufSubstrBefore(&pciDir, pciDevDirLength);
}
if (gpu->name.length == 0)
{
if (!pciids.length)
loadPciIds(&pciids);
ffGPUParsePciIds(&pciids, subclassId, (uint16_t) vendorId, (uint16_t) deviceId, (uint16_t) subVendorId, (uint16_t) subDeviceId, gpu);
}
pciDetectDriver(gpu, &pciDir, &buffer);
ffStrbufSubstrBefore(&pciDir, pciDevDirLength);
+81
View File
@@ -0,0 +1,81 @@
#include "gpu.h"
void ffGPUParsePciIds(FFstrbuf* content, uint8_t subclass, uint16_t vendor, uint16_t device, uint16_t subVendor, uint16_t subDevice, FFGPUResult* gpu)
{
if (content->length)
{
char buffer[32];
// Search for vendor
uint32_t len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n%04x ", vendor);
char* start = (char*) memmem(content->chars, content->length, buffer, len);
char* end = content->chars + content->length;
if (start)
{
start += len;
end = memchr(start, '\n', (uint32_t) (end - start));
if (!end)
end = content->chars + content->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 = content->chars + content->length;
break;
}
else
end++;
}
// Search for device
len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n\t%04x ", device);
start = memmem(start, (size_t) (end - start), buffer, len);
if (start)
{
start += len;
// Search for subvendor and subdevice
len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n\t\t%04x %04x ", subVendor, subDevice);
char* subStart = memmem(start, (size_t) (end - start), buffer, len);
if (subStart)
start = subStart + len;
end = memchr(start, '\n', (uint32_t) (end - start));
if (!end)
end = content->chars + content->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* subclassStr;
switch (subclass)
{
case 0 /*PCI_CLASS_DISPLAY_VGA*/: subclassStr = " (VGA compatible)"; break;
case 1 /*PCI_CLASS_DISPLAY_XGA*/: subclassStr = " (XGA compatible)"; break;
case 2 /*PCI_CLASS_DISPLAY_3D*/: subclassStr = " (3D)"; break;
default: subclassStr = ""; break;
}
ffStrbufSetF(&gpu->name, "%s Device %04X%s", gpu->vendor.length ? gpu->vendor.chars : "Unknown", device, subclassStr);
}
}
+11
View File
@@ -9,6 +9,8 @@ static uint64_t time1;
void ffPrepareNetIO(FFNetIOOptions* options)
{
if (options->detectTotal) return;
ffListInit(&ioCounters1, sizeof(FFNetIOResult));
ffNetIOGetIoCounters(&ioCounters1, options);
time1 = ffTimeGetNow();
@@ -17,6 +19,15 @@ void ffPrepareNetIO(FFNetIOOptions* options)
const char* ffDetectNetIO(FFlist* result, FFNetIOOptions* options)
{
const char* error = NULL;
if (options->detectTotal)
{
error = ffNetIOGetIoCounters(result, options);
if (error)
return error;
return NULL;
}
if (time1 == 0)
{
ffListInit(&ioCounters1, sizeof(FFNetIOResult));
+11 -9
View File
@@ -99,14 +99,16 @@ static uint32_t getNixPackages(FFstrbuf* baseDir, const char* dirname)
return num_elements;
}
void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options)
void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options)
{
getBrewPackages(result);
result->macports = getMacPortsPackages();
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateS(FASTFETCH_TARGET_DIR_ROOT);
result->nixDefault += getNixPackages(&baseDir, "/nix/var/nix/profiles/default");
result->nixSystem += getNixPackages(&baseDir, "/run/current-system");
ffStrbufSet(&baseDir, &instance.state.platform.homeDir);
result->nixUser = getNixPackages(&baseDir, "/.nix-profile");
if (!(options->disabled & FF_PACKAGES_FLAG_BREW_BIT)) getBrewPackages(result);
if (!(options->disabled & FF_PACKAGES_FLAG_MACPORTS_BIT)) result->macports = getMacPortsPackages();
if (!(options->disabled & FF_PACKAGES_FLAG_NIX_BIT))
{
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateS(FASTFETCH_TARGET_DIR_ROOT);
result->nixDefault += getNixPackages(&baseDir, "/nix/var/nix/profiles/default");
result->nixSystem += getNixPackages(&baseDir, "/run/current-system");
ffStrbufSet(&baseDir, &instance.state.platform.homeDir);
result->nixUser = getNixPackages(&baseDir, "/.nix-profile");
}
}
+2 -1
View File
@@ -4,5 +4,6 @@
void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options)
{
result->pkg = (uint32_t) ffSettingsGetSQLite3Int(FASTFETCH_TARGET_DIR_ROOT "/var/db/pkg/local.sqlite", "SELECT count(*) FROM packages");
if (!(options->disabled & FF_PACKAGES_FLAG_PKG_BIT))
result->pkg = (uint32_t) ffSettingsGetSQLite3Int(FASTFETCH_TARGET_DIR_ROOT "/var/db/pkg/local.sqlite", "SELECT count(*) FROM packages");
}
+44 -34
View File
@@ -253,44 +253,53 @@ static uint32_t getRpmFromLibrpm(void)
#endif //FF_HAVE_RPM
static void getPackageCounts(FFstrbuf* baseDir, FFPackagesResult* packageCounts)
static void getPackageCounts(FFstrbuf* baseDir, FFPackagesResult* packageCounts, FFPackagesOptions* options)
{
packageCounts->apk += getNumStrings(baseDir, "/lib/apk/db/installed", "C:Q");
packageCounts->dpkg += getNumStrings(baseDir, "/var/lib/dpkg/status", "Status: install ok installed");
packageCounts->emerge += countFilesRecursive(baseDir, "/var/db/pkg", "SIZE");
packageCounts->eopkg += getNumElements(baseDir, "/var/lib/eopkg/package", DT_DIR);
packageCounts->flatpakSystem += getFlatpak(baseDir, "/var/lib/flatpak");
packageCounts->nixDefault += getNixPackages(baseDir, "/nix/var/nix/profiles/default");
packageCounts->nixSystem += getNixPackages(baseDir, "/run/current-system");
packageCounts->pacman += getNumElements(baseDir, "/var/lib/pacman/local", DT_DIR);
packageCounts->pkgtool += getNumElements(baseDir, "/var/log/packages", DT_REG);
packageCounts->rpm += getSQLite3Int(baseDir, "/var/lib/rpm/rpmdb.sqlite", "SELECT count(*) FROM Packages");
packageCounts->snap += getSnap(baseDir);
packageCounts->xbps += getXBPS(baseDir, "/var/db/xbps");
packageCounts->brewCask += getNumElements(baseDir, "/home/linuxbrew/.linuxbrew/Caskroom", DT_DIR);
packageCounts->brew += getNumElements(baseDir, "/home/linuxbrew/.linuxbrew/Cellar", DT_DIR);
packageCounts->paludis += countFilesRecursive(baseDir, "/var/db/paludis/repositories", "environment.bz2");
packageCounts->opkg += getNumStrings(baseDir, "/usr/lib/opkg/status", "Package:"); // openwrt
if (!(options->disabled & FF_PACKAGES_FLAG_APK_BIT)) packageCounts->apk += getNumStrings(baseDir, "/lib/apk/db/installed", "C:Q");
if (!(options->disabled & FF_PACKAGES_FLAG_DPKG_BIT)) packageCounts->dpkg += getNumStrings(baseDir, "/var/lib/dpkg/status", "Status: install ok installed");
if (!(options->disabled & FF_PACKAGES_FLAG_EMERGE_BIT)) packageCounts->emerge += countFilesRecursive(baseDir, "/var/db/pkg", "SIZE");
if (!(options->disabled & FF_PACKAGES_FLAG_EOPKG_BIT)) packageCounts->eopkg += getNumElements(baseDir, "/var/lib/eopkg/package", DT_DIR);
if (!(options->disabled & FF_PACKAGES_FLAG_FLATPAK_BIT)) packageCounts->flatpakSystem += getFlatpak(baseDir, "/var/lib/flatpak");
if (!(options->disabled & FF_PACKAGES_FLAG_NIX_BIT))
{
packageCounts->nixDefault += getNixPackages(baseDir, "/nix/var/nix/profiles/default");
packageCounts->nixSystem += getNixPackages(baseDir, "/run/current-system");
}
if (!(options->disabled & FF_PACKAGES_FLAG_PACMAN_BIT)) packageCounts->pacman += getNumElements(baseDir, "/var/lib/pacman/local", DT_DIR);
if (!(options->disabled & FF_PACKAGES_FLAG_PKGTOOL_BIT)) packageCounts->pkgtool += getNumElements(baseDir, "/var/log/packages", DT_REG);
if (!(options->disabled & FF_PACKAGES_FLAG_RPM_BIT)) packageCounts->rpm += getSQLite3Int(baseDir, "/var/lib/rpm/rpmdb.sqlite", "SELECT count(*) FROM Packages");
if (!(options->disabled & FF_PACKAGES_FLAG_SNAP_BIT)) packageCounts->snap += getSnap(baseDir);
if (!(options->disabled & FF_PACKAGES_FLAG_XBPS_BIT)) packageCounts->xbps += getXBPS(baseDir, "/var/db/xbps");
if (!(options->disabled & FF_PACKAGES_FLAG_BREW_BIT))
{
packageCounts->brewCask += getNumElements(baseDir, "/home/linuxbrew/.linuxbrew/Caskroom", DT_DIR);
packageCounts->brew += getNumElements(baseDir, "/home/linuxbrew/.linuxbrew/Cellar", DT_DIR);
}
if (!(options->disabled & FF_PACKAGES_FLAG_PALUDIS_BIT)) packageCounts->paludis += countFilesRecursive(baseDir, "/var/db/paludis/repositories", "environment.bz2");
if (!(options->disabled & FF_PACKAGES_FLAG_OPKG_BIT)) packageCounts->opkg += getNumStrings(baseDir, "/usr/lib/opkg/status", "Package:"); // openwrt
}
static void getPackageCountsRegular(FFstrbuf* baseDir, FFPackagesResult* packageCounts)
static void getPackageCountsRegular(FFstrbuf* baseDir, FFPackagesResult* packageCounts, FFPackagesOptions* options)
{
getPackageCounts(baseDir, packageCounts);
getPackageCounts(baseDir, packageCounts, options);
uint32_t baseDirLength = baseDir->length;
ffStrbufAppendS(baseDir, FASTFETCH_TARGET_DIR_ETC "/pacman-mirrors.conf");
if(ffParsePropFile(baseDir->chars, "Branch =", &packageCounts->pacmanBranch) && packageCounts->pacmanBranch.length == 0)
ffStrbufAppendS(&packageCounts->pacmanBranch, "stable");
ffStrbufSubstrBefore(baseDir, baseDirLength);
if (!(options->disabled & FF_PACKAGES_FLAG_PACMAN_BIT))
{
uint32_t baseDirLength = baseDir->length;
ffStrbufAppendS(baseDir, FASTFETCH_TARGET_DIR_ETC "/pacman-mirrors.conf");
if(ffParsePropFile(baseDir->chars, "Branch =", &packageCounts->pacmanBranch) && packageCounts->pacmanBranch.length == 0)
ffStrbufAppendS(&packageCounts->pacmanBranch, "stable");
ffStrbufSubstrBefore(baseDir, baseDirLength);
}
}
static void getPackageCountsBedrock(FFstrbuf* baseDir, FFPackagesResult* packageCounts)
static void getPackageCountsBedrock(FFstrbuf* baseDir, FFPackagesResult* packageCounts, FFPackagesOptions* options)
{
uint32_t baseDirLength = baseDir->length;
ffStrbufAppendS(baseDir, "/bedrock/strata");
DIR* dir = opendir(baseDir->chars);
FF_AUTO_CLOSE_DIR DIR* dir = opendir(baseDir->chars);
if(dir == NULL)
{
ffStrbufSubstrBefore(baseDir, baseDirLength);
@@ -309,33 +318,34 @@ static void getPackageCountsBedrock(FFstrbuf* baseDir, FFPackagesResult* package
continue;
ffStrbufAppendS(baseDir, entry->d_name);
getPackageCounts(baseDir, packageCounts);
getPackageCounts(baseDir, packageCounts, options);
ffStrbufSubstrBefore(baseDir, baseDirLength2);
}
closedir(dir);
ffStrbufSubstrBefore(baseDir, baseDirLength);
}
void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options)
void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options)
{
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(512);
ffStrbufAppendS(&baseDir, FASTFETCH_TARGET_DIR_ROOT);
if(ffStrbufIgnCaseEqualS(&ffDetectOS()->id, "bedrock"))
getPackageCountsBedrock(&baseDir, result);
getPackageCountsBedrock(&baseDir, result, options);
else
getPackageCountsRegular(&baseDir, result);
getPackageCountsRegular(&baseDir, result, options);
// If SQL failed, we can still try with librpm.
// This is needed on openSUSE, which seems to use a proprietary database file
// This method doesn't work on bedrock, so we do it here.
#ifdef FF_HAVE_RPM
if(result->rpm == 0)
if(!(options->disabled & FF_PACKAGES_FLAG_RPM_BIT) && result->rpm == 0)
result->rpm = getRpmFromLibrpm();
#endif
ffStrbufSet(&baseDir, &instance.state.platform.homeDir);
result->nixUser = getNixPackages(&baseDir, "/.nix-profile");
result->flatpakUser = getFlatpak(&baseDir, "/.local/share/flatpak");
if (!(options->disabled & FF_PACKAGES_FLAG_NIX_BIT))
result->nixUser = getNixPackages(&baseDir, "/.nix-profile");
if (!(options->disabled & FF_PACKAGES_FLAG_FLATPAK_BIT))
result->flatpakUser = getFlatpak(&baseDir, "/.local/share/flatpak");
}
+4 -5
View File
@@ -107,9 +107,8 @@ static void detectWinget(FFPackagesResult* result)
void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options)
{
detectScoop(result);
detectChoco(result);
detectPacman(result);
if (options->winget)
detectWinget(result);
if (!(options->disabled & FF_PACKAGES_FLAG_SCOOP_BIT)) detectScoop(result);
if (!(options->disabled & FF_PACKAGES_FLAG_CHOCO_BIT)) detectChoco(result);
if (!(options->disabled & FF_PACKAGES_FLAG_PACMAN_BIT)) detectPacman(result);
if (!(options->disabled & FF_PACKAGES_FLAG_WINGET_BIT)) detectWinget(result);
}
+11 -1
View File
@@ -170,7 +170,17 @@ static void detectFromWindowsTeriminal(const FFstrbuf* terminalExe, FFTerminalFo
if(terminalExe && terminalExe->length > 0 && !ffStrbufEqualS(terminalExe, "Windows Terminal"))
{
char jsonPath[MAX_PATH + 1];
if(SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, jsonPath)))
strncpy(jsonPath, terminalExe->chars, ffStrbufLastIndexC(terminalExe, '\\') + 1);
char* pathEnd = jsonPath + strlen(jsonPath);
strncpy(pathEnd, ".portable", sizeof(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
if(ffPathExists(jsonPath, FF_PATHTYPE_FILE))
{
strncpy(pathEnd, "settings\\settings.json", sizeof(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
if(!ffAppendFileBuffer(jsonPath, &json))
error = "Error reading Windows Terminal portable settings JSON file";
}
else if(SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, jsonPath)))
{
size_t remaining = sizeof(jsonPath) - strlen(jsonPath) - 1;
if(ffStrbufContainIgnCaseS(terminalExe, "_8wekyb3d8bbwe\\"))
+16 -1
View File
@@ -222,7 +222,22 @@ static bool printSpecificCommandHelp(const char* command)
yyjson_val* remarkKey = yyjson_obj_get(flagObj, "remark");
if (remarkKey)
printf("%10s: %s\n", "Remark", yyjson_get_str(remarkKey));
{
if (yyjson_is_str(remarkKey))
printf("%10s: %s\n", "Remark", yyjson_get_str(remarkKey));
else if (yyjson_is_arr(remarkKey) && yyjson_arr_size(remarkKey) > 0)
{
yyjson_val* remarkStr;
size_t remarkIdx, remarkMax;
yyjson_arr_foreach(remarkKey, remarkIdx, remarkMax, remarkStr)
{
if (remarkIdx == 0)
printf("%10s: %s\n", "Remark", yyjson_get_str(remarkStr));
else
printf(" %s\n", yyjson_get_str(remarkStr));
}
}
}
return true;
}
+128 -18
View File
@@ -4,37 +4,55 @@
#include "modules/colors/colors.h"
#include "util/stringUtils.h"
static inline uint8_t min(uint8_t a, uint8_t b)
{
return a < b ? a : b;
}
static inline uint8_t max(uint8_t a, uint8_t b)
{
return a > b ? a : b;
}
void ffPrintColors(FFColorsOptions* options)
{
if(instance.config.display.pipe)
return;
ffPrintLogoAndKey(FF_COLORS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
bool flag = false;
if(options->paddingLeft > 0)
ffPrintCharTimes(' ', options->paddingLeft);
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreateA(128);
if (options->symbol == FF_COLORS_SYMBOL_BLOCK)
{
// 4%d: Set the background color
// 3%d: Set the foreground color
for(uint8_t i = 0; i < 8; i++)
printf("\033[3%dm███", i);
for(uint8_t i = options->block.range[0]; i <= min(options->block.range[1], 7); i++)
{
ffStrbufAppendF(&result, "\e[3%dm", i);
for (uint8_t j = 0; j < options->block.width; j++)
ffStrbufAppendS(&result, "");
}
if (result.length > 0)
{
ffPrintLogoAndKey(FF_COLORS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
flag = true;
puts(FASTFETCH_TEXT_MODIFIER_RESET);
if(options->paddingLeft > 0)
ffPrintCharTimes(' ', options->paddingLeft);
ffLogoPrintLine();
if(options->paddingLeft > 0)
ffPrintCharTimes(' ', options->paddingLeft);
ffStrbufAppendS(&result, FASTFETCH_TEXT_MODIFIER_RESET);
ffStrbufPutTo(&result, stdout);
ffStrbufClear(&result);
}
// 1: Set everything to bolt. This causes normal colors on some systems to be bright.
// 4%d: Set the background to the not bright color
// 3%d: Set the foreground to the not bright color
// 10%d: Set the background to the bright color
// 9%d: Set the foreground to the bright color
for(uint8_t i = 0; i < 8; i++)
printf("\033[1;3%d;9%dm███", i, i);
for(uint8_t i = max(options->block.range[0], 8); i <= options->block.range[1]; i++)
{
ffStrbufAppendF(&result, "\e[1;9%dm", i - 8);
for (uint8_t j = 0; j < options->block.width; j++)
ffStrbufAppendS(&result, "");
}
}
else
{
@@ -49,10 +67,29 @@ void ffPrintColors(FFColorsOptions* options)
default: symbol = "███"; break;
}
for (int i = 8; i >= 1; --i)
printf("\e[3%dm%s ", i, symbol);
ffStrbufAppendF(&result, "\e[3%dm%s ", i, symbol);
}
puts(FASTFETCH_TEXT_MODIFIER_RESET);
if (result.length > 0)
{
if (flag)
ffLogoPrintLine();
else
{
ffPrintLogoAndKey(FF_COLORS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
flag = true;
}
if(options->paddingLeft > 0)
ffPrintCharTimes(' ', options->paddingLeft);
ffStrbufAppendS(&result, FASTFETCH_TEXT_MODIFIER_RESET);
ffStrbufPutTo(&result, stdout);
}
if (!flag)
{
ffPrintError(FF_COLORS_MODULE_NAME, 0, &options->moduleArgs, "%s", "Nothing to print");
}
}
bool ffParseColorsCommandOptions(FFColorsOptions* options, const char* key, const char* value)
@@ -82,6 +119,24 @@ bool ffParseColorsCommandOptions(FFColorsOptions* options, const char* key, cons
return true;
}
if (ffStrEqualsIgnCase(subKey, "block-width"))
{
options->block.width = (uint8_t) ffOptionParseUInt32(key, value);
return true;
}
if (ffStrEqualsIgnCase(subKey, "block-range-start"))
{
options->block.range[0] = min((uint8_t) ffOptionParseUInt32(key, value), 15);
return true;
}
if (ffStrEqualsIgnCase(subKey, "block-range-end"))
{
options->block.range[1] = min((uint8_t) ffOptionParseUInt32(key, value), 15);
return true;
}
return false;
}
@@ -123,6 +178,40 @@ void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module)
continue;
}
if (ffStrEqualsIgnCase(key, "block"))
{
if (!yyjson_is_obj(val))
ffPrintErrorString(FF_COLORS_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Invalid %s value: must be an object", key);
else
{
yyjson_val* width = yyjson_obj_get(val, "width");
if (width)
options->block.width = (uint8_t) yyjson_get_uint(width);
yyjson_val* range = yyjson_obj_get(val, "range");
if (range)
{
if (!yyjson_is_arr(range) || yyjson_arr_size(range) != 2)
ffPrintErrorString(FF_COLORS_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Invalid %s.range value: must be an array of 2 elements", key);
else
{
uint8_t start = (uint8_t) yyjson_get_uint(yyjson_arr_get(range, 0));
uint8_t end = (uint8_t) yyjson_get_uint(yyjson_arr_get(range, 1));
if (start > end)
ffPrintErrorString(FF_COLORS_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Invalid %s.range value: range[0] > range[1]", key);
else if (end > 15)
ffPrintErrorString(FF_COLORS_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Invalid %s.range value: range[1] > 15", key);
else
{
options->block.range[0] = start;
options->block.range[1] = end;
}
}
}
}
continue;
}
ffPrintErrorString(FF_COLORS_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Unknown JSON key %s", key);
}
}
@@ -149,6 +238,23 @@ void ffGenerateColorsJsonConfig(FFColorsOptions* options, yyjson_mut_doc* doc, y
if (defaultOptions.paddingLeft != options->paddingLeft)
yyjson_mut_obj_add_uint(doc, module, "paddingLeft", options->paddingLeft);
{
yyjson_mut_val* block = yyjson_mut_obj(doc);
if (defaultOptions.block.width != options->block.width)
yyjson_mut_obj_add_uint(doc, block, "width", options->block.width);
if (memcmp(defaultOptions.block.range, options->block.range, sizeof(options->block.range)) != 0)
{
yyjson_mut_val* range = yyjson_mut_obj_add_arr(doc, block, "range");
for (uint8_t i = 0; i < 2; i++)
yyjson_mut_arr_add_uint(doc, range, options->block.range[i]);
}
if (yyjson_mut_obj_size(block) > 0)
yyjson_mut_obj_add_val(doc, module, "block", block);
}
}
void ffInitColorsOptions(FFColorsOptions* options)
@@ -168,6 +274,10 @@ void ffInitColorsOptions(FFColorsOptions* options)
ffStrbufSetStatic(&options->moduleArgs.key, " ");
options->symbol = FF_COLORS_SYMBOL_BLOCK;
options->paddingLeft = 0;
options->block = (FFBlockConfig) {
.width = 3,
.range = { 0, 15 },
};
}
void ffDestroyColorsOptions(FF_MAYBE_UNUSED FFColorsOptions* options)
+7
View File
@@ -14,6 +14,12 @@ typedef enum FFColorsSymbol
FF_COLORS_SYMBOL_STAR,
} FFColorsSymbol;
typedef struct FFBlockConfig
{
uint8_t width;
uint8_t range[2];
} FFBlockConfig;
typedef struct FFColorsOptions
{
FFModuleBaseInfo moduleInfo;
@@ -21,4 +27,5 @@ typedef struct FFColorsOptions
FFColorsSymbol symbol;
uint32_t paddingLeft;
FFBlockConfig block;
} FFColorsOptions;
+26 -8
View File
@@ -58,18 +58,21 @@ void ffPrintDiskIO(FFDiskIOOptions* options)
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffParseSize(dev->bytesRead, &buffer);
ffStrbufAppendS(&buffer, "/s (R) - ");
if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s");
ffStrbufAppendS(&buffer, " (R) - ");
ffParseSize(dev->bytesWritten, &buffer);
ffStrbufAppendS(&buffer, "/s (W)");
if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s");
ffStrbufAppendS(&buffer, " (W)");
ffStrbufPutTo(&buffer, stdout);
}
else
{
ffStrbufClear(&buffer2);
ffParseSize(dev->bytesRead, &buffer);
ffStrbufAppendS(&buffer, "/s");
if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s");
ffParseSize(dev->bytesWritten, &buffer2);
ffStrbufAppendS(&buffer2, "/s");
if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s");
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISKIO_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &buffer},
@@ -105,6 +108,12 @@ bool ffParseDiskIOCommandOptions(FFDiskIOOptions* options, const char* key, cons
return true;
}
if (ffStrEqualsIgnCase(subKey, "detect-total"))
{
options->detectTotal = ffOptionParseBoolean(value);
return true;
}
return false;
}
@@ -127,6 +136,12 @@ void ffParseDiskIOJsonObject(FFDiskIOOptions* options, yyjson_val* module)
continue;
}
if (ffStrEqualsIgnCase(key, "detectTotal"))
{
options->detectTotal = yyjson_get_bool(val);
continue;
}
ffPrintError(FF_DISKIO_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
@@ -140,6 +155,9 @@ void ffGenerateDiskIOJsonConfig(FFDiskIOOptions* options, yyjson_mut_doc* doc, y
if (!ffStrbufEqual(&options->namePrefix, &defaultOptions.namePrefix))
yyjson_mut_obj_add_strbuf(doc, module, "namePrefix", &options->namePrefix);
if (defaultOptions.detectTotal != options->detectTotal)
yyjson_mut_obj_add_bool(doc, module, "detectTotal", options->detectTotal);
}
void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
@@ -175,12 +193,12 @@ void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, y
void ffPrintDiskIOHelpFormat(void)
{
ffPrintModuleFormatHelp(FF_DISKIO_MODULE_NAME, "{1} (R) - {2} (W)", FF_DISKIO_NUM_FORMAT_ARGS, (const char* []) {
"Size of data read per second (formatted)",
"Size of data written per second (formatted)",
"Size of data read [per second] (formatted)",
"Size of data written [per second] (formatted)",
"Device name",
"Device raw file path",
"Size of data read per second (in bytes)",
"Size of data written per second (in bytes)",
"Size of data read [per second] (in bytes)",
"Size of data written [per second] (in bytes)",
"Number of reads",
"Number of writes",
});
+1
View File
@@ -10,4 +10,5 @@ typedef struct FFDiskIOOptions
FFModuleArgs moduleArgs;
FFstrbuf namePrefix;
bool detectTotal;
} FFDiskIOOptions;
+76 -8
View File
@@ -6,6 +6,16 @@
#define FF_DISPLAY_NUM_FORMAT_ARGS 8
static int sortByNameAsc(FFDisplayResult* a, FFDisplayResult* b)
{
return ffStrbufComp(&a->name, &b->name);
}
static int sortByNameDesc(FFDisplayResult* a, FFDisplayResult* b)
{
return -ffStrbufComp(&a->name, &b->name);
}
void ffPrintDisplay(FFDisplayOptions* options)
{
const FFDisplayServerResult* dsResult = ffConnectDisplayServer();
@@ -16,25 +26,46 @@ void ffPrintDisplay(FFDisplayOptions* options)
return;
}
if (options->order != FF_DISPLAY_ORDER_NONE)
{
ffListSort((FFlist*) &dsResult->displays, (void*) (options->order == FF_DISPLAY_ORDER_ASC ? sortByNameAsc : sortByNameDesc));
}
if (options->compactType != FF_DISPLAY_COMPACT_TYPE_NONE)
{
ffPrintLogoAndKey(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
int index = 0;
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
FF_LIST_FOR_EACH(FFDisplayResult, result, dsResult->displays)
{
if (options->compactType & FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT)
{
if (index++) putchar(' ');
printf("%ix%i", result->width, result->height);
ffStrbufAppendF(&buffer, "%ix%i", result->width, result->height);
}
if (options->compactType & FF_DISPLAY_COMPACT_TYPE_SCALED_BIT)
else
{
if (index++) putchar(' ');
printf("%ix%i", result->scaledWidth, result->scaledHeight);
ffStrbufAppendF(&buffer, "%ix%i", result->scaledWidth, result->scaledHeight);
}
if (options->compactType & FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT)
{
if (result->refreshRate > 0)
{
if (options->preciseRefreshRate)
ffStrbufAppendF(&buffer, " @ %gHz", result->refreshRate);
else
ffStrbufAppendF(&buffer, " @ %iHz", (uint32_t) (result->refreshRate + 0.5));
}
ffStrbufAppendS(&buffer, ", ");
}
else
{
ffStrbufAppendC(&buffer, ' ');
}
}
putchar('\n');
ffStrbufTrimRight(&buffer, ' ');
ffStrbufTrimRight(&buffer, ',');
ffStrbufPutTo(&buffer, stdout);
return;
}
@@ -122,6 +153,8 @@ bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, co
{ "none", FF_DISPLAY_COMPACT_TYPE_NONE },
{ "original", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT },
{ "scaled", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT },
{ "original-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
{ "scaled-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
{},
});
return true;
@@ -133,6 +166,17 @@ bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, co
return true;
}
if (ffStrEqualsIgnCase(subKey, "order"))
{
options->order = (FFDisplayOrder) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
{ "asc", FF_DISPLAY_ORDER_ASC },
{ "desc", FF_DISPLAY_ORDER_DESC },
{ "none", FF_DISPLAY_ORDER_NONE },
{},
});
return true;
}
return false;
}
@@ -156,6 +200,8 @@ void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module)
{ "none", FF_DISPLAY_COMPACT_TYPE_NONE },
{ "original", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT },
{ "scaled", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT },
{ "original-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
{ "scaled-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
{},
});
if (error)
@@ -171,6 +217,22 @@ void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module)
continue;
}
if (ffStrEqualsIgnCase(key, "order"))
{
int value;
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
{ "asc", FF_DISPLAY_ORDER_ASC },
{ "desc", FF_DISPLAY_ORDER_DESC },
{ "none", FF_DISPLAY_ORDER_NONE },
{},
});
if (error)
ffPrintError(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, "Invalid %s value: %s", key, error);
else
options->order = (FFDisplayOrder) value;
continue;
}
ffPrintError(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
@@ -184,7 +246,7 @@ void ffGenerateDisplayJsonConfig(FFDisplayOptions* options, yyjson_mut_doc* doc,
if (options->compactType != defaultOptions.compactType)
{
switch (options->compactType)
switch ((int) options->compactType)
{
case FF_DISPLAY_COMPACT_TYPE_NONE:
yyjson_mut_obj_add_str(doc, module, "compactType", "none");
@@ -195,6 +257,12 @@ void ffGenerateDisplayJsonConfig(FFDisplayOptions* options, yyjson_mut_doc* doc,
case FF_DISPLAY_COMPACT_TYPE_SCALED_BIT:
yyjson_mut_obj_add_str(doc, module, "compactType", "scaled");
break;
case FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT:
yyjson_mut_obj_add_str(doc, module, "compactType", "original-with-refresh-rate");
break;
case FF_DISPLAY_COMPACT_TYPE_SCALED_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT:
yyjson_mut_obj_add_str(doc, module, "compactType", "scaled-with-refresh-rate");
break;
}
}
+9
View File
@@ -9,8 +9,16 @@ typedef enum FFDisplayCompactType
FF_DISPLAY_COMPACT_TYPE_NONE = 0,
FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT = 1 << 0,
FF_DISPLAY_COMPACT_TYPE_SCALED_BIT = 1 << 1,
FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT = 1 << 2,
} FFDisplayCompactType;
typedef enum FFDisplayOrder
{
FF_DISPLAY_ORDER_NONE,
FF_DISPLAY_ORDER_ASC,
FF_DISPLAY_ORDER_DESC,
} FFDisplayOrder;
typedef struct FFDisplayOptions
{
FFModuleBaseInfo moduleInfo;
@@ -18,4 +26,5 @@ typedef struct FFDisplayOptions
FFDisplayCompactType compactType;
bool preciseRefreshRate;
FFDisplayOrder order;
} FFDisplayOptions;
+34 -15
View File
@@ -60,10 +60,14 @@ void ffPrintNetIO(FFNetIOOptions* options)
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffParseSize(inf->rxBytes, &buffer);
ffStrbufAppendS(&buffer, "/s (IN) - ");
if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s");
ffStrbufAppendS(&buffer, " (IN) - ");
ffParseSize(inf->txBytes, &buffer);
ffStrbufAppendS(&buffer, "/s (OUT)");
if (!options->defaultRouteOnly && inf->defaultRoute)
if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s");
ffStrbufAppendS(&buffer, " (OUT)");
if (inf->defaultRoute)
ffStrbufAppendS(&buffer, " *");
ffStrbufPutTo(&buffer, stdout);
}
@@ -71,9 +75,9 @@ void ffPrintNetIO(FFNetIOOptions* options)
{
ffStrbufClear(&buffer2);
ffParseSize(inf->rxBytes, &buffer);
ffStrbufAppendS(&buffer, "/s");
if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s");
ffParseSize(inf->txBytes, &buffer2);
ffStrbufAppendS(&buffer2, "/s");
if (!options->detectTotal) ffStrbufAppendS(&buffer2, "/s");
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_NETIO_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &buffer},
@@ -118,6 +122,12 @@ bool ffParseNetIOCommandOptions(FFNetIOOptions* options, const char* key, const
return true;
}
if (ffStrEqualsIgnCase(subKey, "detect-total"))
{
options->detectTotal = ffOptionParseBoolean(value);
return true;
}
return false;
}
@@ -146,6 +156,12 @@ void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module)
continue;
}
if (ffStrEqualsIgnCase(key, "detectTotal"))
{
options->detectTotal = yyjson_get_bool(val);
continue;
}
ffPrintError(FF_NETIO_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
@@ -162,6 +178,9 @@ void ffGenerateNetIOJsonConfig(FFNetIOOptions* options, yyjson_mut_doc* doc, yyj
if (options->defaultRouteOnly != defaultOptions.defaultRouteOnly)
yyjson_mut_obj_add_bool(doc, module, "defaultRouteOnly", options->defaultRouteOnly);
if (options->detectTotal != defaultOptions.detectTotal)
yyjson_mut_obj_add_bool(doc, module, "detectTotal", options->detectTotal);
}
void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
@@ -200,18 +219,18 @@ void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyj
void ffPrintNetIOHelpFormat(void)
{
ffPrintModuleFormatHelp(FF_NETIO_MODULE_NAME, "{1} (IN) - {2} (OUT)", FF_NETIO_NUM_FORMAT_ARGS, (const char* []) {
"Size of data received per second (formatted)",
"Size of data sent per second (formatted)",
"Size of data received [per second] (formatted)",
"Size of data sent [per second] (formatted)",
"Interface name",
"Is default route",
"Size of data received per second (in bytes)",
"Size of data sent per second (in bytes)",
"Number of packets received per second",
"Number of packets sent per second",
"Number of errors received per second",
"Number of errors sent per second",
"Number of packets dropped when receiving per second",
"Number of packets dropped when sending per second",
"Size of data received [per second] (in bytes)",
"Size of data sent [per second] (in bytes)",
"Number of packets received [per second]",
"Number of packets sent [per second]",
"Number of errors received [per second]",
"Number of errors sent [per second]",
"Number of packets dropped when receiving [per second]",
"Number of packets dropped when sending [per second]",
});
}
+1
View File
@@ -11,4 +11,5 @@ typedef struct FFNetIOOptions
FFstrbuf namePrefix;
bool defaultRouteOnly;
bool detectTotal;
} FFNetIOOptions;
+25 -3
View File
@@ -4,12 +4,34 @@
#include "common/option.h"
typedef enum FFPackagesFlags
{
FF_PACKAGES_FLAG_NONE = 0,
FF_PACKAGES_FLAG_APK_BIT = 1 << 0,
FF_PACKAGES_FLAG_BREW_BIT = 1 << 1,
FF_PACKAGES_FLAG_CHOCO_BIT = 1 << 2,
FF_PACKAGES_FLAG_DPKG_BIT = 1 << 3,
FF_PACKAGES_FLAG_EMERGE_BIT = 1 << 4,
FF_PACKAGES_FLAG_EOPKG_BIT = 1 << 5,
FF_PACKAGES_FLAG_FLATPAK_BIT = 1 << 6,
FF_PACKAGES_FLAG_NIX_BIT = 1 << 7,
FF_PACKAGES_FLAG_OPKG_BIT = 1 << 8,
FF_PACKAGES_FLAG_PACMAN_BIT = 1 << 9,
FF_PACKAGES_FLAG_PALUDIS_BIT = 1 << 10,
FF_PACKAGES_FLAG_PKG_BIT = 1 << 11,
FF_PACKAGES_FLAG_PKGTOOL_BIT = 1 << 12,
FF_PACKAGES_FLAG_MACPORTS_BIT = 1 << 13,
FF_PACKAGES_FLAG_RPM_BIT = 1 << 14,
FF_PACKAGES_FLAG_SCOOP_BIT = 1 << 15,
FF_PACKAGES_FLAG_SNAP_BIT = 1 << 16,
FF_PACKAGES_FLAG_WINGET_BIT = 1 << 17,
FF_PACKAGES_FLAG_XBPS_BIT = 1 << 18,
} FFPackagesFlags;
typedef struct FFPackagesOptions
{
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
#ifdef _WIN32
bool winget;
#endif
FFPackagesFlags disabled;
} FFPackagesOptions;
+113 -19
View File
@@ -28,7 +28,7 @@ void ffPrintPackages(FFPackagesOptions* options)
{ \
printf("%u (%s)", counts.var, (name)); \
if((all -= counts.var) > 0) \
printf(", "); \
fputs(", ", stdout); \
};
#define FF_PRINT_PACKAGE(name) FF_PRINT_PACKAGE_NAME(name, #name)
@@ -42,7 +42,6 @@ void ffPrintPackages(FFPackagesOptions* options)
if((all -= counts.pacman) > 0)
printf(", ");
};
FF_PRINT_PACKAGE(dpkg)
FF_PRINT_PACKAGE(rpm)
FF_PRINT_PACKAGE(emerge)
@@ -109,13 +108,52 @@ bool ffParsePackagesCommandOptions(FFPackagesOptions* options, const char* key,
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
return true;
#ifdef _WIN32
if(ffStrEqualsIgnCase(subKey, "winget"))
if (ffStrEqualsIgnCase(subKey, "disabled"))
{
options->winget = ffOptionParseBoolean(value);
options->disabled = FF_PACKAGES_FLAG_NONE;
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
ffOptionParseString(key, value, &buffer);
char *start = buffer.chars, *end = strchr(start, ':');
while (true)
{
if (end)
*end = '\0';
#define FF_TEST_PACKAGE_NAME(name) else if (ffStrEqualsIgnCase(start, #name)) { options->disabled |= FF_PACKAGES_FLAG_ ## name ## _BIT; }
if (false);
FF_TEST_PACKAGE_NAME(APK)
FF_TEST_PACKAGE_NAME(BREW)
FF_TEST_PACKAGE_NAME(CHOCO)
FF_TEST_PACKAGE_NAME(DPKG)
FF_TEST_PACKAGE_NAME(EMERGE)
FF_TEST_PACKAGE_NAME(EOPKG)
FF_TEST_PACKAGE_NAME(FLATPAK)
FF_TEST_PACKAGE_NAME(NIX)
FF_TEST_PACKAGE_NAME(OPKG)
FF_TEST_PACKAGE_NAME(PACMAN)
FF_TEST_PACKAGE_NAME(PALUDIS)
FF_TEST_PACKAGE_NAME(PKG)
FF_TEST_PACKAGE_NAME(PKGTOOL)
FF_TEST_PACKAGE_NAME(MACPORTS)
FF_TEST_PACKAGE_NAME(RPM)
FF_TEST_PACKAGE_NAME(SCOOP)
FF_TEST_PACKAGE_NAME(SNAP)
FF_TEST_PACKAGE_NAME(WINGET)
FF_TEST_PACKAGE_NAME(XBPS)
#undef FF_TEST_PACKAGE_NAME
if (end)
{
start = end + 1;
end = strchr(end, ':');
}
else
break;
}
return true;
}
#endif
return false;
}
@@ -127,19 +165,55 @@ void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module)
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
if (ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
#ifdef _WIN32
if (ffStrEqualsIgnCase(key, "winget"))
if (ffStrEqualsIgnCase(key, "disabled"))
{
options->winget = yyjson_get_bool(val);
continue;
if (!yyjson_is_null(val) && !yyjson_is_arr(val))
{
ffPrintError(FF_PACKAGES_MODULE_NAME, 0, &options->moduleArgs, "Invalid JSON value for %s", key);
continue;
}
options->disabled = FF_PACKAGES_FLAG_NONE;
if (yyjson_is_arr(val))
{
yyjson_val* flagObj;
size_t flagIdx, flagMax;
yyjson_arr_foreach(val, flagIdx, flagMax, flagObj)
{
const char* flag = yyjson_get_str(flagObj);
#define FF_TEST_PACKAGE_NAME(name) else if (ffStrEqualsIgnCase(flag, #name)) { options->disabled |= FF_PACKAGES_FLAG_ ## name ## _BIT; }
if (false);
FF_TEST_PACKAGE_NAME(APK)
FF_TEST_PACKAGE_NAME(BREW)
FF_TEST_PACKAGE_NAME(CHOCO)
FF_TEST_PACKAGE_NAME(DPKG)
FF_TEST_PACKAGE_NAME(EMERGE)
FF_TEST_PACKAGE_NAME(EOPKG)
FF_TEST_PACKAGE_NAME(FLATPAK)
FF_TEST_PACKAGE_NAME(NIX)
FF_TEST_PACKAGE_NAME(OPKG)
FF_TEST_PACKAGE_NAME(PACMAN)
FF_TEST_PACKAGE_NAME(PALUDIS)
FF_TEST_PACKAGE_NAME(PKG)
FF_TEST_PACKAGE_NAME(PKGTOOL)
FF_TEST_PACKAGE_NAME(MACPORTS)
FF_TEST_PACKAGE_NAME(RPM)
FF_TEST_PACKAGE_NAME(SCOOP)
FF_TEST_PACKAGE_NAME(SNAP)
FF_TEST_PACKAGE_NAME(WINGET)
FF_TEST_PACKAGE_NAME(XBPS)
#undef FF_TEST_PACKAGE_NAME
}
}
}
#endif
ffPrintError(FF_PACKAGES_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
@@ -152,10 +226,32 @@ void ffGeneratePackagesJsonConfig(FFPackagesOptions* options, yyjson_mut_doc* do
ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
#ifdef _WIN32
if (options->winget != defaultOptions.winget)
yyjson_mut_obj_add_bool(doc, module, "winget", options->winget);
#endif
if (options->disabled != defaultOptions.disabled)
{
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "disabled");
#define FF_TEST_PACKAGE_NAME(name) else if ((options->disabled & FF_PACKAGES_FLAG_ ## name ## _BIT) != (defaultOptions.disabled & FF_PACKAGES_FLAG_ ## name ## _BIT)) { yyjson_mut_arr_add_str(doc, arr, #name); }
if (false);
FF_TEST_PACKAGE_NAME(APK)
FF_TEST_PACKAGE_NAME(BREW)
FF_TEST_PACKAGE_NAME(CHOCO)
FF_TEST_PACKAGE_NAME(DPKG)
FF_TEST_PACKAGE_NAME(EMERGE)
FF_TEST_PACKAGE_NAME(EOPKG)
FF_TEST_PACKAGE_NAME(FLATPAK)
FF_TEST_PACKAGE_NAME(NIX)
FF_TEST_PACKAGE_NAME(OPKG)
FF_TEST_PACKAGE_NAME(PACMAN)
FF_TEST_PACKAGE_NAME(PALUDIS)
FF_TEST_PACKAGE_NAME(PKG)
FF_TEST_PACKAGE_NAME(PKGTOOL)
FF_TEST_PACKAGE_NAME(MACPORTS)
FF_TEST_PACKAGE_NAME(RPM)
FF_TEST_PACKAGE_NAME(SCOOP)
FF_TEST_PACKAGE_NAME(SNAP)
FF_TEST_PACKAGE_NAME(WINGET)
FF_TEST_PACKAGE_NAME(XBPS)
#undef FF_TEST_PACKAGE_NAME
}
}
void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
@@ -248,9 +344,7 @@ void ffInitPackagesOptions(FFPackagesOptions* options)
);
ffOptionInitModuleArg(&options->moduleArgs);
#ifdef _WIN32
options->winget = false;
#endif
options->disabled = FF_PACKAGES_FLAG_WINGET_BIT;
}
void ffDestroyPackagesOptions(FFPackagesOptions* options)
-5
View File
@@ -300,11 +300,6 @@ static inline int ffStrbufComp(const FFstrbuf* strbuf, const FFstrbuf* comp)
return memcmp(strbuf->chars, comp->chars, length + 1);
}
static inline int ffStrbufCompAlphabetically(const FFstrbuf* strbuf, const FFstrbuf* comp)
{
return strcmp(strbuf->chars, comp->chars);
}
static inline FF_C_NODISCARD bool ffStrbufEqual(const FFstrbuf* strbuf, const FFstrbuf* comp)
{
return ffStrbufComp(strbuf, comp) == 0;
+4
View File
@@ -7,6 +7,7 @@
#include <pwd.h>
#include <limits.h>
#include <sys/utsname.h>
#include <paths.h>
#ifdef __APPLE__
#include <libproc.h>
@@ -135,6 +136,9 @@ static void getDataDirs(FFPlatform* platform)
ffPlatformPathAddHome(&platform->dataDirs, platform, "");
platformPathAddEnv(&platform->dataDirs, "XDG_DATA_DIRS");
#ifdef _PATH_LOCALBASE
ffPlatformPathAddAbsolute(&platform->dataDirs, _PATH_LOCALBASE "/share/");
#endif
ffPlatformPathAddAbsolute(&platform->dataDirs, FASTFETCH_TARGET_DIR_USR "/local/share/");
ffPlatformPathAddAbsolute(&platform->dataDirs, FASTFETCH_TARGET_DIR_USR "/share/");
}
+30 -10
View File
@@ -192,13 +192,13 @@ static void getSystemReleaseAndVersion(FFPlatform* platform)
switch (osVersion.dwPlatformId)
{
case VER_PLATFORM_WIN32s:
ffStrbufAppendS(&platform->systemName, "WIN32s");
ffStrbufSetStatic(&platform->systemName, "WIN32s");
break;
case VER_PLATFORM_WIN32_WINDOWS:
ffStrbufAppendS(&platform->systemName, "WIN32_WINDOWS");
ffStrbufSetStatic(&platform->systemName, "WIN32_WINDOWS");
break;
case VER_PLATFORM_WIN32_NT:
ffStrbufAppendS(&platform->systemName, "WIN32_NT");
ffStrbufSetStatic(&platform->systemName, "WIN32_NT");
break;
}
}
@@ -211,25 +211,45 @@ static void getSystemArchitectureAndPageSize(FFPlatform* platform)
switch(sysInfo.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
ffStrbufAppendS(&platform->systemArchitecture, "x86_64");
ffStrbufSetStatic(&platform->systemArchitecture, "x86_64");
break;
case PROCESSOR_ARCHITECTURE_IA64:
ffStrbufAppendS(&platform->systemArchitecture, "ia64");
ffStrbufSetStatic(&platform->systemArchitecture, "ia64");
break;
case PROCESSOR_ARCHITECTURE_INTEL:
ffStrbufAppendS(&platform->systemArchitecture, "i686");
switch (sysInfo.wProcessorLevel)
{
case 4:
ffStrbufSetStatic(&platform->systemArchitecture, "i486");
break;
case 5:
ffStrbufSetStatic(&platform->systemArchitecture, "i586");
break;
case 6:
ffStrbufSetStatic(&platform->systemArchitecture, "i686");
break;
default:
ffStrbufSetStatic(&platform->systemArchitecture, "i386");
break;
}
break;
case PROCESSOR_ARCHITECTURE_ARM64:
ffStrbufAppendS(&platform->systemArchitecture, "aarch64");
ffStrbufSetStatic(&platform->systemArchitecture, "aarch64");
break;
case PROCESSOR_ARCHITECTURE_ARM:
ffStrbufAppendS(&platform->systemArchitecture, "arm");
ffStrbufSetStatic(&platform->systemArchitecture, "arm");
break;
case PROCESSOR_ARCHITECTURE_PPC:
ffStrbufAppendS(&platform->systemArchitecture, "ppc");
ffStrbufSetStatic(&platform->systemArchitecture, "ppc");
break;
case PROCESSOR_ARCHITECTURE_MIPS:
ffStrbufAppendS(&platform->systemArchitecture, "mips");
ffStrbufSetStatic(&platform->systemArchitecture, "mips");
break;
case PROCESSOR_ARCHITECTURE_ALPHA:
ffStrbufSetStatic(&platform->systemArchitecture, "alpha");
break;
case PROCESSOR_ARCHITECTURE_ALPHA64:
ffStrbufSetStatic(&platform->systemArchitecture, "alpha64");
break;
case PROCESSOR_ARCHITECTURE_UNKNOWN:
default: