ohmu
·
2026-10-15
1#include "common/printing.h"
2#include "common/jsonconfig.h"
3#include "common/strutil.h"
4#include "detection/cursor/cursor.h"
5#include "modules/cursor/cursor.h"
6
7bool ffPrintCursor(FFCursorOptions* options) {
8 bool success = false;
9 FFCursorResult result;
10 ffStrbufInit(&result.error);
11 ffStrbufInit(&result.theme);
12 ffStrbufInit(&result.size);
13
14 ffDetectCursor(&result);
15
16 if (result.error.length) {
17 ffPrintError(FF_MODULE_GET_DISPLAY_NAME(Cursor), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", result.error.chars);
18 } else {
19 ffStrbufRemoveIgnCaseEndS(&result.theme, "cursors");
20 ffStrbufRemoveIgnCaseEndS(&result.theme, "cursor");
21 ffStrbufTrimRight(&result.theme, '_');
22 ffStrbufTrimRight(&result.theme, '-');
23 if (result.theme.length == 0) {
24 ffStrbufAppendS(&result.theme, "default");
25 }
26
27 if (options->moduleArgs.outputFormat.length == 0) {
28 ffPrintLogoAndKey(FF_MODULE_GET_DISPLAY_NAME(Cursor), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
29 ffStrbufWriteTo(&result.theme, stdout);
30
31 if (result.size.length > 0 && !ffStrbufEqualS(&result.size, "0")) {
32 printf(" (%spx)", result.size.chars);
33 }
34
35 putchar('\n');
36 } else {
37 FF_PRINT_FORMAT_CHECKED(FF_MODULE_GET_DISPLAY_NAME(Cursor), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
38 FF_ARG(result.theme, "theme"),
39 FF_ARG(result.size, "size"),
40 }));
41 }
42
43 success = true;
44 }
45
46 ffStrbufDestroy(&result.error);
47 ffStrbufDestroy(&result.theme);
48 ffStrbufDestroy(&result.size);
49
50 return success;
51}
52
53void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module) {
54 yyjson_val *key, *val;
55 size_t idx, max;
56 yyjson_obj_foreach (module, idx, max, key, val) {
57 if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
58 continue;
59 }
60
61 ffPrintError(FF_MODULE_GET_DISPLAY_NAME(Cursor), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
62 }
63}
64
65[[gnu::cold]]
66void ffGenerateCursorJsonConfig(FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
67 ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
68}
69
70bool ffGenerateCursorJsonResult([[maybe_unused]] FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
71 bool success = false;
72 FFCursorResult result;
73 ffStrbufInit(&result.error);
74 ffStrbufInit(&result.theme);
75 ffStrbufInit(&result.size);
76
77 ffDetectCursor(&result);
78
79 if (result.error.length) {
80 yyjson_mut_obj_add_strbuf(doc, module, "error", &result.error);
81 } else {
82 yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
83 yyjson_mut_obj_add_strbuf(doc, obj, "theme", &result.theme);
84 yyjson_mut_obj_add_strbuf(doc, obj, "size", &result.size);
85 success = true;
86 }
87
88 ffStrbufDestroy(&result.error);
89 ffStrbufDestroy(&result.theme);
90 ffStrbufDestroy(&result.size);
91
92 return success;
93}
94
95void ffInitCursorOptions(FFCursorOptions* options) {
96 ffOptionInitModuleArg(&options->moduleArgs, "");
97}
98
99void ffDestroyCursorOptions(FFCursorOptions* options) {
100 ffOptionDestroyModuleArg(&options->moduleArgs);
101}
102
103FFModuleBaseInfo ffCursorModuleInfo = {
104 .name = "Cursor",
105 .description = "Print cursor style name",
106 .displayName = {
107 .en = "Cursor",
108 .ar = "المؤشر",
109 .cs = "Kurzor",
110 .de = "Mauszeiger",
111 .es = "Cursor",
112 .fi = "Kursori",
113 .fr = "Curseur",
114 .gl = "Cursor",
115 .he = "סמן",
116 .id = "Kursor",
117 .it = "Cursore",
118 .ja = "カーソル",
119 .ko = "커서",
120 .pl = "Kursor",
121 .pt = "Cursor",
122 .ru = "Курсор",
123 .tr = "İmleç",
124 .uk = "Курсор",
125 .vi = "Con trỏ",
126 .zh_CN = "光标",
127 .zh_TW = "游標",
128 },
129 .initOptions = (void*) ffInitCursorOptions,
130 .destroyOptions = (void*) ffDestroyCursorOptions,
131 .parseJsonObject = (void*) ffParseCursorJsonObject,
132 .printModule = (void*) ffPrintCursor,
133 .generateJsonResult = (void*) ffGenerateCursorJsonResult,
134 .generateJsonConfig = (void*) ffGenerateCursorJsonConfig,
135 .formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
136 { "Cursor theme", "theme" },
137 { "Cursor size", "size" },
138 })),
139 .defaultOrder = 27,
140};