From 2e2cf644521b0a27654443c828489f7ebdfd4092 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 8 Aug 2024 14:58:56 +0800 Subject: [PATCH] Terminal (Linux): add kitty version detection fast path back --- src/detection/terminalshell/terminalshell.c | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index 9d65bde3a..4d0adf414 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -485,6 +485,33 @@ static bool getTerminalVersionZed(FFstrbuf* exe, FFstrbuf* version) #ifndef _WIN32 static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version) { + #if defined(__linux__) || defined(__FreeBSD__) + char buffer[1024] = {}; + if ( + #ifdef __linux__ + ffReadFileData(FASTFETCH_TARGET_DIR_USR "/lib64/kitty/kitty/constants.py", sizeof(buffer) - 1, buffer) || + ffReadFileData(FASTFETCH_TARGET_DIR_USR "/lib/kitty/kitty/constants.py", sizeof(buffer) - 1, buffer) + #else + ffReadFileData(_PATH_LOCALBASE "/share/kitty/kitty/constants.py", sizeof(buffer) - 1, buffer) + #endif + ) + { + // Starts from version 0.17.0 + // https://github.com/kovidgoyal/kitty/blob/master/kitty/constants.py#L25 + const char* p = memmem(buffer, sizeof(buffer) - 1, "version: Version = Version(", strlen("version: Version = Version(")); + if (p) + { + p += strlen("version: Version = Version("); + int major, minor, patch; + if (sscanf(p, "%d,%d,%d", &major, &minor, &patch) == 3) + { + ffStrbufSetF(version, "%d.%d.%d", major, minor, patch); + return true; + } + } + } + #endif + char versionHex[64]; // https://github.com/fastfetch-cli/fastfetch/discussions/1030#discussioncomment-9845233 if (ffGetTerminalResponse(