From 2fab89f2cbe1182dffb76f5bb550f0937d69967e Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Fri, 1 Mar 2024 12:28:03 -0600 Subject: [PATCH] screen: allow reading of cells Signed-off-by: Tim Culverhouse --- src/Screen.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Screen.zig b/src/Screen.zig index 48ed02d..fe118f7 100644 --- a/src/Screen.zig +++ b/src/Screen.zig @@ -60,3 +60,17 @@ pub fn writeCell(self: *Screen, col: usize, row: usize, cell: Cell) void { assert(i < self.buf.len); self.buf[i] = cell; } + +pub fn readCell(self: *Screen, col: usize, row: usize) ?Cell { + if (self.width < col) { + // column out of bounds + return null; + } + if (self.height < row) { + // height out of bounds + return null; + } + const i = (row * self.width) + col; + assert(i < self.buf.len); + return self.buf[i]; +}