Terminal: support JSON format

This commit is contained in:
李通洲
2023-09-12 09:49:36 +08:00
parent f13b771317
commit 9447f1ca80
3 changed files with 23 additions and 2 deletions
+2 -1
View File
@@ -92,9 +92,10 @@ void ffGenerateShellJson(FF_MAYBE_UNUSED FFShellOptions* options, yyjson_mut_doc
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "processName", &result->shellProcessName);
yyjson_mut_obj_add_strbuf(doc, obj, "exe", &result->shellExe);
yyjson_mut_obj_add_strcpy(doc, obj, "exeName", result->shellExeName);
yyjson_mut_obj_add_uint(doc, obj, "pid", result->shellPid);
yyjson_mut_obj_add_strbuf(doc, obj, "processName", &result->shellProcessName);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result->shellVersion);
yyjson_mut_obj_add_strbuf(doc, obj, "userShellExe", &result->userShellExe);
yyjson_mut_obj_add_strcpy(doc, obj, "userShellExeName", result->userShellExeName);
+20 -1
View File
@@ -46,7 +46,7 @@ void ffPrintTerminal(FFTerminalOptions* options)
void ffInitTerminalOptions(FFTerminalOptions* options)
{
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINAL_MODULE_NAME, ffParseTerminalCommandOptions, ffParseTerminalJsonObject, ffPrintTerminal, NULL);
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINAL_MODULE_NAME, ffParseTerminalCommandOptions, ffParseTerminalJsonObject, ffPrintTerminal, ffGenerateTerminalJson);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -81,3 +81,22 @@ void ffParseTerminalJsonObject(FFTerminalOptions* options, yyjson_val* module)
ffPrintError(FF_TERMINAL_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
void ffGenerateTerminalJson(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
const FFTerminalShellResult* result = ffDetectTerminalShell();
if(result->terminalProcessName.length == 0)
{
yyjson_mut_obj_add_str(doc, module, "error", "Couldn't detect terminal");
return;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "exe", &result->terminalExe);
yyjson_mut_obj_add_strcpy(doc, obj, "exeName", result->terminalExeName);
yyjson_mut_obj_add_uint(doc, obj, "pid", result->terminalPid);
yyjson_mut_obj_add_strbuf(doc, obj, "prettyName", &result->terminalPrettyName);
yyjson_mut_obj_add_strbuf(doc, obj, "processName", &result->terminalProcessName);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result->terminalVersion);
}
+1
View File
@@ -9,3 +9,4 @@ void ffInitTerminalOptions(FFTerminalOptions* options);
bool ffParseTerminalCommandOptions(FFTerminalOptions* options, const char* key, const char* value);
void ffDestroyTerminalOptions(FFTerminalOptions* options);
void ffParseTerminalJsonObject(FFTerminalOptions* options, yyjson_val* module);
void ffGenerateTerminalJson(FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);