TerminalFont: support WezTerm font detection

This commit is contained in:
李通洲 2023-01-11 13:58:59 +08:00
parent ccdb5c54d0
commit 54ea9c2386
No known key found for this signature in database
GPG Key ID: 3570F9F0F4410388
3 changed files with 33 additions and 0 deletions

View File

@ -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)

View File

@ -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"})
// <built-in>, 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);

View File

@ -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