|
4 | 4 | #include "common/processing.h" |
5 | 5 | #include "detection/terminalshell/terminalshell.h" |
6 | 6 | #include "util/debug.h" |
| 7 | +#include "util/stringUtils.h" |
7 | 8 |
|
8 | 9 | static void detectAlacritty(FFTerminalFontResult* terminalFont) |
9 | 10 | { |
@@ -49,77 +50,67 @@ static void detectAlacritty(FFTerminalFontResult* terminalFont) |
49 | 50 | ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars); |
50 | 51 | } |
51 | 52 |
|
52 | | -static bool parseGhosttyConfig(FFstrbuf* path, FFstrbuf* fontName, FFstrbuf* fontNameFallback, FFstrbuf* fontSize) |
| 53 | +static void detectGhostty(const FFstrbuf* exe, FFTerminalFontResult* terminalFont) |
53 | 54 | { |
54 | | - FF_DEBUG("parsing config: %s", path->chars); |
| 55 | + FF_DEBUG("detectGhostty: start"); |
| 56 | + FF_STRBUF_AUTO_DESTROY configPath = ffStrbufCreate(); |
| 57 | + FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate(); |
| 58 | + FF_STRBUF_AUTO_DESTROY fontNameFallback = ffStrbufCreate(); |
| 59 | + FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate(); |
| 60 | + |
| 61 | + // Try ghostty +show-config first |
55 | 62 | FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); |
56 | | - if (!ffAppendFileBuffer(path->chars, &buffer)) { |
57 | | - FF_DEBUG("cannot read config: %s", path->chars); |
58 | | - return false; |
| 63 | + const char* error = ffProcessAppendStdOut(&buffer, (char* const[]){ |
| 64 | + exe->chars, |
| 65 | + "+show-config", |
| 66 | + NULL, |
| 67 | + }); |
| 68 | + if(error != NULL) |
| 69 | + { |
| 70 | + FF_DEBUG("`ghostty +show-config` failed: %s", error); |
| 71 | + return; |
59 | 72 | } |
60 | 73 |
|
61 | 74 | char* line = NULL; |
62 | 75 | size_t len = 0; |
63 | 76 | while (ffStrbufGetline(&line, &len, &buffer)) |
64 | 77 | { |
65 | | - if (!fontName->length) |
| 78 | + if (!fontName.length || !fontNameFallback.length) |
66 | 79 | { |
67 | | - if (ffParsePropLine(line, "font-family =", fontName)) { |
68 | | - FF_DEBUG("found font-family='%s' in %s", fontName->chars, path->chars); |
| 80 | + if (ffStrStartsWith(line, "font-family = ")) { |
| 81 | + FF_DEBUG("found %s", line); |
| 82 | + ffStrbufSetNS( |
| 83 | + !fontName.length ? &fontName : &fontNameFallback, |
| 84 | + (uint32_t) (len - strlen("font-family = ")), |
| 85 | + line + strlen("font-family = ")); |
69 | 86 | continue; |
70 | 87 | } |
71 | 88 | } |
72 | | - else if (!fontNameFallback->length) |
| 89 | + if (!fontSize.length) |
73 | 90 | { |
74 | | - if (ffParsePropLine(line, "font-family =", fontNameFallback)) { |
75 | | - FF_DEBUG("found fallback font-family='%s' in %s", fontNameFallback->chars, path->chars); |
| 91 | + if (ffStrStartsWith(line, "font-size = ")) { |
| 92 | + FF_DEBUG("found fallback %s", line); |
| 93 | + ffStrbufSetNS( |
| 94 | + &fontSize, |
| 95 | + (uint32_t) (len - strlen("font-size = ")), |
| 96 | + line + strlen("font-size = ")); |
76 | 97 | continue; |
77 | 98 | } |
78 | 99 | } |
79 | | - if (!fontSize->length) |
80 | | - { |
81 | | - if (ffParsePropLine(line, "font-size =", fontSize)) { |
82 | | - FF_DEBUG("found font-size='%s' in %s", fontSize->chars, path->chars); |
83 | | - continue; |
84 | | - } |
85 | | - } |
86 | | - } |
87 | | - return true; |
88 | | -} |
89 | | - |
90 | | -static void detectGhostty(FFTerminalFontResult* terminalFont) |
91 | | -{ |
92 | | - FF_DEBUG("detectGhostty: start"); |
93 | | - FF_STRBUF_AUTO_DESTROY configPath = ffStrbufCreate(); |
94 | | - FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate(); |
95 | | - FF_STRBUF_AUTO_DESTROY fontNameFallback = ffStrbufCreate(); |
96 | | - FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate(); |
97 | | - |
98 | | - #if __APPLE__ |
99 | | - ffStrbufSet(&configPath, &instance.state.platform.homeDir); |
100 | | - ffStrbufAppendS(&configPath, "Library/Application Support/com.mitchellh.ghostty/config"); |
101 | | - parseGhosttyConfig(&configPath, &fontName, &fontNameFallback, &fontSize); |
102 | | - #endif |
103 | | - |
104 | | - if (instance.state.platform.configDirs.length > 0) |
105 | | - { |
106 | | - ffStrbufSet(&configPath, FF_LIST_GET(FFstrbuf, instance.state.platform.configDirs, 0)); |
107 | | - ffStrbufAppendS(&configPath, "ghostty/config"); |
108 | | - parseGhosttyConfig(&configPath, &fontName, &fontNameFallback, &fontSize); |
109 | 100 | } |
110 | 101 |
|
111 | | - if(fontName.length == 0) { |
| 102 | + if (fontName.length == 0) { |
112 | 103 | ffStrbufAppendS(&fontName, "JetBrainsMono Nerd Font"); |
113 | 104 | FF_DEBUG("using default family='%s'", fontName.chars); |
114 | 105 | } |
115 | 106 |
|
116 | | - if(fontSize.length == 0) { |
| 107 | + if (fontSize.length == 0) { |
117 | 108 | ffStrbufAppendS(&fontSize, "13"); |
118 | 109 | FF_DEBUG("using default size='%s'", fontSize.chars); |
119 | 110 | } |
120 | 111 |
|
121 | 112 | ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars); |
122 | | - if(fontNameFallback.length > 0) { |
| 113 | + if (fontNameFallback.length > 0) { |
123 | 114 | FF_DEBUG("applying fallback family='%s'", fontNameFallback.chars); |
124 | 115 | ffFontInitValues(&terminalFont->fallback, fontNameFallback.chars, NULL); |
125 | 116 | } |
@@ -333,7 +324,7 @@ static bool detectTerminalFontCommon(const FFTerminalResult* terminal, FFTermina |
333 | 324 | else if(ffStrbufStartsWithIgnCaseS(&terminal->processName, "contour")) |
334 | 325 | detectContour(&terminal->exe, terminalFont); |
335 | 326 | else if(ffStrbufStartsWithIgnCaseS(&terminal->processName, "ghostty")) |
336 | | - detectGhostty(terminalFont); |
| 327 | + detectGhostty(&terminal->exe, terminalFont); |
337 | 328 | else if(ffStrbufStartsWithIgnCaseS(&terminal->processName, "rio")) |
338 | 329 | detectRio(terminalFont); |
339 | 330 |
|
|
0 commit comments