@@ -141,24 +141,20 @@ void fossil_io_apply_position(const char *pos) {
141
141
}
142
142
143
143
// Function to print text with attributes, colors, positions, and format specifiers
144
- void fossil_io_print_with_attributes (const char * format , ...) {
145
- va_list args ;
146
- va_start (args , format );
147
-
148
- // Create a buffer to hold the formatted string
149
- char buffer [FOSSIL_IO_BUFFER_SIZE ];
150
- vsnprintf (buffer , sizeof (buffer ), format , args );
144
+ void fossil_io_print_with_attributes (const char * str ) {
145
+ if (str == NULL ) {
146
+ fputs ("cnullptr\n" , stderr );
147
+ return ;
148
+ }
151
149
152
- // Variable to keep track of the current position in the buffer
153
- const char * current_pos = buffer ;
150
+ const char * current_pos = str ;
154
151
const char * start = NULL ;
155
152
const char * end = NULL ;
156
153
157
- // Iterate over the buffer and process color/attribute/position inside `{}` and format specifiers
158
154
while ((start = strchr (current_pos , '{' )) != NULL ) {
159
- // Print text before '{'
160
- printf ( "%.*s" , ( int )( start - current_pos ), current_pos );
161
-
155
+ // Output text before '{'
156
+ fwrite ( current_pos , 1 , start - current_pos , stdout );
157
+
162
158
// Find the matching '}'
163
159
end = strchr (start , '}' );
164
160
if (end ) {
@@ -190,18 +186,23 @@ void fossil_io_print_with_attributes(const char *format, ...) {
190
186
if (FOSSIL_IO_COLOR_ENABLE && color ) {
191
187
fossil_io_apply_color (color );
192
188
}
193
- fossil_io_apply_attribute (attribute );
189
+ if (attribute ) {
190
+ fossil_io_apply_attribute (attribute );
191
+ }
194
192
}
195
193
196
194
// Move past '}' and continue processing
197
195
current_pos = end + 1 ;
196
+ } else {
197
+ // No matching '}', print the rest and break
198
+ fputs (start , stdout );
199
+ break ;
198
200
}
199
201
}
200
202
201
- // Print remaining text after last '}'
202
- printf ("%s" , current_pos );
203
-
204
- va_end (args );
203
+ // Output remaining text after last '}'
204
+ fputs (current_pos , stdout );
205
+ fflush (stdout );
205
206
}
206
207
207
208
// Function to print a sanitized formatted string to a specific file stream with attributes
0 commit comments