terminal2: add Pin.cells

This commit is contained in:
Mitchell Hashimoto
2024-03-07 21:31:16 -08:00
parent 0e62076f52
commit 312eb050f3
2 changed files with 16 additions and 0 deletions

View File

@ -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.

View File

@ -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");