Skip to content

Commit e2af8fc

Browse files
refactor(cli): update progress bar component
- fix memory usage and leaks - reduced code
1 parent 9e3248b commit e2af8fc

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/cli/cli.zig

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,30 +151,31 @@ fn compileCurrentExercise(self: *CLI) !void {
151151
}
152152

153153
fn progressBar(self: *CLI) !void {
154-
var completed_exercises_status: STD.ArrayList(u8) = .empty;
155-
var incomplete_exercises_status: STD.ArrayList(u8) = .empty;
154+
var ascii_bar: STD.ArrayList(u8) = .empty;
156155

157156
for (self.completed_exercises.items) |exercise| {
158157
_ = exercise;
159-
try completed_exercises_status.append(self.allocator, '#');
158+
159+
try ascii_bar.append(self.allocator, '#');
160160
}
161161

162+
try ascii_bar.append(self.allocator, '>');
163+
162164
for (self.list_of_exercises.items[self.completed_exercises.items.len..]) |exercise| {
163165
_ = exercise;
164-
try incomplete_exercises_status.append(self.allocator, '-');
166+
167+
try ascii_bar.append(self.allocator, '-');
165168
}
166169

167-
STD.debug.print("\nProgress: [{s}>{s}] {d}/{d}\n", .{ completed_exercises_status.items, incomplete_exercises_status.items, self.current_exercise_index + 1, self.list_of_exercises.items.len });
170+
STD.debug.print("\nProgress: [{s}] {d}/{d}\n", .{ ascii_bar.items, self.current_exercise_index + 1, self.list_of_exercises.items.len });
168171

169-
incomplete_exercises_status.clearAndFree(self.allocator);
170-
completed_exercises_status.clearAndFree(self.allocator);
172+
ascii_bar.clearAndFree(self.allocator);
171173
}
172174

173175
fn draw(self: *CLI) !void {
174176
STD.debug.print("{s}\n", .{ASCII_ART});
175177

176178
STD.debug.print("{s}", .{self.current_exercise_stdout.items});
177-
178179
if (!(self.did_current_exercise_compile)) {
179180
STD.debug.print("\n{s}", .{self.current_exercise_stderr.items});
180181
}

0 commit comments

Comments
 (0)