2023-03-20 14:57:46 +08:00
|
|
|
#include "common/printing.h"
|
2023-06-10 15:01:54 +08:00
|
|
|
#include "common/jsonconfig.h"
|
2023-03-20 14:57:46 +08:00
|
|
|
#include "detection/cursor/cursor.h"
|
|
|
|
|
#include "modules/cursor/cursor.h"
|
2023-06-19 15:21:49 +08:00
|
|
|
#include "util/stringUtils.h"
|
2023-03-20 14:57:46 +08:00
|
|
|
|
|
|
|
|
#define FF_CURSOR_NUM_FORMAT_ARGS 2
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
void ffPrintCursor(FFCursorOptions* options)
|
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
|
|
|
|
|
|
|
|
if(result.error.length)
|
2023-06-24 10:59:53 +08:00
|
|
|
ffPrintError(FF_CURSOR_MODULE_NAME, 0, &options->moduleArgs, "%s", result.error.chars);
|
2023-03-20 14:57:46 +08:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ffStrbufRemoveIgnCaseEndS(&result.theme, "cursors");
|
|
|
|
|
ffStrbufRemoveIgnCaseEndS(&result.theme, "cursor");
|
|
|
|
|
ffStrbufTrimRight(&result.theme, '_');
|
|
|
|
|
ffStrbufTrimRight(&result.theme, '-');
|
|
|
|
|
if(result.theme.length == 0)
|
|
|
|
|
ffStrbufAppendS(&result.theme, "default");
|
|
|
|
|
|
|
|
|
|
if(options->moduleArgs.outputFormat.length == 0)
|
|
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
ffPrintLogoAndKey(FF_CURSOR_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor);
|
2023-03-20 14:57:46 +08:00
|
|
|
ffStrbufWriteTo(&result.theme, stdout);
|
|
|
|
|
|
|
|
|
|
if(result.size.length > 0)
|
|
|
|
|
printf(" (%spx)", result.size.chars);
|
|
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
ffPrintFormat(FF_CURSOR_MODULE_NAME, 0, &options->moduleArgs, FF_CURSOR_NUM_FORMAT_ARGS, (FFformatarg[]){
|
2023-03-20 14:57:46 +08:00
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &result.theme},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &result.size}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffStrbufDestroy(&result.error);
|
|
|
|
|
ffStrbufDestroy(&result.theme);
|
|
|
|
|
ffStrbufDestroy(&result.size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffInitCursorOptions(FFCursorOptions* options)
|
|
|
|
|
{
|
|
|
|
|
options->moduleName = FF_CURSOR_MODULE_NAME;
|
|
|
|
|
ffOptionInitModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ffParseCursorCommandOptions(FFCursorOptions* options, const char* key, const char* value)
|
|
|
|
|
{
|
|
|
|
|
const char* subKey = ffOptionTestPrefix(key, FF_CURSOR_MODULE_NAME);
|
|
|
|
|
if (!subKey) return false;
|
|
|
|
|
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffDestroyCursorOptions(FFCursorOptions* options)
|
|
|
|
|
{
|
|
|
|
|
ffOptionDestroyModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
void ffParseCursorJsonObject(yyjson_val* module)
|
2023-03-20 14:57:46 +08:00
|
|
|
{
|
|
|
|
|
FFCursorOptions __attribute__((__cleanup__(ffDestroyCursorOptions))) options;
|
|
|
|
|
ffInitCursorOptions(&options);
|
|
|
|
|
|
|
|
|
|
if (module)
|
|
|
|
|
{
|
2023-06-10 15:01:54 +08:00
|
|
|
yyjson_val *key_, *val;
|
|
|
|
|
size_t idx, max;
|
|
|
|
|
yyjson_obj_foreach(module, idx, max, key_, val)
|
2023-03-20 14:57:46 +08:00
|
|
|
{
|
2023-06-10 15:01:54 +08:00
|
|
|
const char* key = yyjson_get_str(key_);
|
2023-06-19 15:21:49 +08:00
|
|
|
if(ffStrEqualsIgnCase(key, "type"))
|
2023-06-10 15:01:54 +08:00
|
|
|
continue;
|
|
|
|
|
|
2023-03-20 14:57:46 +08:00
|
|
|
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
|
|
|
|
continue;
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
ffPrintError(FF_CURSOR_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
2023-03-20 14:57:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
ffPrintCursor(&options);
|
2023-03-20 14:57:46 +08:00
|
|
|
}
|