Created
January 11, 2024 22:31
-
-
Save guidoschmidt/09fdb6cd12aac7e99bce0bbc9871a833 to your computer and use it in GitHub Desktop.
Animate 2D text buffers right in the terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn printDefault(c: u8) void { | |
std.debug.print("{c}", .{ c }); | |
} | |
fn animate(buffer: *[]u8, rows: u32, cols: u32, comptime print_fn: fn(u8) void) void { | |
for(0..rows) |dy| { | |
for(0..cols) |dx| { | |
const idx = dy * cols + dx; | |
const pipe_tile = buffer.*[idx]; | |
std.debug.print("\x1B[{d};{d}H", .{ dy, dx }); | |
print_fn(pipe_tile); | |
} | |
} | |
std.time.sleep(1000 * 1000 * 16); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Allows animating text buffers as 2D maps right in the terminal. Use like this: