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) {
|
2025-08-18 13:38:30 +08:00
|
|
|
bool success = false;
|
2023-03-20 14:57:46 +08:00
|
|
|
FFCursorResult result;
|
|
|
|
|
ffStrbufInit(&result.error);
|
|
|
|
|
ffStrbufInit(&result.theme);
|
|
|
|
|
ffStrbufInit(&result.size);
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
ffDetectCursor(&result);
|
2023-03-20 14:57:46 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (result.error.length) {
|
2024-03-07 11:10:18 +08:00
|
|
|
ffPrintError(FF_CURSOR_MODULE_NAME, 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) {
|
2023-08-15 21:40:22 +08:00
|
|
|
ffPrintLogoAndKey(FF_CURSOR_MODULE_NAME, 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 {
|
2024-12-11 10:47:02 +08:00
|
|
|
FF_PRINT_FORMAT_CHECKED(FF_CURSOR_MODULE_NAME, 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
|
|
|
}
|
2025-08-18 13:38:30 +08:00
|
|
|
|
|
|
|
|
success = true;
|
2023-03-20 14:57:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffStrbufDestroy(&result.error);
|
|
|
|
|
ffStrbufDestroy(&result.theme);
|
|
|
|
|
ffStrbufDestroy(&result.size);
|
2025-08-18 13:38:30 +08:00
|
|
|
|
|
|
|
|
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) {
|
2025-08-02 18:51:03 +08:00
|
|
|
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
|
|
|
|
2025-08-02 18:51:03 +08:00
|
|
|
ffPrintError(FF_CURSOR_MODULE_NAME, 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) {
|
2025-08-04 16:46:28 +08:00
|
|
|
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
|
2023-10-24 14:41:29 +08:00
|
|
|
}
|
|
|
|
|
|
2026-07-10 21:13:03 +08:00
|
|
|
bool ffGenerateCursorJsonResult([[maybe_unused]] FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
2025-08-18 13:38:30 +08:00
|
|
|
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) {
|
2023-12-01 15:54:46 +09:00
|
|
|
yyjson_mut_obj_add_strbuf(doc, module, "error", &result.error);
|
2026-03-29 09:28:49 +08:00
|
|
|
} else {
|
2023-12-01 15:54:46 +09:00
|
|
|
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);
|
2025-08-18 13:38:30 +08:00
|
|
|
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);
|
2025-08-18 13:38:30 +08:00
|
|
|
|
|
|
|
|
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) {
|
2025-08-04 14:25:14 +08:00
|
|
|
ffOptionInitModuleArg(&options->moduleArgs, "");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffDestroyCursorOptions(FFCursorOptions* options) {
|
2025-08-04 14:25:14 +08:00
|
|
|
ffOptionDestroyModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-03 22:50:56 +08:00
|
|
|
FFModuleBaseInfo ffCursorModuleInfo = {
|
2024-12-11 10:47:02 +08:00
|
|
|
.name = FF_CURSOR_MODULE_NAME,
|
|
|
|
|
.description = "Print cursor style name",
|
2026-08-14 20:38:58 +08:00
|
|
|
.displayName = {
|
|
|
|
|
.en = "Cursor",
|
|
|
|
|
.de = "Mauszeiger",
|
|
|
|
|
.es = "Cursor",
|
|
|
|
|
.fr = "Curseur",
|
|
|
|
|
.it = "Cursore",
|
|
|
|
|
.ja = "カーソル",
|
|
|
|
|
.ko = "커서",
|
|
|
|
|
.pl = "Kursor",
|
|
|
|
|
.pt_BR = "Cursor",
|
|
|
|
|
.ru = "Курсор",
|
|
|
|
|
.zh_CN = "光标",
|
|
|
|
|
.zh_TW = "游標",
|
|
|
|
|
},
|
2025-08-03 18:39:41 +08:00
|
|
|
.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
|
|
|
})),
|
2026-07-31 10:56:13 +08:00
|
|
|
.defaultOrder = 27,
|
2024-12-11 10:47:02 +08:00
|
|
|
};
|