|
3 | 3 | #include "common/properties.h"
|
4 | 4 | #include "common/processing.h"
|
5 | 5 | #include "detection/terminalshell/terminalshell.h"
|
| 6 | +#include "util/debug.h" |
6 | 7 |
|
7 | 8 | static void detectAlacritty(FFTerminalFontResult* terminalFont)
|
8 | 9 | {
|
@@ -48,29 +49,82 @@ static void detectAlacritty(FFTerminalFontResult* terminalFont)
|
48 | 49 | ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars);
|
49 | 50 | }
|
50 | 51 |
|
| 52 | +static bool parseGhosttyConfig(FFstrbuf* path, FFstrbuf* fontName, FFstrbuf* fontNameFallback, FFstrbuf* fontSize) |
| 53 | +{ |
| 54 | + FF_DEBUG("parsing config: %s", path->chars); |
| 55 | + FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); |
| 56 | + if (!ffAppendFileBuffer(path->chars, &buffer)) { |
| 57 | + FF_DEBUG("cannot read config: %s", path->chars); |
| 58 | + return false; |
| 59 | + } |
| 60 | + |
| 61 | + char* line = NULL; |
| 62 | + size_t len = 0; |
| 63 | + while (ffStrbufGetline(&line, &len, &buffer)) |
| 64 | + { |
| 65 | + if (!fontName->length) |
| 66 | + { |
| 67 | + if (ffParsePropLine(line, "font-family =", fontName)) { |
| 68 | + FF_DEBUG("found font-family='%s' in %s", fontName->chars, path->chars); |
| 69 | + continue; |
| 70 | + } |
| 71 | + } |
| 72 | + else if (!fontNameFallback->length) |
| 73 | + { |
| 74 | + if (ffParsePropLine(line, "font-family =", fontNameFallback)) { |
| 75 | + FF_DEBUG("found fallback font-family='%s' in %s", fontNameFallback->chars, path->chars); |
| 76 | + continue; |
| 77 | + } |
| 78 | + } |
| 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 | + |
51 | 90 | static void detectGhostty(FFTerminalFontResult* terminalFont)
|
52 | 91 | {
|
| 92 | + FF_DEBUG("detectGhostty: start"); |
| 93 | + FF_STRBUF_AUTO_DESTROY configPath = ffStrbufCreate(); |
53 | 94 | FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
| 95 | + FF_STRBUF_AUTO_DESTROY fontNameFallback = ffStrbufCreate(); |
54 | 96 | FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate();
|
55 | 97 |
|
56 |
| - FFpropquery fontQueryToml[] = { |
57 |
| - {"font-family =", &fontName}, |
58 |
| - {"font-size =", &fontSize}, |
59 |
| - }; |
60 |
| - |
61 | 98 | #if __APPLE__
|
62 |
| - ffParsePropFileConfigValues("com.mitchellh.ghostty/config", 2, fontQueryToml); |
| 99 | + ffStrbufSet(&configPath, &instance.state.platform.homeDir); |
| 100 | + ffStrbufAppendS(&configPath, "Library/Application Support/com.mitchellh.ghostty/config"); |
| 101 | + parseGhosttyConfig(&configPath, &fontName, &fontNameFallback, &fontSize); |
63 | 102 | #endif
|
64 | 103 |
|
65 |
| - ffParsePropFileConfigValues("ghostty/config", 2, fontQueryToml); |
| 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 | + } |
66 | 110 |
|
67 |
| - if(fontName.length == 0) |
| 111 | + if(fontName.length == 0) { |
68 | 112 | ffStrbufAppendS(&fontName, "JetBrainsMono Nerd Font");
|
| 113 | + FF_DEBUG("using default family='%s'", fontName.chars); |
| 114 | + } |
69 | 115 |
|
70 |
| - if(fontSize.length == 0) |
| 116 | + if(fontSize.length == 0) { |
71 | 117 | ffStrbufAppendS(&fontSize, "13");
|
| 118 | + FF_DEBUG("using default size='%s'", fontSize.chars); |
| 119 | + } |
72 | 120 |
|
73 | 121 | ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars);
|
| 122 | + if(fontNameFallback.length > 0) { |
| 123 | + FF_DEBUG("applying fallback family='%s'", fontNameFallback.chars); |
| 124 | + ffFontInitValues(&terminalFont->fallback, fontNameFallback.chars, NULL); |
| 125 | + } |
| 126 | + FF_DEBUG("result family='%s' size='%s'%s", fontName.chars, fontSize.chars, fontNameFallback.length ? " (with fallback)" : ""); |
| 127 | + FF_DEBUG("detectGhostty: end"); |
74 | 128 | }
|
75 | 129 |
|
76 | 130 | FF_MAYBE_UNUSED static void detectTTY(FFTerminalFontResult* terminalFont)
|
|
0 commit comments