fix: pass tests

This commit is contained in:
Rylee Lyman 2024-06-21 16:54:18 -04:00 committed by Tim Culverhouse
parent 74fb130797
commit f7cbd42ed5

View file

@ -328,10 +328,12 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print
.word => { .word => {
var col: usize = opts.col_offset; var col: usize = opts.col_offset;
var overflow: bool = false; var overflow: bool = false;
var soft_wrapped = false;
for (segments) |segment| { for (segments) |segment| {
var start: usize = 0; var start: usize = 0;
var tokenizer = std.mem.tokenizeAny(u8, segment.text, "\r\n"); var tokenizer = std.mem.tokenizeAny(u8, segment.text, "\r\n");
while (tokenizer.peek() != null) { while (tokenizer.peek() != null) {
soft_wrapped = false;
const returns = segment.text[start..tokenizer.index]; const returns = segment.text[start..tokenizer.index];
const line = tokenizer.next().?; const line = tokenizer.next().?;
start = tokenizer.index; start = tokenizer.index;
@ -351,6 +353,7 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print
const word = iter.next().?; const word = iter.next().?;
ws_start = iter.index; ws_start = iter.index;
var j: usize = 0; var j: usize = 0;
if (soft_wrapped) soft_wrapped = false else {
while (j < whitespace.len) : (j += 1) { while (j < whitespace.len) : (j += 1) {
if (opts.commit) self.writeCell(col, row, .{ if (opts.commit) self.writeCell(col, row, .{
.char = .{ .char = .{
@ -362,9 +365,11 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print
}); });
col += 1; col += 1;
} }
}
if (col >= self.width) { if (col >= self.width) {
col = 0; col = 0;
row += 1; row += 1;
soft_wrapped = true;
} }
const width = self.gwidth(word); const width = self.gwidth(word);
if (width + col > self.width and width < self.width) { if (width + col > self.width and width < self.width) {
@ -378,6 +383,7 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print
var grapheme_iterator = self.screen.unicode.graphemeIterator(word); var grapheme_iterator = self.screen.unicode.graphemeIterator(word);
while (grapheme_iterator.next()) |grapheme| { while (grapheme_iterator.next()) |grapheme| {
soft_wrapped = false;
const s = grapheme.bytes(word); const s = grapheme.bytes(word);
const w = self.gwidth(s); const w = self.gwidth(s);
if (opts.commit) self.writeCell(col, row, .{ if (opts.commit) self.writeCell(col, row, .{
@ -392,9 +398,22 @@ pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !Print
if (col >= self.width) { if (col >= self.width) {
row += 1; row += 1;
col = 0; col = 0;
soft_wrapped = true;
} }
} }
} }
} else {
const returns = segment.text[start..tokenizer.index];
start = tokenizer.index;
var i: usize = 0;
while (i < returns.len) : (i += 1) {
const b = returns[i];
if (b == '\r' and i + 1 < returns.len and returns[i + 1] == '\n') {
i += 1;
}
row += 1;
col = 0;
}
} }
} }
return .{ return .{