From 47160418aadfbe76e5328d04e01dd1cad81e86e8 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 15 Apr 2024 07:15:26 -0500 Subject: [PATCH] api: export InternalScreen as AllocatingScreen I'm not thrilled with the name but we'll go with it for now --- src/InternalScreen.zig | 17 +++++++++++++++++ src/main.zig | 1 + 2 files changed, 18 insertions(+) diff --git a/src/InternalScreen.zig b/src/InternalScreen.zig index 1a57dc0..6001306 100644 --- a/src/InternalScreen.zig +++ b/src/InternalScreen.zig @@ -95,3 +95,20 @@ pub fn writeCell( }; self.buf[i].style = cell.style; } + +pub fn readCell(self: *InternalScreen, 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 .{ + .char = .{ .grapheme = self.buf[i].char.items }, + .style = self.buf[i].style, + }; +} diff --git a/src/main.zig b/src/main.zig index e6c43ed..9644603 100644 --- a/src/main.zig +++ b/src/main.zig @@ -13,6 +13,7 @@ pub const Color = Cell.Color; pub const Image = @import("Image.zig"); pub const Mouse = @import("Mouse.zig"); pub const Screen = @import("Screen.zig"); +pub const AllocatingScreen = @import("InternalScreen.zig"); pub const Winsize = @import("Tty.zig").Winsize; pub const Window = @import("Window.zig");