This commit is contained in:
Martin Vrhovšek 2025-02-12 01:40:43 +01:00
parent 11bb024ed9
commit 12ce9744d1

View File

@ -7,9 +7,9 @@ const InteractionError = error{
pub fn userInteraction(allocator: std.mem.Allocator, tasks: *std.ArrayList([]const u8)) !void { pub fn userInteraction(allocator: std.mem.Allocator, tasks: *std.ArrayList([]const u8)) !void {
var failure: usize = 0; var failure: usize = 0;
try clearTerminal();
while (failure < 3) { while (failure < 3) {
try clearTerminal();
printItems(tasks) catch |err| { printItems(tasks) catch |err| {
std.debug.print("Failed to print the items:\n{}\n", .{err}); std.debug.print("Failed to print the items:\n{}\n", .{err});
failure += 1; failure += 1;
@ -21,9 +21,10 @@ pub fn userInteraction(allocator: std.mem.Allocator, tasks: *std.ArrayList([]con
continue; continue;
}; };
defer allocator.free(input); defer allocator.free(input);
// todo add option to manipulate tasks via numbers (and add numbers to tasks)
const Case = enum { add, edit, remove, quit }; const Case = enum { add, edit, remove, quit };
const case = std.meta.stringToEnum(Case, input) orelse return; const case = std.meta.stringToEnum(Case, input) orelse continue;
var task_name: []const u8 = undefined; var task_name: []const u8 = undefined;
@ -71,7 +72,6 @@ pub fn userInteraction(allocator: std.mem.Allocator, tasks: *std.ArrayList([]con
}, },
.quit => break, .quit => break,
} }
try clearTerminal();
} }
} }