@@ -72,35 +72,32 @@ FF_MAYBE_UNUSED static void detectTTY(FFTerminalFontResult* terminalFont)
7272 ffStrbufAppendS (& terminalFont -> error , "Couldn't find Font in " FASTFETCH_TARGET_DIR_ETC "/vconsole.conf" );
7373}
7474
75- static bool queryKittyTerm (const char * query , FFstrbuf * res )
75+ FF_MAYBE_UNUSED static bool detectKitty (const FFstrbuf * exe , FFTerminalFontResult * result )
7676{
77+ FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate ();
78+ FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate ();
79+
80+ char fontHex [512 ] = "" , sizeHex [512 ] = "" ;
7781 // https://github.com/fastfetch-cli/fastfetch/discussions/1030#discussioncomment-9845233
78- char buffer [256 ] = "" ;
7982 if (ffGetTerminalResponse (
80- query , // kitty-query-font_family;kitty-query-font_size
81- "\eP1+r%*[^=]=%255[^\e]\e\\" , buffer ) == NULL )
83+ "\eP+q6b697474792d71756572792d666f6e745f66616d696c79;6b697474792d71756572792d666f6e745f73697a65\e\\" , // kitty-query-font_family;kitty-query-font_size
84+ 2 ,
85+ "\eP1+r%*[^=]=%64[^\e]\e\\\eP1+r%*[^=]=%64[^\e]\e\\" , fontHex , sizeHex ) == NULL && * fontHex && * sizeHex )
8286 {
8387 // decode hex string
84- for (const char * p = buffer ; p [0 ] && p [1 ]; p += 2 )
88+ for (const char * p = fontHex ; p [0 ] && p [1 ]; p += 2 )
89+ {
90+ unsigned value ;
91+ if (sscanf (p , "%2x" , & value ))
92+ ffStrbufAppendC (& fontName , (char ) value );
93+ }
94+ for (const char * p = sizeHex ; p [0 ] && p [1 ]; p += 2 )
8595 {
8696 unsigned value ;
87- if (sscanf (p , "%2x" , & value ) == 1 )
88- ffStrbufAppendC (res , (char ) value );
97+ if (sscanf (p , "%2x" , & value ))
98+ ffStrbufAppendC (& fontSize , (char ) value );
8999 }
90- return true;
91100 }
92- return false;
93- }
94-
95- FF_MAYBE_UNUSED static bool detectKitty (const FFstrbuf * exe , FFTerminalFontResult * result )
96- {
97- FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate ();
98- FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate ();
99-
100- // Kitty generates response independently even if we query font family and size in one query
101- // which may result in short read in `ffGetTerminalResponse`
102- if (queryKittyTerm ("\eP+q6b697474792d71756572792d666f6e745f66616d696c79\e\\" , & fontName )) // kitty-query-font_family
103- queryKittyTerm ("\eP+q6b697474792d71756572792d666f6e745f73697a65\e\\" , & fontSize ); // kitty-query-font_size
104101 else
105102 {
106103 FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate ();
0 commit comments