Files
fastfetch/src/modules/cursor/cursor.c
T

139 lines
4.7 KiB
C
Raw Normal View History

2026-01-06 09:48:38 +08:00
#include "common/printing.h"
#include "common/jsonconfig.h"
2026-05-28 15:58:08 +08:00
#include "common/strutil.h"
2023-03-20 14:57:46 +08:00
#include "detection/cursor/cursor.h"
#include "modules/cursor/cursor.h"
2026-03-29 09:28:49 +08:00
bool ffPrintCursor(FFCursorOptions* options) {
bool success = false;
2023-03-20 14:57:46 +08:00
FFCursorResult result;
ffStrbufInit(&result.error);
ffStrbufInit(&result.theme);
ffStrbufInit(&result.size);
ffDetectCursor(&result);
2023-03-20 14:57:46 +08:00
2026-03-29 09:28:49 +08:00
if (result.error.length) {
2026-08-14 23:33:54 +08:00
ffPrintError(FF_MODULE_GET_DISPLAY_NAME(Cursor), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", result.error.chars);
2026-03-29 09:28:49 +08:00
} else {
2023-03-20 14:57:46 +08:00
ffStrbufRemoveIgnCaseEndS(&result.theme, "cursors");
ffStrbufRemoveIgnCaseEndS(&result.theme, "cursor");
ffStrbufTrimRight(&result.theme, '_');
ffStrbufTrimRight(&result.theme, '-');
2026-03-29 09:28:49 +08:00
if (result.theme.length == 0) {
2023-03-20 14:57:46 +08:00
ffStrbufAppendS(&result.theme, "default");
2026-03-29 09:28:49 +08:00
}
2023-03-20 14:57:46 +08:00
2026-03-29 09:28:49 +08:00
if (options->moduleArgs.outputFormat.length == 0) {
2026-08-14 23:33:54 +08:00
ffPrintLogoAndKey(FF_MODULE_GET_DISPLAY_NAME(Cursor), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
2023-03-20 14:57:46 +08:00
ffStrbufWriteTo(&result.theme, stdout);
2026-03-29 09:28:49 +08:00
if (result.size.length > 0 && !ffStrbufEqualS(&result.size, "0")) {
2023-03-20 14:57:46 +08:00
printf(" (%spx)", result.size.chars);
2026-03-29 09:28:49 +08:00
}
2023-03-20 14:57:46 +08:00
putchar('\n');
2026-03-29 09:28:49 +08:00
} else {
2026-08-14 23:33:54 +08:00
FF_PRINT_FORMAT_CHECKED(FF_MODULE_GET_DISPLAY_NAME(Cursor), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
2026-03-29 09:28:49 +08:00
FF_ARG(result.theme, "theme"),
FF_ARG(result.size, "size"),
}));
2023-03-20 14:57:46 +08:00
}
success = true;
2023-03-20 14:57:46 +08:00
}
ffStrbufDestroy(&result.error);
ffStrbufDestroy(&result.theme);
ffStrbufDestroy(&result.size);
return success;
2023-03-20 14:57:46 +08:00
}
2026-03-29 09:28:49 +08:00
void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module) {
yyjson_val *key, *val;
2023-08-17 16:09:41 +08:00
size_t idx, max;
2026-03-29 09:28:49 +08:00
yyjson_obj_foreach (module, idx, max, key, val) {
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
2023-08-17 16:09:41 +08:00
continue;
2026-03-29 09:28:49 +08:00
}
2023-03-20 14:57:46 +08:00
2026-08-14 23:33:54 +08:00
ffPrintError(FF_MODULE_GET_DISPLAY_NAME(Cursor), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
2023-03-20 14:57:46 +08:00
}
}
2023-08-31 10:38:11 +08:00
2026-03-29 09:28:49 +08:00
void ffGenerateCursorJsonConfig(FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
2023-10-24 14:41:29 +08:00
}
bool ffGenerateCursorJsonResult([[maybe_unused]] FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
bool success = false;
2023-08-31 10:38:11 +08:00
FFCursorResult result;
ffStrbufInit(&result.error);
ffStrbufInit(&result.theme);
ffStrbufInit(&result.size);
ffDetectCursor(&result);
2026-03-29 09:28:49 +08:00
if (result.error.length) {
yyjson_mut_obj_add_strbuf(doc, module, "error", &result.error);
2026-03-29 09:28:49 +08:00
} else {
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "theme", &result.theme);
yyjson_mut_obj_add_strbuf(doc, obj, "size", &result.size);
success = true;
2023-08-31 10:38:11 +08:00
}
2023-09-08 20:03:26 +08:00
ffStrbufDestroy(&result.error);
ffStrbufDestroy(&result.theme);
ffStrbufDestroy(&result.size);
return success;
2023-08-31 10:38:11 +08:00
}
2023-10-07 13:40:40 +08:00
2026-03-29 09:28:49 +08:00
void ffInitCursorOptions(FFCursorOptions* options) {
ffOptionInitModuleArg(&options->moduleArgs, "󰆿");
}
2026-03-29 09:28:49 +08:00
void ffDestroyCursorOptions(FFCursorOptions* options) {
ffOptionDestroyModuleArg(&options->moduleArgs);
}
2025-08-03 22:50:56 +08:00
FFModuleBaseInfo ffCursorModuleInfo = {
2026-08-14 23:33:54 +08:00
.name = "Cursor",
2024-12-11 10:47:02 +08:00
.description = "Print cursor style name",
2026-08-14 20:38:58 +08:00
.displayName = {
.en = "Cursor",
2026-08-16 10:51:42 +08:00
.ar = "المؤشر",
2026-08-21 10:19:06 +08:00
.cs = "Kurzor",
2026-08-14 20:38:58 +08:00
.de = "Mauszeiger",
.es = "Cursor",
.fr = "Curseur",
2026-08-20 16:25:32 +00:00
.gl = "Cursor",
2026-08-16 10:51:42 +08:00
.he = "סמן",
2026-08-21 10:19:06 +08:00
.id = "Kursor",
2026-08-14 20:38:58 +08:00
.it = "Cursore",
.ja = "カーソル",
.ko = "커서",
.pl = "Kursor",
2026-08-16 10:37:06 +08:00
.pt = "Cursor",
2026-08-14 20:38:58 +08:00
.ru = "Курсор",
2026-08-21 10:19:06 +08:00
.tr = "İmleç",
.uk = "Курсор",
.vi = "Con trỏ",
2026-08-14 20:38:58 +08:00
.zh_CN = "光标",
.zh_TW = "游標",
},
.initOptions = (void*) ffInitCursorOptions,
.destroyOptions = (void*) ffDestroyCursorOptions,
2024-12-11 10:47:02 +08:00
.parseJsonObject = (void*) ffParseCursorJsonObject,
.printModule = (void*) ffPrintCursor,
.generateJsonResult = (void*) ffGenerateCursorJsonResult,
.generateJsonConfig = (void*) ffGenerateCursorJsonConfig,
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
2026-03-30 10:27:23 +08:00
{ "Cursor theme", "theme" },
{ "Cursor size", "size" },
2024-12-11 10:47:02 +08:00
})),
.defaultOrder = 27,
2024-12-11 10:47:02 +08:00
};