Skip to content

Commit 15517d2

Browse files
Update output.c
1 parent a71d165 commit 15517d2

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

code/logic/output.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,20 @@ void fossil_io_apply_position(const char *pos) {
141141
}
142142

143143
// 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+
}
151149

152-
// Variable to keep track of the current position in the buffer
153-
const char *current_pos = buffer;
150+
const char *current_pos = str;
154151
const char *start = NULL;
155152
const char *end = NULL;
156153

157-
// Iterate over the buffer and process color/attribute/position inside `{}` and format specifiers
158154
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+
162158
// Find the matching '}'
163159
end = strchr(start, '}');
164160
if (end) {
@@ -190,18 +186,23 @@ void fossil_io_print_with_attributes(const char *format, ...) {
190186
if (FOSSIL_IO_COLOR_ENABLE && color) {
191187
fossil_io_apply_color(color);
192188
}
193-
fossil_io_apply_attribute(attribute);
189+
if (attribute) {
190+
fossil_io_apply_attribute(attribute);
191+
}
194192
}
195193

196194
// Move past '}' and continue processing
197195
current_pos = end + 1;
196+
} else {
197+
// No matching '}', print the rest and break
198+
fputs(start, stdout);
199+
break;
198200
}
199201
}
200202

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);
205206
}
206207

207208
// Function to print a sanitized formatted string to a specific file stream with attributes

0 commit comments

Comments
 (0)