aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/stdlib.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-27 16:49:38 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-27 16:49:38 -0400
commitbaf990e65c62f42e45fe25ac385db9536d3f1788 (patch)
tree7b89cecde1d6cd3b600b9295e0ad22a702cd1065 /src/stdlib/stdlib.c
parent1a8a8bc3e2ebd9c282db8131902f9bb5de8c03cb (diff)
Update stdlib to use `print` instead of `printf` in all cases. This
means bringing in fpconv to do float-to-string conversion and a few updates to integer and number methods for string formatting.
Diffstat (limited to 'src/stdlib/stdlib.c')
-rw-r--r--src/stdlib/stdlib.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c
index 7ee249ab..71257b8e 100644
--- a/src/stdlib/stdlib.c
+++ b/src/stdlib/stdlib.c
@@ -465,26 +465,33 @@ public void start_inspect(const char *filename, int64_t start, int64_t end)
file = load_file(filename);
if (file) {
- const char *spaces = " ";
- int64_t first_line_len = (int64_t)strcspn(file->text + start, "\r\n");
+ size_t first_line_len = strcspn(file->text + start, "\r\n");
const char *slash = strrchr(filename, '/');
const char *file_base = slash ? slash + 1 : filename;
int64_t line_num = get_line_number(file, file->text + start);
- fprintf(stdout, USE_COLOR ? "%.*s\x1b[33;1m>> \x1b[m%.*s %.*s\x1b[32;2m[%s:%ld]\x1b[m\n" : "%.*s>> %.*s %.*s[%s:%ld]\n",
- 3*_inspect_depth, spaces, first_line_len, file->text + start,
- MAX(0, 35-first_line_len-3*_inspect_depth), spaces, file_base, line_num);
+ if (USE_COLOR) {
+ print(repeated_char(' ', 3*_inspect_depth), "\x1b[33;1m>> \x1b[m",
+ string_slice(file->text + start, first_line_len),
+ " ", repeated_char(' ', MAX(0, 35-(int64_t)first_line_len-3*_inspect_depth)),
+ "\x1b[32;2m[", file_base, ":", line_num, "]\x1b[m");
+ } else {
+ print(repeated_char(' ', 3*_inspect_depth), ">> ",
+ string_slice(file->text + start, first_line_len),
+ " ", repeated_char(' ', MAX(0, 35-(int64_t)first_line_len-3*_inspect_depth)),
+ "[", file_base, ":", line_num, "]");
+ }
// For multi-line expressions, dedent each and print it on a new line with ".. " in front:
- if (end > start + first_line_len) {
+ if (end > start + (int64_t)first_line_len) {
const char *line_start = get_line(file, line_num);
int64_t indent_len = (int64_t)strspn(line_start, " \t");
for (const char *line = file->text + start + first_line_len; line < file->text + end; line += strcspn(line, "\r\n")) {
line += strspn(line, "\r\n");
if ((int64_t)strspn(line, " \t") >= indent_len)
line += indent_len;
- fprintf(stdout, USE_COLOR ? "%.*s\x1b[33m.. \x1b[m%.*s\n" : "%.*s.. %.*s\n",
- 3*_inspect_depth, spaces, strcspn(line, "\r\n"), line);
+ print(repeated_char(' ', 3*_inspect_depth), USE_COLOR ? "\x1b[33m.. " : ".. ",
+ string_slice(line, strcspn(line, "\r\n")));
}
}
}