From 281af9c86fefc99ae11e2b9b52e84f8491f02082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 23 Oct 2023 22:20:28 +0800 Subject: [PATCH] Terminal (Linux): better support for tmux --- src/detection/terminalshell/terminalshell.h | 1 + .../terminalshell/terminalshell_linux.c | 17 +++++++++++++-- .../terminalshell/terminalshell_windows.c | 2 ++ src/modules/terminal/terminal.c | 21 ++++++++++++++----- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/detection/terminalshell/terminalshell.h b/src/detection/terminalshell/terminalshell.h index 41e31700f..5e9113d71 100644 --- a/src/detection/terminalshell/terminalshell.h +++ b/src/detection/terminalshell/terminalshell.h @@ -20,6 +20,7 @@ typedef struct FFTerminalShellResult const char* terminalExeName; //pointer to a char in terminalExe FFstrbuf terminalVersion; uint32_t terminalPid; + FFstrbuf terminalPlugins; } FFTerminalShellResult; const FFTerminalShellResult* ffDetectTerminalShell(); diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 810fe90bc..37ec1e87f 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -176,6 +176,18 @@ static void getTerminalShell(FFTerminalShellResult* result, pid_t pid) return; } + if (ffStrStartsWith(name, "tmux: ")) + { + if (result->terminalPlugins.length) + ffStrbufAppendS(&result->terminalPlugins, ", "); + ffStrbufAppendS(&result->terminalPlugins, "tmux "); + ffStrbufAppendS(&result->terminalPlugins, getenv("TERM_PROGRAM_VERSION")); + ffStrbufTrimRight(&result->terminalPlugins, ' '); + + getTerminalShell(result, ppid); + return; + } + #ifdef __APPLE__ // https://github.com/fastfetch-cli/fastfetch/discussions/501 if (ffStrEndsWith(name, " (figterm)")) @@ -236,8 +248,7 @@ static void getTerminalFromEnv(FFTerminalShellResult* result) //Termux if(!ffStrSet(term) && ( getenv("TERMUX_VERSION") != NULL || - getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL || - getenv("TMUX_TMPDIR") != NULL + getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL )) term = "com.termux"; #endif @@ -332,6 +343,8 @@ const FFTerminalShellResult* ffDetectTerminalShell() const uint32_t exePathLen = 260; #endif + ffStrbufInit(&result.terminalPlugins); + ffStrbufInit(&result.shellProcessName); ffStrbufInitA(&result.shellExe, exePathLen); result.shellExeName = result.shellExe.chars; diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index ebc062b33..ee0f287ba 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -366,6 +366,8 @@ const FFTerminalShellResult* ffDetectTerminalShell(void) } init = true; + ffStrbufInit(&result.terminalPlugins); + ffStrbufInit(&result.shellProcessName); ffStrbufInitA(&result.shellExe, 128); result.shellExeName = ""; diff --git a/src/modules/terminal/terminal.c b/src/modules/terminal/terminal.c index d157cec38..5f508263e 100644 --- a/src/modules/terminal/terminal.c +++ b/src/modules/terminal/terminal.c @@ -6,7 +6,7 @@ #include -#define FF_TERMINAL_NUM_FORMAT_ARGS 6 +#define FF_TERMINAL_NUM_FORMAT_ARGS 7 void ffPrintTerminal(FFTerminalOptions* options) { @@ -22,10 +22,18 @@ void ffPrintTerminal(FFTerminalOptions* options) { ffPrintLogoAndKey(FF_TERMINAL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + ffStrbufWriteTo(&result->terminalPrettyName, stdout); + if(result->terminalVersion.length) - printf("%s %s\n", result->terminalPrettyName.chars, result->terminalVersion.chars); - else - ffStrbufPutTo(&result->terminalPrettyName, stdout); + { + putchar(' '); + ffStrbufWriteTo(&result->terminalVersion, stdout); + } + + if(result->terminalPlugins.length) + printf(" (with %s)", result->terminalPlugins.chars); + + putchar('\n'); } else { @@ -36,6 +44,7 @@ void ffPrintTerminal(FFTerminalOptions* options) {FF_FORMAT_ARG_TYPE_UINT, &result->terminalPid}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalPrettyName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalVersion}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalPlugins}, }); } } @@ -84,6 +93,7 @@ void ffGenerateTerminalJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yy 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, "version", &result->terminalVersion); + yyjson_mut_obj_add_strbuf(doc, obj, "plugins", &result->terminalPlugins); } void ffPrintTerminalHelpFormat(void) @@ -94,7 +104,8 @@ void ffPrintTerminalHelpFormat(void) "Terminal exe name", "Terminal pid", "Terminal pretty name", - "Terminal version" + "Terminal version", + "Terminal plugins (e.g. tmux)" }); }