diff --git a/src/terminal/Style.zig b/src/terminal/Style.zig index a3451a5..af0b137 100644 --- a/src/terminal/Style.zig +++ b/src/terminal/Style.zig @@ -113,6 +113,22 @@ reverse: bool = false, invisible: 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 { // foreground switch (this.fg) {