aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
blob: 98f036972b5bc9007ab76b71f38fb75f5527ef9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const std = @import("std");
const IO = @import("frontend/ncurses.zig").IO;
const Action = @import("actions.zig").Action;

pub fn main() u8 {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    const allocator = gpa.allocator();
    var io = IO.init(allocator) catch |err| {
        std.log.err("{}", .{err});
        return 1;
    };
    defer io.deinit();

    try io.displayMessage("Initialized");

    var action = Action.illegal;
    var tick_count: usize = 0;
    while (action != Action.exit) {
        const str = std.fmt.allocPrint(allocator, "{}", .{tick_count}) catch {
            return 1;
        };
        defer allocator.free(str);
        try io.displayMessage(str);

        action = io.waitForTick() catch {
            return 1;
        };
        switch (action) {
            Action.tick => {
                const str2 = std.fmt.allocPrint(allocator, "{}", .{tick_count}) catch {
                    return 1;
                };
                defer allocator.free(str2);
                try io.displayMessage(str2);

                tick_count += 1;
            },
            else => {},
        }
    }

    return 0;
}