properly clamp the timeout in conway

This commit is contained in:
Squibid 2025-12-23 23:40:29 -05:00
parent 24a230a027
commit 1d9cb6a1f9
Signed by: squibid
GPG key ID: BECE5684D3C4005D

View file

@ -145,6 +145,9 @@ pub fn play(width: u64, height: u64, writer: *std.Io.Writer) !void {
try con.writer.print("\x1B[{}A", .{height + 1});
try con.print();
// keep the timeouts reasonable
timeout = std.math.clamp(timeout, 1, 10000);
// keep the cursor in the game window to prevent the terminal from doing
// anything we can't/don't account for
cursor_x = std.math.clamp(cursor_x, 1, con.width);
@ -174,7 +177,7 @@ pub fn play(width: u64, height: u64, writer: *std.Io.Writer) !void {
for (buf) |c| switch (c) {
// we don't wanna worry about case when using +
'+', '=' => timeout += 50,
'-' => timeout = std.math.clamp(timeout - 50, 1, 1000),
'-' => timeout -= 50,
'n' => break :run, // next generation
'q' => {
running = false;