fix(container): check border sides configurations before trying to create borders
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 28s

This commit is contained in:
2025-03-01 20:58:34 +01:00
parent e2fe884925
commit bec0cf2987

View File

@@ -48,37 +48,41 @@ pub const Border = packed struct {
std.debug.assert(frame.len == 6); std.debug.assert(frame.len == 6);
// render top and bottom border // render top and bottom border
for (0..size.cols) |col| { if (this.sides.top or this.sides.bottom) {
const last_row = @as(usize, size.rows - 1) * @as(usize, size.cols); for (0..size.cols) |col| {
if (this.sides.left and col == 0) { const last_row = @as(usize, size.rows - 1) * @as(usize, size.cols);
// top left corner if (this.sides.left and col == 0) {
if (this.sides.top) cells[col].cp = frame[0]; // top left corner
// bottom left corner if (this.sides.top) cells[col].cp = frame[0];
if (this.sides.bottom) cells[last_row + col].cp = frame[4]; // bottom left corner
} else if (this.sides.right and col == size.cols - 1) { if (this.sides.bottom) cells[last_row + col].cp = frame[4];
// top right corner } else if (this.sides.right and col == size.cols - 1) {
if (this.sides.top) cells[col].cp = frame[2]; // top right corner
// bottom left corner if (this.sides.top) cells[col].cp = frame[2];
if (this.sides.bottom) cells[last_row + col].cp = frame[5]; // bottom left corner
} else { if (this.sides.bottom) cells[last_row + col].cp = frame[5];
// top side } else {
if (this.sides.top) cells[col].cp = frame[1]; // top side
// bottom side if (this.sides.top) cells[col].cp = frame[1];
if (this.sides.bottom) cells[last_row + col].cp = frame[1]; // bottom side
if (this.sides.bottom) cells[last_row + col].cp = frame[1];
}
if (this.sides.top) cells[col].style.fg = this.color;
if (this.sides.bottom) cells[last_row + col].style.fg = this.color;
} }
if (this.sides.top) cells[col].style.fg = this.color;
if (this.sides.bottom) cells[last_row + col].style.fg = this.color;
} }
// render left and right border // render left and right border
for (1..size.rows -| 1) |row| { if (this.sides.left or this.sides.right) {
const idx = (row * size.cols); for (1..size.rows -| 1) |row| {
if (this.sides.left) { const idx = (row * size.cols);
cells[idx].cp = frame[3]; // left if (this.sides.left) {
cells[idx].style.fg = this.color; cells[idx].cp = frame[3]; // left
} cells[idx].style.fg = this.color;
if (this.sides.right) { }
cells[idx + size.cols - 1].cp = frame[3]; // right if (this.sides.right) {
cells[idx + size.cols - 1].style.fg = this.color; cells[idx + size.cols - 1].cp = frame[3]; // right
cells[idx + size.cols - 1].style.fg = this.color;
}
} }
} }
} }