From 54ea9c23864e1aa5a0314a9e05362528358ee881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 11 Jan 2023 13:58:59 +0800 Subject: [PATCH] TerminalFont: support WezTerm font detection --- CHANGELOG.md | 1 + src/detection/terminalfont/terminalfont.c | 30 +++++++++++++++++++ .../terminalshell/terminalshell_linux.c | 2 ++ 3 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4809204dc..5c49019b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Features: * Add `Battery` module support for FreeBSD * Add `--disk-show-unknown` option for Disk module * Detect terminal version when available +* Support `WezTerm` terminal font detection (requires [`wezterm` executable](https://wezfurlong.org/wezterm/cli/general.html) being available) Logos: * Raspbian (@IamNoRobot, #373) diff --git a/src/detection/terminalfont/terminalfont.c b/src/detection/terminalfont/terminalfont.c index 5716b720d..a4a049276 100644 --- a/src/detection/terminalfont/terminalfont.c +++ b/src/detection/terminalfont/terminalfont.c @@ -320,6 +320,34 @@ static bool detectKitty(const FFinstance* instance, FFTerminalFontResult* result return true; } +static bool detectWezterm(FF_UNUSED_PARAM const FFinstance* instance, FFTerminalFontResult* result) +{ + FF_STRBUF_AUTO_DESTROY fontName; + ffStrbufInit(&fontName); + + ffStrbufSetS(&result->error, ffProcessAppendStdOut(&fontName, (char* const[]){ + "wezterm", + "ls-fonts", + "--text", + "a", + NULL + })); + if(result->error.length) + return false; + + //LeftToRight + // 0 a \u{61} x_adv=7 cells=1 glyph=a,180 wezterm.font("JetBrains Mono", {weight="Regular", stretch="Normal", style="Normal"}) + // , BuiltIn + ffStrbufSubstrAfterFirstC(&fontName, '"'); + ffStrbufSubstrBeforeFirstC(&fontName, '"'); + + if(!fontName.length) + return false; + + ffFontInitCopy(&result->font, fontName.chars); + return true; +} + void ffDetectTerminalFontPlatform(const FFinstance* instance, const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont); static bool detectTerminalFontCommon(const FFinstance* instance, const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont) @@ -328,6 +356,8 @@ static bool detectTerminalFontCommon(const FFinstance* instance, const FFTermina detectAlacritty(instance, terminalFont); else if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "kitty") == 0) detectKitty(instance, terminalFont); + else if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "wezterm-gui") == 0) + detectWezterm(instance, terminalFont); else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalExe, "/dev/tty")) detectTTY(terminalFont); diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index fb3ad0a76..510897287 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -375,6 +375,8 @@ const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance) ffStrbufInitS(&result.terminalPrettyName, "Apple Terminal"); else if(ffStrbufEqualS(&result.terminalProcessName, "WarpTerminal")) ffStrbufInitS(&result.terminalPrettyName, "Warp"); + else if(ffStrbufEqualS(&result.terminalProcessName, "wezterm-gui")) + ffStrbufInitS(&result.terminalPrettyName, "WezTerm"); else if(strncmp(result.terminalExeName, result.terminalProcessName.chars, result.terminalProcessName.length) == 0) // if exeName starts with processName, print it. Otherwise print processName ffStrbufInitS(&result.terminalPrettyName, result.terminalExeName); else