From 312eb050f3b645d2214eac276158bda290e60da8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 7 Mar 2024 21:31:16 -0800 Subject: [PATCH] terminal2: add Pin.cells --- src/terminal2/PageList.zig | 15 +++++++++++++++ src/terminal2/main.zig | 1 + 2 files changed, 16 insertions(+) diff --git a/src/terminal2/PageList.zig b/src/terminal2/PageList.zig index 83aa99c83..aae4c1c9e 100644 --- a/src/terminal2/PageList.zig +++ b/src/terminal2/PageList.zig @@ -2038,6 +2038,21 @@ pub const Pin = struct { return .{ .row = rac.row, .cell = rac.cell }; } + pub const CellSubset = enum { all, left, right }; + + /// Returns the cells for the row that this pin is on. The subset determines + /// what subset of the cells are returned. The "left/right" subsets are + /// inclusive of the x coordinate of the pin. + pub fn cells(self: Pin, subset: CellSubset) []pagepkg.Cell { + const rac = self.rowAndCell(); + const all = self.page.data.getCells(rac.row); + return switch (subset) { + .all => all, + .left => all[0 .. self.x + 1], + .right => all[self.x..], + }; + } + /// Iterators. These are the same as PageList iterator funcs but operate /// on pins rather than points. This is MUCH more efficient than calling /// pointFromPin and building up the iterator from points. diff --git a/src/terminal2/main.zig b/src/terminal2/main.zig index 1045fae7a..8945f4ea5 100644 --- a/src/terminal2/main.zig +++ b/src/terminal2/main.zig @@ -28,6 +28,7 @@ pub const MouseShape = @import("mouse_shape.zig").MouseShape; pub const Page = page.Page; pub const PageList = @import("PageList.zig"); pub const Parser = @import("Parser.zig"); +pub const Pin = PageList.Pin; pub const Screen = @import("Screen.zig"); pub const Selection = @import("Selection.zig"); pub const Terminal = @import("Terminal.zig");