@@ -36,6 +36,9 @@ void ffPrintSeparator(FFSeparatorOptions* options)
3636{
3737 ffLogoPrintLine ();
3838
39+ if (options -> outputColor .length && !instance .config .display .pipe )
40+ ffPrintColor (& options -> outputColor );
41+
3942 if (options -> length > 0 )
4043 {
4144 if (__builtin_expect (options -> string .length == 1 , 1 ))
@@ -47,68 +50,67 @@ void ffPrintSeparator(FFSeparatorOptions* options)
4750 fputs (options -> string .chars , stdout );
4851 }
4952 }
50- putchar ('\n' );
51- return ;
52- }
53-
54- setlocale (LC_CTYPE , "" );
55- mbstate_t state = {};
56- bool fqdn = instance .config .modules .title .fqdn ;
57- const FFPlatform * platform = & instance .state .platform ;
58-
59- FF_AUTO_FREE wchar_t * wstr = malloc ((max (
60- platform -> userName .length , options -> string .length ) + 1 ) * sizeof (* wstr ));
61-
62- uint32_t titleLength = 1 // @
63- + getWcsWidth (& platform -> userName , wstr , & state ) // user name
64- + (fqdn ? platform -> hostName .length : ffStrbufFirstIndexC (& platform -> hostName , '.' )); // host name
65-
66- if (options -> outputColor .length && !instance .config .display .pipe )
67- ffPrintColor (& options -> outputColor );
68- if (__builtin_expect (options -> string .length == 1 , 1 ))
69- {
70- ffPrintCharTimes (options -> string .chars [0 ], titleLength );
7153 }
7254 else
7355 {
74- uint32_t wcsLength = getWcsWidth (& options -> string , wstr , & state );
56+ setlocale (LC_CTYPE , "" );
57+ mbstate_t state = {};
58+ bool fqdn = instance .config .modules .title .fqdn ;
59+ const FFPlatform * platform = & instance .state .platform ;
60+
61+ FF_AUTO_FREE wchar_t * wstr = malloc ((max (
62+ platform -> userName .length , options -> string .length ) + 1 ) * sizeof (* wstr ));
7563
76- int remaining = (int ) titleLength ;
77- //Write the whole separator as often as it fits fully into titleLength
78- for (; remaining >= (int ) wcsLength ; remaining -= (int ) wcsLength )
79- ffStrbufWriteTo (& options -> string , stdout );
64+ uint32_t titleLength = 1 // @
65+ + getWcsWidth (& platform -> userName , wstr , & state ) // user name
66+ + (fqdn ? platform -> hostName .length : ffStrbufFirstIndexC (& platform -> hostName , '.' )); // host name
8067
81- if (remaining > 0 )
68+ if (__builtin_expect (options -> string .length == 1 , 1 ))
69+ {
70+ ffPrintCharTimes (options -> string .chars [0 ], titleLength );
71+ }
72+ else
8273 {
83- //Write as much of the separator as needed to fill titleLength
84- if (wcsLength != options -> string .length )
74+ uint32_t wcsLength = getWcsWidth (& options -> string , wstr , & state );
75+
76+ int remaining = (int ) titleLength ;
77+ //Write the whole separator as often as it fits fully into titleLength
78+ for (; remaining >= (int ) wcsLength ; remaining -= (int ) wcsLength )
79+ ffStrbufWriteTo (& options -> string , stdout );
80+
81+ if (remaining > 0 )
8582 {
86- // Unicode chars
87- for ( int i = 0 ; remaining > 0 ; ++ i )
83+ //Write as much of the separator as needed to fill titleLength
84+ if ( wcsLength != options -> string . length )
8885 {
89- #ifdef __linux__
90- // https://stackoverflow.com/questions/75126743/i-have-difficulties-with-putwchar-in-c#answer-75137784
91- char wch [16 ] = "" ;
92- uint32_t wchLength = (uint32_t ) wcrtomb (wch , wstr [i ], & state );
93- fwrite (wch , wchLength , 1 , stdout );
94- #else
95- putwchar (wstr [i ]);
96- #endif
97- int width = mk_wcwidth (wstr [i ]);
98- remaining -= width < 0 ? 0 : width ;
86+ // Unicode chars
87+ for (int i = 0 ; remaining > 0 ; ++ i )
88+ {
89+ #ifdef __linux__
90+ // https://stackoverflow.com/questions/75126743/i-have-difficulties-with-putwchar-in-c#answer-75137784
91+ char wch [16 ] = "" ;
92+ uint32_t wchLength = (uint32_t ) wcrtomb (wch , wstr [i ], & state );
93+ fwrite (wch , wchLength , 1 , stdout );
94+ #else
95+ putwchar (wstr [i ]);
96+ #endif
97+ int width = mk_wcwidth (wstr [i ]);
98+ remaining -= width < 0 ? 0 : width ;
99+ }
100+ }
101+ else
102+ {
103+ for (int i = 0 ; i < remaining ; i ++ )
104+ putchar (options -> string .chars [i ]);
99105 }
100- }
101- else
102- {
103- for (int i = 0 ; i < remaining ; i ++ )
104- putchar (options -> string .chars [i ]);
105106 }
106107 }
108+ setlocale (LC_CTYPE , "C" );
107109 }
110+
108111 if (options -> outputColor .length && !instance .config .display .pipe )
109112 fputs (FASTFETCH_TEXT_MODIFIER_RESET , stdout );
110113 putchar ('\n' );
111- setlocale (LC_CTYPE , "C" );
112114}
113115
114116bool ffParseSeparatorCommandOptions (FFSeparatorOptions * options , const char * key , const char * value )
0 commit comments