From 30db9d105ab7370bf67938c048714fe2cc3c9c71 Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Mon, 17 Apr 2023 19:09:30 +0200 Subject: [PATCH] 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 --- build.zig | 9 +++++++++ 1 file changed, 9 insertions(+) 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,