summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorManlio Perillo <manlio.perillo@gmail.com>2023-04-17 19:09:30 +0200
committerManlio Perillo <manlio.perillo@gmail.com>2023-04-18 14:43:17 +0200
commit30db9d105ab7370bf67938c048714fe2cc3c9c71 (patch)
tree65b27ec31bc6bf8ce8c417f1b84692e3313ea99f
parentc6e055dd8340981b4eedec5b6a41b944caf9c722 (diff)
build: avoid intermixed messages on the same line
In same cases, the progress messages from the compiler are intermixed with the messages printed by ZiglingStep. This intermixing appears in two cases: - when printing, e.g., the message "Checking 0_arrays2.zig..." - when printing the compiler errors Closes #230
-rw-r--r--build.zig9
1 files changed, 9 insertions, 0 deletions
diff --git a/build.zig b/build.zig
index e906ee4..226d38c 100644
--- a/build.zig
+++ b/build.zig
@@ -728,6 +728,7 @@ const ZiglingStep = struct {
const exe_file = try self.doCompile(prog_node);
+ resetLine();
print("Checking {s}...\n", .{self.exercise.main_file});
const cwd = self.builder.build_root.path.?;
@@ -970,6 +971,8 @@ const ZiglingStep = struct {
}
fn printErrors(self: *ZiglingStep) void {
+ resetLine();
+
// Print the additional log and verbose messages.
// TODO: use colors?
if (self.result_messages.len > 0) print("{s}", .{self.result_messages});
@@ -986,6 +989,12 @@ const ZiglingStep = struct {
}
};
+// Clear the entire line and move the cursor to column zero.
+// Used for clearing the compiler and build_runner progress messages.
+fn resetLine() void {
+ if (use_color_escapes) print("{s}", .{"\x1b[2K\r"});
+}
+
// Print a message to stderr.
const PrintStep = struct {
step: Step,