88
99static void detectAlacritty (FFTerminalFontResult * terminalFont )
1010{
11- FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate ();
11+ // Maybe using a toml parser to read the config file is better?
12+ // https://github.com/cktan/tomlc17
13+
14+ // Doc: https://alacritty.org/config-alacritty.html#s26
15+ FF_STRBUF_AUTO_DESTROY fontNormal = ffStrbufCreate ();
16+ FF_STRBUF_AUTO_DESTROY fontFamily = ffStrbufCreate ();
17+ FF_STRBUF_AUTO_DESTROY fontStyle = ffStrbufCreate ();
1218 FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate ();
1319
1420 do {
15- // Latest alacritty uses toml instead of yaml
1621 FFpropquery fontQueryToml [] = {
17- {"family =" , & fontName },
22+ {"normal =" , & fontNormal },
1823 {"size =" , & fontSize },
1924 };
2025
@@ -25,29 +30,39 @@ static void detectAlacritty(FFTerminalFontResult* terminalFont)
2530 break ;
2631 if (ffParsePropFileConfigValues (".alacritty.toml" , 2 , fontQueryToml ))
2732 break ;
28-
29- FFpropquery fontQueryYaml [] = {
30- {"family:" , & fontName },
31- {"size:" , & fontSize },
32- };
33-
34- if (ffParsePropFileConfigValues ("alacritty/alacritty.yml" , 2 , fontQueryYaml ))
35- break ;
36- if (ffParsePropFileConfigValues ("alacritty.yml" , 2 , fontQueryYaml ))
37- break ;
38- if (ffParsePropFileConfigValues (".alacritty.yml" , 2 , fontQueryYaml ))
39- break ;
4033 } while (false);
4134
42- //by default alacritty uses its own font called alacritty
43- if (fontName .length == 0 )
44- ffStrbufAppendS (& fontName , "alacritty" );
35+ if (fontNormal .length > 0 )
36+ {
37+ // { family = "Fira Code", style = "Medium" }
38+ ffStrbufTrimSpace (& fontNormal );
39+ ffStrbufTrimRight (& fontNormal , '}' );
40+ ffStrbufTrimLeft (& fontNormal , '{' );
41+ ffStrbufTrimSpace (& fontNormal );
42+
43+ // family = "Fira Code", style = "Medium"
44+ ffStrbufReplaceAllC (& fontNormal , ',' , '\n' ); // Assume no commas in font names
45+ ffParsePropLines (fontNormal .chars , "family =" , & fontFamily );
46+ ffParsePropLines (fontNormal .chars , "style =" , & fontStyle );
47+ }
48+
49+ if (fontFamily .length == 0 )
50+ {
51+ #if __APPLE__
52+ ffStrbufSetStatic (& fontFamily , "Menlo" );
53+ #elif _WIN32
54+ ffStrbufSetStatic (& fontFamily , "Consolas" );
55+ #else
56+ ffStrbufSetStatic (& fontFamily , "monospace" );
57+ #endif
58+ }
59+ if (fontStyle .length == 0 )
60+ ffStrbufSetStatic (& fontStyle , "Regular" );
4561
46- // the default font size is 11
4762 if (fontSize .length == 0 )
48- ffStrbufAppendS (& fontSize , "11" );
63+ ffStrbufSetStatic (& fontSize , "11.25 " );
4964
50- ffFontInitValues (& terminalFont -> font , fontName . chars , fontSize . chars );
65+ ffFontInitMoveValues (& terminalFont -> font , & fontFamily , & fontSize , & fontStyle );
5166}
5267
5368static void detectGhostty (const FFstrbuf * exe , FFTerminalFontResult * terminalFont )
0 commit comments