mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
TerminalFont: migrate to json-c to prevent from 3rd lib code embedding
This commit is contained in:
parent
199f2fc0cd
commit
e2e3561443
10
.github/workflows/push.yml
vendored
10
.github/workflows/push.yml
vendored
@ -21,12 +21,12 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: install required packages
|
- name: install required packages
|
||||||
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev rpm librpm-dev libzstd-dev libegl-dev libglx-dev libosmesa6-dev ocl-icd-opencl-dev libnm-dev libpulse-dev
|
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev rpm librpm-dev libzstd-dev libegl-dev libglx-dev libosmesa6-dev ocl-icd-opencl-dev libnm-dev libpulse-dev libjson-c-dev
|
||||||
|
|
||||||
- name: configure project
|
- name: configure project
|
||||||
env:
|
env:
|
||||||
CC: ${{ matrix.compiler }}
|
CC: ${{ matrix.compiler }}
|
||||||
run: cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_LIBPCI=${{ matrix.enableFeatures }} -DENABLE_VULKAN=${{ matrix.enableFeatures }} -DENABLE_WAYLAND=${{ matrix.enableFeatures }} -DENABLE_XCB_RANDR=${{ matrix.enableFeatures }} -DENABLE_XCB=${{ matrix.enableFeatures }} -DENABLE_XRANDR=${{ matrix.enableFeatures }} -DENABLE_X11=${{ matrix.enableFeatures }} -DENABLE_GIO=${{ matrix.enableFeatures }} -DENABLE_DCONF=${{ matrix.enableFeatures }} -DENABLE_DBUS=${{ matrix.enableFeatures }} -DENABLE_XFCONF=${{ matrix.enableFeatures }} -DENABLE_SQLITE3=${{ matrix.enableFeatures }} -DENABLE_RPM=${{ matrix.enableFeatures }} -DENABLE_IMAGEMAGICK7=${{ matrix.enableFeatures }} -DENABLE_IMAGEMAGICK6=${{ matrix.enableFeatures }} -DENABLE_CHAFA=${{ matrix.enableFeatures }} -DENABLE_ZLIB=${{ matrix.enableFeatures }} -DENABLE_EGL=${{ matrix.enableFeatures }} -DENABLE_GLX=${{ matrix.enableFeatures }} -DENABLE_OSMESA=${{ matrix.enableFeatures }} -DENABLE_OPENCL=${{ matrix.enableFeatures }} -DENABLE_LIBNM=${{ matrix.enableFeatures }} -DENABLE_PULSE=${{ matrix.enableFeatures }} .
|
run: cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_LIBPCI=${{ matrix.enableFeatures }} -DENABLE_VULKAN=${{ matrix.enableFeatures }} -DENABLE_WAYLAND=${{ matrix.enableFeatures }} -DENABLE_XCB_RANDR=${{ matrix.enableFeatures }} -DENABLE_XCB=${{ matrix.enableFeatures }} -DENABLE_XRANDR=${{ matrix.enableFeatures }} -DENABLE_X11=${{ matrix.enableFeatures }} -DENABLE_GIO=${{ matrix.enableFeatures }} -DENABLE_DCONF=${{ matrix.enableFeatures }} -DENABLE_DBUS=${{ matrix.enableFeatures }} -DENABLE_XFCONF=${{ matrix.enableFeatures }} -DENABLE_SQLITE3=${{ matrix.enableFeatures }} -DENABLE_RPM=${{ matrix.enableFeatures }} -DENABLE_IMAGEMAGICK7=${{ matrix.enableFeatures }} -DENABLE_IMAGEMAGICK6=${{ matrix.enableFeatures }} -DENABLE_CHAFA=${{ matrix.enableFeatures }} -DENABLE_ZLIB=${{ matrix.enableFeatures }} -DENABLE_EGL=${{ matrix.enableFeatures }} -DENABLE_GLX=${{ matrix.enableFeatures }} -DENABLE_OSMESA=${{ matrix.enableFeatures }} -DENABLE_OPENCL=${{ matrix.enableFeatures }} -DENABLE_LIBNM=${{ matrix.enableFeatures }} -DENABLE_PULSE=${{ matrix.enableFeatures }} -DENABLE_JSONC=${{ matrix.enableFeatures }} .
|
||||||
|
|
||||||
- name: build project
|
- name: build project
|
||||||
run: cmake --build .
|
run: cmake --build .
|
||||||
@ -53,7 +53,7 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: install required packages
|
- name: install required packages
|
||||||
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev rpm librpm-dev libzstd-dev libegl-dev libglx-dev libosmesa6-dev ocl-icd-opencl-dev libnm-dev libpulse-dev
|
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev rpm librpm-dev libzstd-dev libegl-dev libglx-dev libosmesa6-dev ocl-icd-opencl-dev libnm-dev libpulse-dev libjson-c-dev
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v2
|
uses: github/codeql-action/init@v2
|
||||||
@ -183,7 +183,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
msystem: CLANG64
|
msystem: CLANG64
|
||||||
update: true
|
update: true
|
||||||
install: git zip mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-vulkan-loader mingw-w64-clang-x86_64-opencl-icd
|
install: git zip mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-vulkan-loader mingw-w64-clang-x86_64-opencl-icd mingw-w64-clang-x86_64-json-c
|
||||||
|
|
||||||
- name: print msys version
|
- name: print msys version
|
||||||
run: uname -a
|
run: uname -a
|
||||||
@ -244,7 +244,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
msystem: CLANG32
|
msystem: CLANG32
|
||||||
update: true
|
update: true
|
||||||
install: git zip mingw-w64-clang-i686-cmake mingw-w64-clang-i686-clang mingw-w64-clang-i686-vulkan-loader mingw-w64-clang-i686-opencl-icd
|
install: git zip mingw-w64-clang-i686-cmake mingw-w64-clang-i686-clang mingw-w64-clang-i686-vulkan-loader mingw-w64-clang-i686-opencl-icd mingw-w64-clang-i686-json-c
|
||||||
|
|
||||||
- name: print msys version
|
- name: print msys version
|
||||||
run: uname -a
|
run: uname -a
|
||||||
|
@ -5,7 +5,7 @@ Bugfixes:
|
|||||||
* Fix compiling with musl (Wifi, Linux, #429)
|
* Fix compiling with musl (Wifi, Linux, #429)
|
||||||
|
|
||||||
Changes:
|
Changes:
|
||||||
* Use yyjson to parse JSON strings for comments support, instead of using unmaintained cJSON
|
* Use json-c to parse JSON strings for comments support, instead of using unmaintained cJSON
|
||||||
|
|
||||||
# 1.10.3
|
# 1.10.3
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR BSD OR WIN32"
|
|||||||
cmake_dependent_option(ENABLE_LIBNM "Enable libnm" ON "LINUX" OFF)
|
cmake_dependent_option(ENABLE_LIBNM "Enable libnm" ON "LINUX" OFF)
|
||||||
cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF)
|
cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF)
|
||||||
cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR BSD" OFF)
|
cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR BSD" OFF)
|
||||||
|
cmake_dependent_option(ENABLE_JSONC "Enable json-c" ON "LINUX OR WIN32" OFF)
|
||||||
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF)
|
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF)
|
||||||
cmake_dependent_option(ENABLE_BUFFER "Enable stdout buffer" ON "LINUX OR APPLE OR BSD OR WIN32 OR ANDROID" OFF)
|
cmake_dependent_option(ENABLE_BUFFER "Enable stdout buffer" ON "LINUX OR APPLE OR BSD OR WIN32 OR ANDROID" OFF)
|
||||||
cmake_dependent_option(USE_WIN_NTAPI "Allow using internal NTAPI" ON "WIN32" OFF)
|
cmake_dependent_option(USE_WIN_NTAPI "Allow using internal NTAPI" ON "WIN32" OFF)
|
||||||
@ -236,7 +237,6 @@ set(LIBFASTFETCH_SRC
|
|||||||
src/common/printing.c
|
src/common/printing.c
|
||||||
src/common/properties.c
|
src/common/properties.c
|
||||||
src/common/settings.c
|
src/common/settings.c
|
||||||
src/common/yyjson.c
|
|
||||||
src/detection/bluetooth/bluetooth.c
|
src/detection/bluetooth/bluetooth.c
|
||||||
src/detection/cpu/cpu.c
|
src/detection/cpu/cpu.c
|
||||||
src/detection/cpuUsage/cpuUsage.c
|
src/detection/cpuUsage/cpuUsage.c
|
||||||
@ -681,6 +681,10 @@ ff_lib_enable(PULSE
|
|||||||
"libpulse"
|
"libpulse"
|
||||||
"Pulse"
|
"Pulse"
|
||||||
)
|
)
|
||||||
|
ff_lib_enable(JSONC
|
||||||
|
"json-c"
|
||||||
|
"json-c"
|
||||||
|
)
|
||||||
|
|
||||||
if(ENABLE_THREADS)
|
if(ENABLE_THREADS)
|
||||||
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_THREADS)
|
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_THREADS)
|
||||||
|
@ -53,7 +53,7 @@ The following libraries are used if present at runtime:
|
|||||||
* [`libXFConf`](https://gitlab.xfce.org/xfce/xfconf): Needed for XFWM theme and XFCE Terminal font.
|
* [`libXFConf`](https://gitlab.xfce.org/xfce/xfconf): Needed for XFWM theme and XFCE Terminal font.
|
||||||
* [`libsqlite3`](https://www.sqlite.org/index.html): Needed for pkg & rpm package count.
|
* [`libsqlite3`](https://www.sqlite.org/index.html): Needed for pkg & rpm package count.
|
||||||
* [`librpm`](http://rpm.org/): Slower fallback for rpm package count. Needed on openSUSE.
|
* [`librpm`](http://rpm.org/): Slower fallback for rpm package count. Needed on openSUSE.
|
||||||
* [`libcJSON`](https://github.com/DaveGamble/cJSON): Needed for Windows Terminal font ( WSL ).
|
* [`json-c`](https://github.com/json-c/json-c): Needed for Windows Terminal font ( WSL ).
|
||||||
* [`libnm`](https://networkmanager.dev/docs/libnm/latest/): Used for Wifi detection.
|
* [`libnm`](https://networkmanager.dev/docs/libnm/latest/): Used for Wifi detection.
|
||||||
* [`libpulse`](https://freedesktop.org/software/pulseaudio/doxygen/): Used for Sound detection.
|
* [`libpulse`](https://freedesktop.org/software/pulseaudio/doxygen/): Used for Sound detection.
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ For the image logo, iTerm with iterm image protocol should work. Apple Terminal
|
|||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
* [`wlanapi`](https://learn.microsoft.com/en-us/windows/win32/api/wlanapi/): A system dll which isn't supported by Windows Server by default. Used for Wifi info detection.
|
* [`wlanapi`](https://learn.microsoft.com/en-us/windows/win32/api/wlanapi/): A system dll which isn't supported by Windows Server by default. Used for Wifi info detection.
|
||||||
* [`libcJSON`](https://github.com/DaveGamble/cJSON): Used for Windows Terminal font detection. [`cjson`](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-cjson)
|
* [`json-c`](https://github.com/json-c/json-c): Used for Windows Terminal font detection. [`json-c`](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-json-c)
|
||||||
* [`libvulkan`](https://www.vulkan.org/): Vulkan module. Usually has been provided by GPU drivers. [`vulkan-loader`](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-vulkan-loader) [`vulkan-headers`](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-vulkan-headers)
|
* [`libvulkan`](https://www.vulkan.org/): Vulkan module. Usually has been provided by GPU drivers. [`vulkan-loader`](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-vulkan-loader) [`vulkan-headers`](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-vulkan-headers)
|
||||||
* [`libOpenCL`](https://www.khronos.org/opencl/): OpenCL module. [`opencl-icd`](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-opencl-icd)
|
* [`libOpenCL`](https://www.khronos.org/opencl/): OpenCL module. [`opencl-icd`](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-opencl-icd)
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ Currently GCC or clang is required (MSVC is not supported). MSYS2 with CLANG64 s
|
|||||||
1. Open `MSYS2 / CLANG64` (not `MSYS2 / MSYS`, which targets cygwin C runtime)
|
1. Open `MSYS2 / CLANG64` (not `MSYS2 / MSYS`, which targets cygwin C runtime)
|
||||||
1. Install dependencies
|
1. Install dependencies
|
||||||
```bash
|
```bash
|
||||||
pacman -Syu mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-pkgconf mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-cjson mingw-w64-clang-x86_64-vulkan-loader mingw-w64-clang-x86_64-opencl-icd
|
pacman -Syu mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-pkgconf mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-json-c mingw-w64-clang-x86_64-vulkan-loader mingw-w64-clang-x86_64-opencl-icd
|
||||||
```
|
```
|
||||||
|
|
||||||
Follow the building instructions of Linux next.
|
Follow the building instructions of Linux next.
|
||||||
|
@ -137,7 +137,7 @@ static void defaultConfig(FFinstance* instance)
|
|||||||
ffStrbufInitA(&instance->config.libGLX, 0);
|
ffStrbufInitA(&instance->config.libGLX, 0);
|
||||||
ffStrbufInitA(&instance->config.libOSMesa, 0);
|
ffStrbufInitA(&instance->config.libOSMesa, 0);
|
||||||
ffStrbufInitA(&instance->config.libOpenCL, 0);
|
ffStrbufInitA(&instance->config.libOpenCL, 0);
|
||||||
ffStrbufInitA(&instance->config.libcJSON, 0);
|
ffStrbufInitA(&instance->config.libJSONC, 0);
|
||||||
ffStrbufInitA(&instance->config.libfreetype, 0);
|
ffStrbufInitA(&instance->config.libfreetype, 0);
|
||||||
ffStrbufInit(&instance->config.libPulse);
|
ffStrbufInit(&instance->config.libPulse);
|
||||||
ffStrbufInit(&instance->config.libwlanapi);
|
ffStrbufInit(&instance->config.libwlanapi);
|
||||||
@ -400,7 +400,7 @@ static void destroyConfig(FFinstance* instance)
|
|||||||
ffStrbufDestroy(&instance->config.libGLX);
|
ffStrbufDestroy(&instance->config.libGLX);
|
||||||
ffStrbufDestroy(&instance->config.libOSMesa);
|
ffStrbufDestroy(&instance->config.libOSMesa);
|
||||||
ffStrbufDestroy(&instance->config.libOpenCL);
|
ffStrbufDestroy(&instance->config.libOpenCL);
|
||||||
ffStrbufDestroy(&instance->config.libcJSON);
|
ffStrbufDestroy(&instance->config.libJSONC);
|
||||||
ffStrbufDestroy(&instance->config.libfreetype);
|
ffStrbufDestroy(&instance->config.libfreetype);
|
||||||
ffStrbufDestroy(&instance->config.libPulse);
|
ffStrbufDestroy(&instance->config.libPulse);
|
||||||
ffStrbufDestroy(&instance->config.libwlanapi);
|
ffStrbufDestroy(&instance->config.libwlanapi);
|
||||||
@ -505,8 +505,8 @@ void ffListFeatures()
|
|||||||
#ifdef FF_HAVE_OPENCL
|
#ifdef FF_HAVE_OPENCL
|
||||||
"opencl\n"
|
"opencl\n"
|
||||||
#endif
|
#endif
|
||||||
#ifdef FF_HAVE_LIBCJSON
|
#ifdef FF_HAVE_LIBJSONC
|
||||||
"libcjson\n"
|
"json-c\n"
|
||||||
#endif
|
#endif
|
||||||
#ifdef FF_HAVE_FREETYPE
|
#ifdef FF_HAVE_FREETYPE
|
||||||
"freetype\n"
|
"freetype\n"
|
||||||
|
8336
src/common/yyjson.c
8336
src/common/yyjson.c
File diff suppressed because it is too large
Load Diff
6003
src/common/yyjson.h
6003
src/common/yyjson.h
File diff suppressed because it is too large
Load Diff
@ -428,7 +428,6 @@
|
|||||||
#--lib-glx /usr/lib/libGLX.so
|
#--lib-glx /usr/lib/libGLX.so
|
||||||
#--lib-osmesa /usr/lib/libOSMesa.so
|
#--lib-osmesa /usr/lib/libOSMesa.so
|
||||||
#--lib-opencl /usr/lib/libOpenCL.so
|
#--lib-opencl /usr/lib/libOpenCL.so
|
||||||
#--lib-cjson /usr/lib/libcjson.so
|
#--lib-jsonc /usr/lib/libjson-c.so
|
||||||
#--lib-cjson /usr/lib/libasound.so
|
|
||||||
#--lib-freetype /data/data/com.termux/files/usr/lib
|
#--lib-freetype /data/data/com.termux/files/usr/lib
|
||||||
#--lib-pulse /usr/lib/libpulse.so
|
#--lib-pulse /usr/lib/libpulse.so
|
||||||
|
@ -97,7 +97,7 @@ Library options: Set the path of a library to load
|
|||||||
--lib-glx <path>
|
--lib-glx <path>
|
||||||
--lib-osmesa <path>
|
--lib-osmesa <path>
|
||||||
--lib-opencl <path>
|
--lib-opencl <path>
|
||||||
--lib-cjson <path>
|
--lib-jsonc <path>
|
||||||
--lib-pulse <path>
|
--lib-pulse <path>
|
||||||
--lib-freetype <path>
|
--lib-freetype <path>
|
||||||
|
|
||||||
|
@ -67,90 +67,119 @@ FF_MAYBE_UNUSED static void detectTTY(FFTerminalFontResult* terminalFont)
|
|||||||
|
|
||||||
#if defined(_WIN32) || defined(__linux__)
|
#if defined(_WIN32) || defined(__linux__)
|
||||||
|
|
||||||
|
#ifdef FF_HAVE_JSONC
|
||||||
|
|
||||||
#include "common/library.h"
|
#include "common/library.h"
|
||||||
#include "common/processing.h"
|
#include "common/processing.h"
|
||||||
#include "common/yyjson.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <json-c/json.h>
|
||||||
|
|
||||||
static const char* detectWTProfile(yyjson_val* profile, FFstrbuf* name, double* size)
|
typedef struct JSONCData
|
||||||
{
|
{
|
||||||
if (!yyjson_is_obj(profile))
|
FF_LIBRARY_SYMBOL(json_tokener_parse)
|
||||||
return "yyjson_is_obj(profile) returns false";
|
FF_LIBRARY_SYMBOL(json_object_array_length)
|
||||||
|
FF_LIBRARY_SYMBOL(json_object_array_get_idx)
|
||||||
|
FF_LIBRARY_SYMBOL(json_object_is_type)
|
||||||
|
FF_LIBRARY_SYMBOL(json_object_get_double)
|
||||||
|
FF_LIBRARY_SYMBOL(json_object_get_string_len)
|
||||||
|
FF_LIBRARY_SYMBOL(json_object_get_string)
|
||||||
|
FF_LIBRARY_SYMBOL(json_object_object_get)
|
||||||
|
FF_LIBRARY_SYMBOL(json_object_put)
|
||||||
|
|
||||||
yyjson_val* font = yyjson_obj_get(profile, "font");
|
json_object* root;
|
||||||
if (!yyjson_is_obj(font))
|
} JSONCData;
|
||||||
return "yyjson_is_obj(font) returns false";
|
|
||||||
|
static const char* detectWTProfile(JSONCData* data, json_object* profile, FFstrbuf* name, double* size)
|
||||||
|
{
|
||||||
|
if (!data->ffjson_object_is_type(profile, json_type_object))
|
||||||
|
return "json_object_is_type(profile, json_type_object) returns false";
|
||||||
|
|
||||||
|
json_object* font = data->ffjson_object_object_get(profile, "font");
|
||||||
|
if (!data->ffjson_object_is_type(font, json_type_object))
|
||||||
|
return "json_object_is_type(font, json_type_object) returns false";
|
||||||
|
|
||||||
if (name->length == 0)
|
if (name->length == 0)
|
||||||
{
|
{
|
||||||
yyjson_val* pface = yyjson_obj_get(font, "face");
|
json_object* pface = data->ffjson_object_object_get(font, "face");
|
||||||
if(yyjson_is_str(pface))
|
if(data->ffjson_object_is_type(pface, json_type_string))
|
||||||
ffStrbufAppendS(name, unsafe_yyjson_get_str(pface));
|
ffStrbufAppendNS(name, (uint32_t) data->ffjson_object_get_string_len(pface), data->ffjson_object_get_string(pface));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*size < 0)
|
if (*size < 0)
|
||||||
{
|
{
|
||||||
yyjson_val* psize = yyjson_obj_get(font, "size");
|
json_object* psize = data->ffjson_object_object_get(font, "size");
|
||||||
if (yyjson_is_int(psize))
|
if (data->ffjson_object_is_type(psize, json_type_int) || data->ffjson_object_is_type(psize, json_type_double))
|
||||||
*size = (double) yyjson_get_sint(psize);
|
*size = data->ffjson_object_get_double(psize);
|
||||||
else if (yyjson_is_real(psize))
|
|
||||||
*size = yyjson_get_real(psize);
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wrapYyjsonDocFree(yyjson_doc** doc)
|
static inline void wrapJsoncFree(JSONCData* data)
|
||||||
{
|
{
|
||||||
assert(doc);
|
assert(data);
|
||||||
if (*doc)
|
if (data->root)
|
||||||
yyjson_doc_free(*doc);
|
data->ffjson_object_put(data->root);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* detectFromWTImpl(FFstrbuf* content, FFstrbuf* name, double* size)
|
static const char* detectFromWTImpl(const FFinstance* instance, FFstrbuf* content, FFstrbuf* name, double* size)
|
||||||
{
|
{
|
||||||
yyjson_doc* __attribute__((__cleanup__(wrapYyjsonDocFree))) doc =
|
FF_LIBRARY_LOAD(libjsonc, &instance->config.libJSONC, "dlopen libjson-c" FF_LIBRARY_EXTENSION" failed",
|
||||||
yyjson_read_opts(content->chars, content->length, YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS | YYJSON_READ_ALLOW_INF_AND_NAN, NULL, NULL);
|
#ifdef _WIN32
|
||||||
if (!doc)
|
"libjson-c-5" FF_LIBRARY_EXTENSION, -1
|
||||||
|
#else
|
||||||
|
"libjson-c" FF_LIBRARY_EXTENSION, 5
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
JSONCData __attribute__((__cleanup__(wrapJsoncFree))) data = {};
|
||||||
|
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_tokener_parse)
|
||||||
|
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_array_length)
|
||||||
|
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_array_get_idx)
|
||||||
|
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_is_type)
|
||||||
|
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_double)
|
||||||
|
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_string_len)
|
||||||
|
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_string)
|
||||||
|
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_object_get)
|
||||||
|
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_put)
|
||||||
|
|
||||||
|
data.root = data.ffjson_tokener_parse(content->chars);
|
||||||
|
if (!data.root)
|
||||||
return "Failed to parse WT JSON config file";
|
return "Failed to parse WT JSON config file";
|
||||||
|
|
||||||
yyjson_val* const root = yyjson_doc_get_root(doc);
|
json_object* profiles = data.ffjson_object_object_get(data.root, "profiles");
|
||||||
assert(root);
|
|
||||||
|
|
||||||
yyjson_val* profiles = yyjson_obj_get(root, "profiles");
|
|
||||||
if (!profiles)
|
if (!profiles)
|
||||||
return "yyjson_obj_get(root, \"profiles\") failed";
|
return "json_object_object_get(root, \"profiles\") failed";
|
||||||
|
|
||||||
FF_STRBUF_AUTO_DESTROY wtProfileId;
|
FF_STRBUF_AUTO_DESTROY wtProfileId;
|
||||||
ffStrbufInitS(&wtProfileId, getenv("WT_PROFILE_ID"));
|
ffStrbufInitS(&wtProfileId, getenv("WT_PROFILE_ID"));
|
||||||
ffStrbufTrim(&wtProfileId, '\'');
|
ffStrbufTrim(&wtProfileId, '\'');
|
||||||
if (wtProfileId.length > 0)
|
if (wtProfileId.length > 0)
|
||||||
{
|
{
|
||||||
yyjson_val* list = yyjson_obj_get(profiles, "list");
|
json_object* list = data.ffjson_object_object_get(profiles, "list");
|
||||||
if (yyjson_is_arr(list))
|
if (list && data.ffjson_object_is_type(list, json_type_array))
|
||||||
{
|
{
|
||||||
yyjson_val* profile;
|
for (size_t idx = 0, length = data.ffjson_object_array_length(list); idx < length; ++idx)
|
||||||
size_t idx, max;
|
|
||||||
yyjson_arr_foreach(list, idx, max, profile)
|
|
||||||
{
|
{
|
||||||
if(!yyjson_is_obj(profile))
|
json_object* profile = data.ffjson_object_array_get_idx(list, idx);
|
||||||
continue;
|
if (!data.ffjson_object_is_type(profile, json_type_object))
|
||||||
yyjson_val* guid = yyjson_obj_get(profile, "guid");
|
|
||||||
|
|
||||||
if(!yyjson_is_str(guid))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(ffStrbufCompS(&wtProfileId, unsafe_yyjson_get_str(guid)) == 0)
|
json_object* guid = data.ffjson_object_object_get(profile, "guid");
|
||||||
|
if (!data.ffjson_object_is_type(guid, json_type_string))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(ffStrbufEqualS(&wtProfileId, data.ffjson_object_get_string(guid)))
|
||||||
{
|
{
|
||||||
detectWTProfile(profile, name, size);
|
detectWTProfile(&data, profile, name, size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
yyjson_val* defaults = yyjson_obj_get(profiles, "defaults");
|
json_object* defaults = data.ffjson_object_object_get(profiles, "defaults");
|
||||||
if (defaults)
|
if (defaults)
|
||||||
detectWTProfile(defaults, name, size);
|
detectWTProfile(&data, defaults, name, size);
|
||||||
|
|
||||||
if(name->length == 0)
|
if(name->length == 0)
|
||||||
ffStrbufSetS(name, "Cascadia Mono");
|
ffStrbufSetS(name, "Cascadia Mono");
|
||||||
@ -165,7 +194,7 @@ static const char* detectFromWTImpl(FFstrbuf* content, FFstrbuf* name, double* s
|
|||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void detectFromWindowsTeriminal(const FFstrbuf* terminalExe, FFTerminalFontResult* terminalFont)
|
static void detectFromWindowsTeriminal(const FFinstance* instance, const FFstrbuf* terminalExe, FFTerminalFontResult* terminalFont)
|
||||||
{
|
{
|
||||||
//https://learn.microsoft.com/en-us/windows/terminal/install#settings-json-file
|
//https://learn.microsoft.com/en-us/windows/terminal/install#settings-json-file
|
||||||
FFstrbuf json;
|
FFstrbuf json;
|
||||||
@ -243,7 +272,7 @@ static void detectFromWindowsTeriminal(const FFstrbuf* terminalExe, FFTerminalFo
|
|||||||
FFstrbuf name;
|
FFstrbuf name;
|
||||||
ffStrbufInit(&name);
|
ffStrbufInit(&name);
|
||||||
double size = -1;
|
double size = -1;
|
||||||
error = detectFromWTImpl(&json, &name, &size);
|
error = detectFromWTImpl(instance, &json, &name, &size);
|
||||||
ffStrbufDestroy(&json);
|
ffStrbufDestroy(&json);
|
||||||
|
|
||||||
if(error)
|
if(error)
|
||||||
@ -258,6 +287,15 @@ static void detectFromWindowsTeriminal(const FFstrbuf* terminalExe, FFTerminalFo
|
|||||||
ffStrbufDestroy(&name);
|
ffStrbufDestroy(&name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else //FF_HAVE_JSONC
|
||||||
|
|
||||||
|
static void detectFromWindowsTeriminal(const FFinstance* instance, const FFstrbuf* terminalExe, FFTerminalFontResult* terminalFont)
|
||||||
|
{
|
||||||
|
FF_UNUSED(instance, terminalExe, terminalFont);
|
||||||
|
ffStrbufAppendS(&terminalFont->error, "Fastfetch was built without json-c support");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //FF_HAVE_JSONC
|
||||||
|
|
||||||
#endif //defined(_WIN32) || defined(__linux__)
|
#endif //defined(_WIN32) || defined(__linux__)
|
||||||
|
|
||||||
@ -371,7 +409,7 @@ static bool detectTerminalFontCommon(const FFinstance* instance, const FFTermina
|
|||||||
//Used by both Linux (WSL) and Windows
|
//Used by both Linux (WSL) and Windows
|
||||||
else if(ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "Windows Terminal") ||
|
else if(ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "Windows Terminal") ||
|
||||||
ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "WindowsTerminal.exe"))
|
ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "WindowsTerminal.exe"))
|
||||||
detectFromWindowsTeriminal(&terminalShell->terminalExe, terminalFont);
|
detectFromWindowsTeriminal(instance, &terminalShell->terminalExe, terminalFont);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -1226,8 +1226,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
|||||||
optionParseString(key, value, &instance->config.libOSMesa);
|
optionParseString(key, value, &instance->config.libOSMesa);
|
||||||
else if(strcasecmp(subkey, "-opencl") == 0)
|
else if(strcasecmp(subkey, "-opencl") == 0)
|
||||||
optionParseString(key, value, &instance->config.libOpenCL);
|
optionParseString(key, value, &instance->config.libOpenCL);
|
||||||
else if(strcasecmp(subkey, "-cjson") == 0)
|
else if(strcasecmp(subkey, "-jsonc") == 0)
|
||||||
optionParseString(key, value, &instance->config.libcJSON);
|
optionParseString(key, value, &instance->config.libJSONC);
|
||||||
else if(strcasecmp(subkey, "-wlanapi") == 0)
|
else if(strcasecmp(subkey, "-wlanapi") == 0)
|
||||||
optionParseString(key, value, &instance->config.libwlanapi);
|
optionParseString(key, value, &instance->config.libwlanapi);
|
||||||
else if(strcasecmp(key, "-pulse") == 0)
|
else if(strcasecmp(key, "-pulse") == 0)
|
||||||
|
@ -177,7 +177,7 @@ typedef struct FFconfig
|
|||||||
FFstrbuf libGLX;
|
FFstrbuf libGLX;
|
||||||
FFstrbuf libOSMesa;
|
FFstrbuf libOSMesa;
|
||||||
FFstrbuf libOpenCL;
|
FFstrbuf libOpenCL;
|
||||||
FFstrbuf libcJSON;
|
FFstrbuf libJSONC;
|
||||||
FFstrbuf libfreetype;
|
FFstrbuf libfreetype;
|
||||||
FFstrbuf libPulse;
|
FFstrbuf libPulse;
|
||||||
FFstrbuf libwlanapi;
|
FFstrbuf libwlanapi;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user