Cursor: add JSON format support

This commit is contained in:
李通洲
2023-08-31 10:38:11 +08:00
parent ac8741d57d
commit a4fababb71
2 changed files with 23 additions and 1 deletions
+22 -1
View File
@@ -52,7 +52,7 @@ void ffPrintCursor(FFCursorOptions* options)
void ffInitCursorOptions(FFCursorOptions* options)
{
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CURSOR_MODULE_NAME, ffParseCursorCommandOptions, ffParseCursorJsonObject, ffPrintCursor, NULL);
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CURSOR_MODULE_NAME, ffParseCursorCommandOptions, ffParseCursorJsonObject, ffPrintCursor, ffGenerateCursorJson);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -87,3 +87,24 @@ void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module)
ffPrintError(FF_CURSOR_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
void ffGenerateCursorJson(FF_MAYBE_UNUSED FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFCursorResult result;
ffStrbufInit(&result.error);
ffStrbufInit(&result.theme);
ffStrbufInit(&result.size);
ffDetectCursor(&result);
if (result.error.length)
{
yyjson_mut_obj_add_str(doc, module, "error", result.error.chars);
return;
}
yyjson_mut_val* obj = yyjson_mut_obj(doc);
yyjson_mut_obj_add_val(doc, module, "result", obj);
yyjson_mut_obj_add_strbuf(doc, obj, "theme", &result.theme);
yyjson_mut_obj_add_strbuf(doc, obj, "size", &result.size);
}
+1
View File
@@ -9,3 +9,4 @@ void ffInitCursorOptions(FFCursorOptions* options);
bool ffParseCursorCommandOptions(FFCursorOptions* options, const char* key, const char* value);
void ffDestroyCursorOptions(FFCursorOptions* options);
void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module);
void ffGenerateCursorJson(FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);