From 227168dc05683e8092c5528f7dd9bb35d0c094a9 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 18 Sep 2024 12:00:51 -0400 Subject: [PATCH] refactor(cellbuf): rename Style to CellStyle and Hyperlink to CellLink --- cellbuf/buffer_string.go | 4 ++-- cellbuf/buffer_write.go | 4 ++-- cellbuf/cell.go | 16 +++++++-------- cellbuf/style.go | 42 ++++++++++++++++++++-------------------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/cellbuf/buffer_string.go b/cellbuf/buffer_string.go index 7f70c03..fc8e9a4 100644 --- a/cellbuf/buffer_string.go +++ b/cellbuf/buffer_string.go @@ -9,8 +9,8 @@ import ( // Render returns a string representation of the buffer with ANSI escape // sequences. Use [ansi.Strip] to remove them. func (b *Buffer) Render() string { - var pen Style - var link Hyperlink + var pen CellStyle + var link CellLink var buf bytes.Buffer for y := 0; y < b.height; y++ { for x := 0; x < b.width; x++ { diff --git a/cellbuf/buffer_write.go b/cellbuf/buffer_write.go index fcd60fb..000d900 100644 --- a/cellbuf/buffer_write.go +++ b/cellbuf/buffer_write.go @@ -25,8 +25,8 @@ func writeFrame[ decodeRune TDecodeRuneFunc, ) (n int, err error) { var cell Cell - var pen Style - var link Hyperlink + var pen CellStyle + var link CellLink origX := x p := ansi.GetParser() diff --git a/cellbuf/cell.go b/cellbuf/cell.go index b166ff0..9f331be 100644 --- a/cellbuf/cell.go +++ b/cellbuf/cell.go @@ -20,10 +20,10 @@ var ( type Cell struct { // The style of the cell. Nil style means no style. Zero value prints a // reset sequence. - Style Style + Style CellStyle // Link is the hyperlink of the cell. - Link Hyperlink + Link CellLink // Content is the string representation of the cell as a grapheme cluster. Content string @@ -85,30 +85,30 @@ func (c *Cell) Info() string { return b.String() } -// Hyperlink represents a hyperlink in the terminal screen. -type Hyperlink struct { +// CellLink represents a hyperlink in the terminal screen. +type CellLink struct { URL string URLID string } // Reset resets the hyperlink to the default state zero value. -func (h *Hyperlink) Reset() { +func (h *CellLink) Reset() { h.URL = "" h.URLID = "" } // Equal returns true if the hyperlink is equal to the other hyperlink. -func (h Hyperlink) Equal(o Hyperlink) bool { +func (h CellLink) Equal(o CellLink) bool { return h.URL == o.URL && h.URLID == o.URLID } // IsEmpty returns true if the hyperlink is empty. -func (h Hyperlink) IsEmpty() bool { +func (h CellLink) IsEmpty() bool { return h.URL == "" && h.URLID == "" } // Info returns a string representation of the hyperlink. -func (h Hyperlink) Info() string { +func (h CellLink) Info() string { if h.URL == "" && h.URLID == "" { return "Hyperlink{}" } else if h.URL == "" { diff --git a/cellbuf/style.go b/cellbuf/style.go index d8c2302..2a3ef9f 100644 --- a/cellbuf/style.go +++ b/cellbuf/style.go @@ -86,8 +86,8 @@ func (u UnderlineStyle) String() string { return underlineStyleNames[u] } -// Style represents the Style of a cell. -type Style struct { +// CellStyle represents the CellStyle of a cell. +type CellStyle struct { Fg ansi.Color Bg ansi.Color Ul ansi.Color @@ -96,7 +96,7 @@ type Style struct { } // Sequence returns the ANSI sequence that sets the style. -func (s Style) Sequence() string { +func (s CellStyle) Sequence() string { if s.IsEmpty() { return ansi.ResetStyle } @@ -158,7 +158,7 @@ func (s Style) Sequence() string { // DiffSequence returns the ANSI sequence that sets the style as a diff from // another style. -func (s Style) DiffSequence(o Style) string { +func (s CellStyle) DiffSequence(o CellStyle) string { if o.IsEmpty() { return s.Sequence() } @@ -247,7 +247,7 @@ func (s Style) DiffSequence(o Style) string { } // Equal returns true if the style is equal to the other style. -func (s Style) Equal(o Style) bool { +func (s CellStyle) Equal(o CellStyle) bool { return colorEqual(s.Fg, o.Fg) && colorEqual(s.Bg, o.Bg) && colorEqual(s.Ul, o.Ul) && @@ -268,7 +268,7 @@ func colorEqual(c, o ansi.Color) bool { } // Bold sets the bold attribute. -func (s *Style) Bold(v bool) *Style { +func (s *CellStyle) Bold(v bool) *CellStyle { if v { s.Attrs |= BoldAttr } else { @@ -278,7 +278,7 @@ func (s *Style) Bold(v bool) *Style { } // Faint sets the faint attribute. -func (s *Style) Faint(v bool) *Style { +func (s *CellStyle) Faint(v bool) *CellStyle { if v { s.Attrs |= FaintAttr } else { @@ -288,7 +288,7 @@ func (s *Style) Faint(v bool) *Style { } // Italic sets the italic attribute. -func (s *Style) Italic(v bool) *Style { +func (s *CellStyle) Italic(v bool) *CellStyle { if v { s.Attrs |= ItalicAttr } else { @@ -298,7 +298,7 @@ func (s *Style) Italic(v bool) *Style { } // SlowBlink sets the slow blink attribute. -func (s *Style) SlowBlink(v bool) *Style { +func (s *CellStyle) SlowBlink(v bool) *CellStyle { if v { s.Attrs |= SlowBlinkAttr } else { @@ -308,7 +308,7 @@ func (s *Style) SlowBlink(v bool) *Style { } // RapidBlink sets the rapid blink attribute. -func (s *Style) RapidBlink(v bool) *Style { +func (s *CellStyle) RapidBlink(v bool) *CellStyle { if v { s.Attrs |= RapidBlinkAttr } else { @@ -318,7 +318,7 @@ func (s *Style) RapidBlink(v bool) *Style { } // Reverse sets the reverse attribute. -func (s *Style) Reverse(v bool) *Style { +func (s *CellStyle) Reverse(v bool) *CellStyle { if v { s.Attrs |= ReverseAttr } else { @@ -328,7 +328,7 @@ func (s *Style) Reverse(v bool) *Style { } // Conceal sets the conceal attribute. -func (s *Style) Conceal(v bool) *Style { +func (s *CellStyle) Conceal(v bool) *CellStyle { if v { s.Attrs |= ConcealAttr } else { @@ -338,7 +338,7 @@ func (s *Style) Conceal(v bool) *Style { } // Strikethrough sets the strikethrough attribute. -func (s *Style) Strikethrough(v bool) *Style { +func (s *CellStyle) Strikethrough(v bool) *CellStyle { if v { s.Attrs |= StrikethroughAttr } else { @@ -348,14 +348,14 @@ func (s *Style) Strikethrough(v bool) *Style { } // UnderlineStyle sets the underline style. -func (s *Style) UnderlineStyle(style UnderlineStyle) *Style { +func (s *CellStyle) UnderlineStyle(style UnderlineStyle) *CellStyle { s.UlStyle = style return s } // Underline sets the underline attribute. // This is a syntactic sugar for [UnderlineStyle]. -func (s *Style) Underline(v bool) *Style { +func (s *CellStyle) Underline(v bool) *CellStyle { if v { return s.UnderlineStyle(SingleUnderline) } @@ -363,25 +363,25 @@ func (s *Style) Underline(v bool) *Style { } // Foreground sets the foreground color. -func (s *Style) Foreground(c ansi.Color) *Style { +func (s *CellStyle) Foreground(c ansi.Color) *CellStyle { s.Fg = c return s } // Background sets the background color. -func (s *Style) Background(c ansi.Color) *Style { +func (s *CellStyle) Background(c ansi.Color) *CellStyle { s.Bg = c return s } // UnderlineColor sets the underline color. -func (s *Style) UnderlineColor(c ansi.Color) *Style { +func (s *CellStyle) UnderlineColor(c ansi.Color) *CellStyle { s.Ul = c return s } // Reset resets the style to default. -func (s *Style) Reset() *Style { +func (s *CellStyle) Reset() *CellStyle { s.Fg = nil s.Bg = nil s.Ul = nil @@ -391,12 +391,12 @@ func (s *Style) Reset() *Style { } // IsEmpty returns true if the style is empty. -func (s *Style) IsEmpty() bool { +func (s *CellStyle) IsEmpty() bool { return s.Fg == nil && s.Bg == nil && s.Ul == nil && s.Attrs == ResetAttr && s.UlStyle == NoUnderline } // Info returns a string representation of the style. -func (s *Style) Info() string { +func (s *CellStyle) Info() string { if s.IsEmpty() { return "Style{ResetAttr}" }