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
This commit is contained in:
Manlio Perillo 2023-04-17 19:09:30 +02:00
parent c6e055dd83
commit 30db9d105a

View file

@ -728,6 +728,7 @@ const ZiglingStep = struct {
const exe_file = try self.doCompile(prog_node); const exe_file = try self.doCompile(prog_node);
resetLine();
print("Checking {s}...\n", .{self.exercise.main_file}); print("Checking {s}...\n", .{self.exercise.main_file});
const cwd = self.builder.build_root.path.?; const cwd = self.builder.build_root.path.?;
@ -970,6 +971,8 @@ const ZiglingStep = struct {
} }
fn printErrors(self: *ZiglingStep) void { fn printErrors(self: *ZiglingStep) void {
resetLine();
// Print the additional log and verbose messages. // Print the additional log and verbose messages.
// TODO: use colors? // TODO: use colors?
if (self.result_messages.len > 0) print("{s}", .{self.result_messages}); 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. // Print a message to stderr.
const PrintStep = struct { const PrintStep = struct {
step: Step, step: Step,