feat: add col_offset to Window.print
this commit adds convenience to `Window.print` by allowing it to start printing at a nonzero column.
This commit is contained in:
parent
6e85cd1fca
commit
b2151349ad
1 changed files with 5 additions and 3 deletions
|
@ -256,6 +256,8 @@ pub fn setCursorShape(self: Window, shape: Cell.CursorShape) void {
|
||||||
pub const PrintOptions = struct {
|
pub const PrintOptions = struct {
|
||||||
/// vertical offset to start printing at
|
/// vertical offset to start printing at
|
||||||
row_offset: usize = 0,
|
row_offset: usize = 0,
|
||||||
|
/// horizontal offset to start printing at
|
||||||
|
col_offset: usize = 0,
|
||||||
|
|
||||||
/// wrap behavior for printing
|
/// wrap behavior for printing
|
||||||
wrap: enum {
|
wrap: enum {
|
||||||
|
@ -285,7 +287,7 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print
|
||||||
var row = opts.row_offset;
|
var row = opts.row_offset;
|
||||||
switch (opts.wrap) {
|
switch (opts.wrap) {
|
||||||
.grapheme => {
|
.grapheme => {
|
||||||
var col: usize = 0;
|
var col: usize = opts.col_offset;
|
||||||
const overflow: bool = blk: for (segments) |segment| {
|
const overflow: bool = blk: for (segments) |segment| {
|
||||||
var iter = self.screen.unicode.graphemeIterator(segment.text);
|
var iter = self.screen.unicode.graphemeIterator(segment.text);
|
||||||
while (iter.next()) |grapheme| {
|
while (iter.next()) |grapheme| {
|
||||||
|
@ -324,7 +326,7 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
.word => {
|
.word => {
|
||||||
var col: usize = 0;
|
var col: usize = opts.col_offset;
|
||||||
var overflow: bool = false;
|
var overflow: bool = false;
|
||||||
var soft_wrapped: bool = false;
|
var soft_wrapped: bool = false;
|
||||||
for (segments) |segment| {
|
for (segments) |segment| {
|
||||||
|
@ -423,7 +425,7 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
.none => {
|
.none => {
|
||||||
var col: usize = 0;
|
var col: usize = opts.col_offset;
|
||||||
const overflow: bool = blk: for (segments) |segment| {
|
const overflow: bool = blk: for (segments) |segment| {
|
||||||
var iter = self.screen.unicode.graphemeIterator(segment.text);
|
var iter = self.screen.unicode.graphemeIterator(segment.text);
|
||||||
while (iter.next()) |grapheme| {
|
while (iter.next()) |grapheme| {
|
||||||
|
|
Loading…
Reference in a new issue