mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Terminal: support JSON format
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user