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
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user