add(style): merge function to merge styles from different styles together
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 1m43s

Merging may overwrite changes of the current style with the other style
if that style differs from the default value.
This commit is contained in:
2025-01-07 12:56:52 +01:00
parent c2c3f41ff3
commit 0015bac9ff

View File

@@ -113,6 +113,22 @@ reverse: bool = false,
invisible: bool = false, invisible: bool = false,
strikethrough: bool = false, strikethrough: bool = false,
/// Merge _other_ `Style` to _this_ style and overwrite _this_ `Style`'s value
/// if the _other_ value differs from the default value.
pub fn merge(this: *@This(), other: @This()) void {
if (other.fg != .default) this.fg = other.fg;
if (other.bg != .default) this.bg = other.bg;
if (other.ul != .default) this.ul = other.ul;
if (other.ul_style != .off) this.ul_style = other.ul_style;
if (other.bold == false) this.bold = other.bold;
if (other.dim == false) this.dim = other.dim;
if (other.italic == false) this.italic = other.italic;
if (other.blink == false) this.blink = other.blink;
if (other.reverse == false) this.reverse = other.reverse;
if (other.invisible == false) this.invisible = other.invisible;
if (other.strikethrough == false) this.strikethrough = other.strikethrough;
}
fn start(this: @This(), writer: anytype) !void { fn start(this: @This(), writer: anytype) !void {
// foreground // foreground
switch (this.fg) { switch (this.fg) {