Skip to content

Commit c6d9c01

Browse files
feat: add CellData.AttributesEqual method
Add AttributesEqual method to CellData that compares all visual attributes between two cells (fg/bg color and mode, bold, italic, underline style, underline color, overline, blink, invisible, dim, strikethrough, inverse). Used by renderers and the serialize addon to detect attribute boundaries. Fixes #5 Co-authored-by: Ona <no-reply@ona.com>
1 parent 3bbf4da commit c6d9c01

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

celldata.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,51 @@ func (c *CellData) SetFromCharData(cd CharData) {
9797
}
9898
}
9999

100+
// AttributesEqual returns true if this cell has the same visual attributes as other.
101+
// Compares fg/bg color and mode, all text decoration flags, and underline style/color.
102+
func (c *CellData) AttributesEqual(other *CellData) bool {
103+
if c.GetFgColorMode() != other.GetFgColorMode() || c.GetFgColor() != other.GetFgColor() {
104+
return false
105+
}
106+
if c.GetBgColorMode() != other.GetBgColorMode() || c.GetBgColor() != other.GetBgColor() {
107+
return false
108+
}
109+
if c.IsInverse() != other.IsInverse() {
110+
return false
111+
}
112+
if c.IsBold() != other.IsBold() {
113+
return false
114+
}
115+
if c.IsUnderline() != other.IsUnderline() {
116+
return false
117+
}
118+
if c.IsOverline() != other.IsOverline() {
119+
return false
120+
}
121+
if c.IsBlink() != other.IsBlink() {
122+
return false
123+
}
124+
if c.IsInvisible() != other.IsInvisible() {
125+
return false
126+
}
127+
if c.IsItalic() != other.IsItalic() {
128+
return false
129+
}
130+
if c.IsDim() != other.IsDim() {
131+
return false
132+
}
133+
if c.IsStrikethrough() != other.IsStrikethrough() {
134+
return false
135+
}
136+
if c.GetUnderlineStyle() != other.GetUnderlineStyle() {
137+
return false
138+
}
139+
if c.GetUnderlineColor() != other.GetUnderlineColor() {
140+
return false
141+
}
142+
return true
143+
}
144+
100145
// GetAsCharData returns the cell as a legacy CharData tuple.
101146
func (c *CellData) GetAsCharData() CharData {
102147
return NewCharData(c.Fg, c.GetChars(), c.GetWidth(), c.GetCode())

celldata_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,4 @@ func TestCellDataGetCodeEmptyCombined(t *testing.T) {
172172
t.Errorf("(-want +got):\n%s", diff)
173173
}
174174
}
175+

0 commit comments

Comments
 (0)