Skip to content

Commit

Permalink
Merge branch 'master' into list-example
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed May 30, 2024
2 parents 7799594 + 70c908d commit 57bc7b2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 48 deletions.
2 changes: 1 addition & 1 deletion color.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var noColor = NoColor{}
//
// Example usage:
//
// var style = someStyle.Copy().Background(lipgloss.NoColor{})
// var style = someStyle.Background(lipgloss.NoColor{})
type NoColor struct{}

func (NoColor) color(*Renderer) termenv.Color {
Expand Down
6 changes: 3 additions & 3 deletions set.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ func (s Style) BorderLeftBackground(c TerminalColor) Style {
// var userStyle = text.Style{ /* ... */ }
// fmt.Println(userStyle.Inline(true).Render(userInput))
func (s Style) Inline(v bool) Style {
o := s.Copy()
o := s // copy
o.set(inlineKey, v)
return o
}
Expand All @@ -621,7 +621,7 @@ func (s Style) Inline(v bool) Style {
// var userStyle = text.Style{ /* ... */ }
// fmt.Println(userStyle.MaxWidth(16).Render(userInput))
func (s Style) MaxWidth(n int) Style {
o := s.Copy()
o := s // copy
o.set(maxWidthKey, n)
return o
}
Expand All @@ -633,7 +633,7 @@ func (s Style) MaxWidth(n int) Style {
// Because this in intended to be used at the time of render, this method will
// not mutate the style and instead returns a copy.
func (s Style) MaxHeight(n int) Style {
o := s.Copy()
o := s // copy
o.set(maxHeightKey, n)
return o
}
Expand Down
3 changes: 2 additions & 1 deletion style.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ func (s Style) String() string {

// Copy returns a copy of this style, including any underlying string values.
//
// Deprecated: to copy just use assignment (i.e. a := b). All methods also return a new style.
// Deprecated: to copy just use assignment (i.e. a := b). All methods also
// return a new style.
func (s Style) Copy() Style {
return s
}
Expand Down
86 changes: 43 additions & 43 deletions style_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ func TestUnderline(t *testing.T) {
r.NewStyle().Underline(true),
"\x1b[4;4ma\x1b[0m\x1b[4;4mb\x1b[0m\x1b[4m \x1b[0m\x1b[4;4mc\x1b[0m",
},
{
r.NewStyle().Underline(true).UnderlineSpaces(true),
"\x1b[4;4ma\x1b[0m\x1b[4;4mb\x1b[0m\x1b[4m \x1b[0m\x1b[4;4mc\x1b[0m",
},
{
r.NewStyle().Underline(true).UnderlineSpaces(false),
"\x1b[4;4ma\x1b[0m\x1b[4;4mb\x1b[0m \x1b[4;4mc\x1b[0m",
},
{
r.NewStyle().UnderlineSpaces(true),
"ab\x1b[4m \x1b[0mc",
},
}
{
r.NewStyle().Underline(true).UnderlineSpaces(true),
"\x1b[4;4ma\x1b[0m\x1b[4;4mb\x1b[0m\x1b[4m \x1b[0m\x1b[4;4mc\x1b[0m",
},
{
r.NewStyle().Underline(true).UnderlineSpaces(false),
"\x1b[4;4ma\x1b[0m\x1b[4;4mb\x1b[0m \x1b[4;4mc\x1b[0m",
},
{
r.NewStyle().UnderlineSpaces(true),
"ab\x1b[4m \x1b[0mc",
},
}

for i, tc := range tt {
s := tc.style.Copy().SetString("ab c")
s := tc.style.SetString("ab c")
res := s.Render()
if res != tc.expected {
t.Errorf("Test %d, expected:\n\n`%s`\n`%s`\n\nActual output:\n\n`%s`\n`%s`\n\n",
Expand All @@ -62,22 +62,22 @@ func TestStrikethrough(t *testing.T) {
r.NewStyle().Strikethrough(true),
"\x1b[9ma\x1b[0m\x1b[9mb\x1b[0m\x1b[9m \x1b[0m\x1b[9mc\x1b[0m",
},
{
r.NewStyle().Strikethrough(true).StrikethroughSpaces(true),
"\x1b[9ma\x1b[0m\x1b[9mb\x1b[0m\x1b[9m \x1b[0m\x1b[9mc\x1b[0m",
},
{
r.NewStyle().Strikethrough(true).StrikethroughSpaces(false),
"\x1b[9ma\x1b[0m\x1b[9mb\x1b[0m \x1b[9mc\x1b[0m",
},
{
r.NewStyle().StrikethroughSpaces(true),
"ab\x1b[9m \x1b[0mc",
},
}
{
r.NewStyle().Strikethrough(true).StrikethroughSpaces(true),
"\x1b[9ma\x1b[0m\x1b[9mb\x1b[0m\x1b[9m \x1b[0m\x1b[9mc\x1b[0m",
},
{
r.NewStyle().Strikethrough(true).StrikethroughSpaces(false),
"\x1b[9ma\x1b[0m\x1b[9mb\x1b[0m \x1b[9mc\x1b[0m",
},
{
r.NewStyle().StrikethroughSpaces(true),
"ab\x1b[9m \x1b[0mc",
},
}

for i, tc := range tt {
s := tc.style.Copy().SetString("ab c")
s := tc.style.SetString("ab c")
res := s.Render()
if res != tc.expected {
t.Errorf("Test %d, expected:\n\n`%s`\n`%s`\n\nActual output:\n\n`%s`\n`%s`\n\n",
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestStyleRender(t *testing.T) {
}

for i, tc := range tt {
s := tc.style.Copy().SetString("hello")
s := tc.style.SetString("hello")
res := s.Render()
if res != tc.expected {
t.Errorf("Test %d, expected:\n\n`%s`\n`%s`\n\nActual output:\n\n`%s`\n`%s`\n\n",
Expand Down Expand Up @@ -181,7 +181,7 @@ func TestStyleCustomRender(t *testing.T) {
}

for i, tc := range tt {
s := tc.style.Copy().SetString("hello")
s := tc.style.SetString("hello")
res := s.Render()
if res != tc.expected {
t.Errorf("Test %d, expected:\n\n`%s`\n`%s`\n\nActual output:\n\n`%s`\n`%s`\n\n",
Expand Down Expand Up @@ -232,9 +232,9 @@ func TestStyleInherit(t *testing.T) {
requireEqual(t, s.GetBold(), i.GetBold())
requireEqual(t, s.GetItalic(), i.GetItalic())
requireEqual(t, s.GetUnderline(), i.GetUnderline())
requireEqual(t, s.GetUnderlineSpaces(), i.GetUnderlineSpaces())
requireEqual(t, s.GetUnderlineSpaces(), i.GetUnderlineSpaces())
requireEqual(t, s.GetStrikethrough(), i.GetStrikethrough())
requireEqual(t, s.GetStrikethroughSpaces(), i.GetStrikethroughSpaces())
requireEqual(t, s.GetStrikethroughSpaces(), i.GetStrikethroughSpaces())
requireEqual(t, s.GetBlink(), i.GetBlink())
requireEqual(t, s.GetFaint(), i.GetFaint())
requireEqual(t, s.GetForeground(), i.GetForeground())
Expand Down Expand Up @@ -266,14 +266,14 @@ func TestStyleCopy(t *testing.T) {
Padding(1, 1, 1, 1).
TabWidth(2)

i := s.Copy()
i := s // copy

requireEqual(t, s.GetBold(), i.GetBold())
requireEqual(t, s.GetItalic(), i.GetItalic())
requireEqual(t, s.GetUnderline(), i.GetUnderline())
requireEqual(t, s.GetUnderlineSpaces(), i.GetUnderlineSpaces())
requireEqual(t, s.GetUnderlineSpaces(), i.GetUnderlineSpaces())
requireEqual(t, s.GetStrikethrough(), i.GetStrikethrough())
requireEqual(t, s.GetStrikethroughSpaces(), i.GetStrikethroughSpaces())
requireEqual(t, s.GetStrikethroughSpaces(), i.GetStrikethroughSpaces())
requireEqual(t, s.GetBlink(), i.GetBlink())
requireEqual(t, s.GetFaint(), i.GetFaint())
requireEqual(t, s.GetForeground(), i.GetForeground())
Expand Down Expand Up @@ -308,20 +308,20 @@ func TestStyleUnset(t *testing.T) {
s = s.UnsetUnderline()
requireFalse(t, s.GetUnderline())

s = NewStyle().UnderlineSpaces(true)
requireTrue(t, s.GetUnderlineSpaces())
s = s.UnsetUnderlineSpaces()
requireFalse(t, s.GetUnderlineSpaces())
s = NewStyle().UnderlineSpaces(true)
requireTrue(t, s.GetUnderlineSpaces())
s = s.UnsetUnderlineSpaces()
requireFalse(t, s.GetUnderlineSpaces())

s = NewStyle().Strikethrough(true)
requireTrue(t, s.GetStrikethrough())
s = s.UnsetStrikethrough()
requireFalse(t, s.GetStrikethrough())

s = NewStyle().StrikethroughSpaces(true)
requireTrue(t, s.GetStrikethroughSpaces())
s = s.UnsetStrikethroughSpaces()
requireFalse(t, s.GetStrikethroughSpaces())
s = NewStyle().StrikethroughSpaces(true)
requireTrue(t, s.GetStrikethroughSpaces())
s = s.UnsetStrikethroughSpaces()
requireFalse(t, s.GetStrikethroughSpaces())

s = NewStyle().Reverse(true)
requireTrue(t, s.GetReverse())
Expand Down

0 comments on commit 57bc7b2

Please sign in to comment.