88#include "detection/displayserver/displayserver.h"
99#include "util/mallocHelper.h"
1010#include "util/stringUtils.h"
11+ #include "util/linux/elf.h"
1112
1213static const char * getSystemMonospaceFont (void )
1314{
@@ -286,6 +287,13 @@ static void detectXterm(FFTerminalFontResult* terminalFont)
286287 ffFontInitValues (& terminalFont -> font , fontName .chars , fontSize .chars );
287288}
288289
290+ static bool elfExtractStringsCallBack (const char * str , uint32_t len , void * userData )
291+ {
292+ if (!ffStrContains (str , "size=" )) return true;
293+ ffStrbufSetNS ((FFstrbuf * ) userData , len , str );
294+ return false;
295+ }
296+
289297static void detectSt (FFTerminalFontResult * terminalFont , const FFTerminalResult * terminal )
290298{
291299 FF_STRBUF_AUTO_DESTROY size = ffStrbufCreateF ("/proc/%u/cmdline" , terminal -> pid );
@@ -306,30 +314,13 @@ static void detectSt(FFTerminalFontResult* terminalFont, const FFTerminalResult*
306314 else
307315 {
308316 ffStrbufClear (& font );
309- if (ffProcessAppendStdOut (& font , (char * const []) {
310- "strings" ,
311- terminal -> exePath .chars ,
312- NULL ,
313- }) != NULL || font .length == 0 )
314- {
315- ffStrbufAppendS (& terminalFont -> error , "Failed to run `strings st`" );
316- return ;
317- }
318317
319- // Search font config string in st binary
320- uint32_t middleIndex = ffStrbufFirstIndexS (& font , "size=" );
321- if (middleIndex == font .length )
318+ ffElfExtractStrings (terminal -> exePath .chars , elfExtractStringsCallBack , & font );
319+ if (font .length == 0 )
322320 {
323321 ffStrbufAppendS (& terminalFont -> error , "No font config found in st binary" );
324322 return ;
325323 }
326-
327- uint32_t startIndex = ffStrbufPreviousIndexC (& font , middleIndex , '\n' );
328- if (startIndex == font .length ) startIndex = 0 ;
329- uint32_t endIndex = ffStrbufNextIndexC (& font , middleIndex , '\n' );
330-
331- ffStrbufSubstrBefore (& font , endIndex );
332- ffStrbufSubstrAfter (& font , startIndex );
333324 }
334325
335326 // JetBrainsMono Nerd Font Mono:pixelsize=12:antialias=true:autohint=true
0 commit comments