diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-07-31 17:15:38 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-07-31 17:56:47 +1000 |
commit | 550c0fd4dc0ee2d6bb6185fa0dd50ff9e250a9de (patch) | |
tree | 068efeda909c5803d7d4dabaf753420e1fca7c02 /pkg/gui/style | |
parent | 0bc0e4ac88f430976e4f2e69285ad6c56d94c137 (diff) |
refactor
Diffstat (limited to 'pkg/gui/style')
-rw-r--r-- | pkg/gui/style/basic_styles.go (renamed from pkg/gui/style/style.go) | 8 | ||||
-rw-r--r-- | pkg/gui/style/text_style.go (renamed from pkg/gui/style/basic.go) | 19 |
2 files changed, 11 insertions, 16 deletions
diff --git a/pkg/gui/style/style.go b/pkg/gui/style/basic_styles.go index d6c8149b2..ef29904bc 100644 --- a/pkg/gui/style/style.go +++ b/pkg/gui/style/basic_styles.go @@ -28,3 +28,11 @@ var ( AttrUnderline = New().SetUnderline() AttrBold = New().SetBold() ) + +func FromBasicFg(fg color.Color) TextStyle { + return New().SetFg(NewBasicColor(fg)) +} + +func FromBasicBg(bg color.Color) TextStyle { + return New().SetBg(NewBasicColor(bg)) +} diff --git a/pkg/gui/style/basic.go b/pkg/gui/style/text_style.go index 45652097e..d2bfccaeb 100644 --- a/pkg/gui/style/basic.go +++ b/pkg/gui/style/text_style.go @@ -44,22 +44,6 @@ func New() TextStyle { return s } -func FromBasicFg(fg color.Color) TextStyle { - s := New() - c := NewBasicColor(fg) - s.fg = &c - s.style = s.deriveStyle() - return s -} - -func FromBasicBg(bg color.Color) TextStyle { - s := New() - c := NewBasicColor(bg) - s.bg = &c - s.style = s.deriveStyle() - return s -} - func (b TextStyle) Sprint(a ...interface{}) string { return b.style.Sprint(a...) } @@ -68,6 +52,9 @@ func (b TextStyle) Sprintf(format string, a ...interface{}) string { return b.style.Sprintf(format, a...) } +// note that our receiver here is not a pointer which means we're receiving a +// copy of the original TextStyle. This allows us to mutate and return that +// TextStyle receiver without actually modifying the original. func (b TextStyle) SetBold() TextStyle { b.decoration.SetBold() b.style = b.deriveStyle() |