From 4767d98dd25342a0e5b1fc534e87b95ca602c39d Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Mon, 6 May 2024 17:19:09 -0400 Subject: [PATCH] Lip Gloss Styles (struct) (#220) * feat: use non-copied styles * chore: no more copy --- examples/bubbletea/main.go | 6 +- examples/go.mod | 12 +- examples/go.sum | 24 +-- field_filepicker.go | 2 +- go.mod | 12 +- go.sum | 12 ++ huh_test.go | 3 +- theme.go | 351 ++++++++++++++----------------------- 8 files changed, 178 insertions(+), 244 deletions(-) diff --git a/examples/bubbletea/main.go b/examples/bubbletea/main.go index 68231643..75c6b4a5 100644 --- a/examples/bubbletea/main.go +++ b/examples/bubbletea/main.go @@ -46,7 +46,7 @@ func NewStyles(lg *lipgloss.Renderer) *Styles { Bold(true) s.Highlight = lg.NewStyle(). Foreground(lipgloss.Color("212")) - s.ErrorHeaderText = s.HeaderText.Copy(). + s.ErrorHeaderText = s.HeaderText. Foreground(red) s.Help = lg.NewStyle(). Foreground(lipgloss.Color("240")) @@ -155,7 +155,7 @@ func (m Model) View() string { var b strings.Builder fmt.Fprintf(&b, "Congratulations, you’re Charm’s newest\n%s!\n\n", title) fmt.Fprintf(&b, "Your job description is as follows:\n\n%s\n\nPlease proceed to HR immediately.", role) - return s.Status.Copy().Margin(0, 1).Padding(1, 2).Width(48).Render(b.String()) + "\n\n" + return s.Status.Margin(0, 1).Padding(1, 2).Width(48).Render(b.String()) + "\n\n" default: var class string @@ -189,7 +189,7 @@ func (m Model) View() string { const statusWidth = 28 statusMarginLeft := m.width - statusWidth - lipgloss.Width(form) - s.Status.GetMarginRight() - status = s.Status.Copy(). + status = s.Status. Height(lipgloss.Height(form)). Width(statusWidth). MarginLeft(statusMarginLeft). diff --git a/examples/go.mod b/examples/go.mod index f15b09f5..e108a6df 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -7,11 +7,11 @@ require ( github.com/charmbracelet/bubbletea v0.26.1 github.com/charmbracelet/huh v0.0.0-00010101000000-000000000000 github.com/charmbracelet/huh/spinner v0.0.0-00010101000000-000000000000 - github.com/charmbracelet/lipgloss v0.10.0 + github.com/charmbracelet/lipgloss v0.10.1-0.20240506202754-3ee5dcab73cb github.com/charmbracelet/log v0.4.0 github.com/charmbracelet/ssh v0.0.0-20240401141849-854cddfa2917 github.com/charmbracelet/wish v1.4.0 - github.com/charmbracelet/x/exp/strings v0.0.0-20240403043919-dea9035a27d4 + github.com/charmbracelet/x/exp/strings v0.0.0-20240506152644-8135bef4e495 ) require ( @@ -22,7 +22,7 @@ require ( github.com/charmbracelet/harmonica v0.2.0 // indirect github.com/charmbracelet/keygen v0.5.0 // indirect github.com/charmbracelet/x/errors v0.0.0-20240117030013-d31dba354651 // indirect - github.com/charmbracelet/x/exp/term v0.0.0-20240328150354-ab9afc214dfd // indirect + github.com/charmbracelet/x/exp/term v0.0.0-20240506152644-8135bef4e495 // indirect github.com/creack/pty v1.1.21 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect @@ -39,9 +39,9 @@ require ( golang.org/x/crypto v0.21.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.19.0 // indirect - golang.org/x/term v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/term v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect ) replace github.com/charmbracelet/huh => ../ diff --git a/examples/go.sum b/examples/go.sum index 178be113..c1f88a41 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -14,8 +14,8 @@ github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao= github.com/charmbracelet/keygen v0.5.0 h1:XY0fsoYiCSM9axkrU+2ziE6u6YjJulo/b9Dghnw6MZc= github.com/charmbracelet/keygen v0.5.0/go.mod h1:DfvCgLHxZ9rJxdK0DGw3C/LkV4SgdGbnliHcObV3L+8= -github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s= -github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE= +github.com/charmbracelet/lipgloss v0.10.1-0.20240506202754-3ee5dcab73cb h1:Hs3xzxHuruNT2Iuo87iS40c0PhLqpnUKBI6Xw6Ad3wQ= +github.com/charmbracelet/lipgloss v0.10.1-0.20240506202754-3ee5dcab73cb/go.mod h1:EPP2QJ0ectp3zo6gx9f8oJGq8keirqPJ3XpYEI8wrrs= github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM= github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM= github.com/charmbracelet/ssh v0.0.0-20240401141849-854cddfa2917 h1:NZKjJ7d/pzk/AfcJYEzmF8M48JlIrrY00RR5JdDc3io= @@ -24,10 +24,10 @@ github.com/charmbracelet/wish v1.4.0 h1:pL1uVP/YuYgJheHEj98teZ/n6pMYnmlZq/fcHvom github.com/charmbracelet/wish v1.4.0/go.mod h1:ew4/MjJVfW/akEO9KmrQHQv1F7bQRGscRMrA+KtovTk= github.com/charmbracelet/x/errors v0.0.0-20240117030013-d31dba354651 h1:3RXpZWGWTOeVXCTv0Dnzxdv/MhNUkBfEcbaTY0zrTQI= github.com/charmbracelet/x/errors v0.0.0-20240117030013-d31dba354651/go.mod h1:2P0UgXMEa6TsToMSuFqKFQR+fZTO9CNGUNokkPatT/0= -github.com/charmbracelet/x/exp/strings v0.0.0-20240403043919-dea9035a27d4 h1:3hiHarKRDh7NF0mtD7iMjW0dHz4XKelswmRpFNR2lKw= -github.com/charmbracelet/x/exp/strings v0.0.0-20240403043919-dea9035a27d4/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ= -github.com/charmbracelet/x/exp/term v0.0.0-20240328150354-ab9afc214dfd h1:HqBjkSFXXfW4IgX3TMKipWoPEN08T3Pi4SA/3DLss/U= -github.com/charmbracelet/x/exp/term v0.0.0-20240328150354-ab9afc214dfd/go.mod h1:6GZ13FjIP6eOCqWU4lqgveGnYxQo9c3qBzHPeFu4HBE= +github.com/charmbracelet/x/exp/strings v0.0.0-20240506152644-8135bef4e495 h1:/aQyDLa4ptexEC+jETEzgXNfMZety/g+niLB4eYsKhM= +github.com/charmbracelet/x/exp/strings v0.0.0-20240506152644-8135bef4e495/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ= +github.com/charmbracelet/x/exp/term v0.0.0-20240506152644-8135bef4e495 h1:+0U9qX8Pv8KiYgRxfBvORRjgBzLgHMjtElP4O0PyKYA= +github.com/charmbracelet/x/exp/term v0.0.0-20240506152644-8135bef4e495/go.mod h1:qeR6w1zITbkF7vEhcx0CqX5GfnIiQloJWQghN6HfP+c= github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0= github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -68,10 +68,10 @@ golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= -golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/field_filepicker.go b/field_filepicker.go index 952e64a6..340407b4 100644 --- a/field_filepicker.go +++ b/field_filepicker.go @@ -344,7 +344,7 @@ func (f *FilePicker) WithTheme(theme *Theme) Field { Selected: theme.Focused.SelectedOption, DisabledSelected: theme.Focused.TextInput.Placeholder, FileSize: theme.Focused.TextInput.Placeholder, - EmptyDirectory: theme.Focused.TextInput.Placeholder.Copy().SetString("No files found."), + EmptyDirectory: theme.Focused.TextInput.Placeholder.SetString("No files found."), } return f diff --git a/go.mod b/go.mod index 839aba5e..ba26b953 100644 --- a/go.mod +++ b/go.mod @@ -6,9 +6,9 @@ require ( github.com/catppuccin/go v0.2.0 github.com/charmbracelet/bubbles v0.18.0 github.com/charmbracelet/bubbletea v0.26.1 - github.com/charmbracelet/lipgloss v0.10.0 - github.com/charmbracelet/x/exp/strings v0.0.0-20240403043919-dea9035a27d4 - github.com/charmbracelet/x/exp/term v0.0.0-20240321133156-7faadd06c281 + github.com/charmbracelet/lipgloss v0.10.1-0.20240506202754-3ee5dcab73cb + github.com/charmbracelet/x/exp/strings v0.0.0-20240506152644-8135bef4e495 + github.com/charmbracelet/x/exp/term v0.0.0-20240506152644-8135bef4e495 ) require ( @@ -26,7 +26,7 @@ require ( github.com/muesli/termenv v0.15.2 // indirect github.com/rivo/uniseg v0.4.7 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.19.0 // indirect - golang.org/x/term v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/term v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect ) diff --git a/go.sum b/go.sum index 6767b85a..9c2b79c0 100644 --- a/go.sum +++ b/go.sum @@ -10,10 +10,16 @@ github.com/charmbracelet/bubbletea v0.26.1 h1:xujcQeF73rh4jwu3+zhfQsvV18x+7zIjlw github.com/charmbracelet/bubbletea v0.26.1/go.mod h1:FzKr7sKoO8iFVcdIBM9J0sJOcQv5nDQaYwsee3kpbgo= github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s= github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE= +github.com/charmbracelet/lipgloss v0.10.1-0.20240506202754-3ee5dcab73cb h1:Hs3xzxHuruNT2Iuo87iS40c0PhLqpnUKBI6Xw6Ad3wQ= +github.com/charmbracelet/lipgloss v0.10.1-0.20240506202754-3ee5dcab73cb/go.mod h1:EPP2QJ0ectp3zo6gx9f8oJGq8keirqPJ3XpYEI8wrrs= github.com/charmbracelet/x/exp/strings v0.0.0-20240403043919-dea9035a27d4 h1:3hiHarKRDh7NF0mtD7iMjW0dHz4XKelswmRpFNR2lKw= github.com/charmbracelet/x/exp/strings v0.0.0-20240403043919-dea9035a27d4/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ= +github.com/charmbracelet/x/exp/strings v0.0.0-20240506152644-8135bef4e495 h1:/aQyDLa4ptexEC+jETEzgXNfMZety/g+niLB4eYsKhM= +github.com/charmbracelet/x/exp/strings v0.0.0-20240506152644-8135bef4e495/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ= github.com/charmbracelet/x/exp/term v0.0.0-20240321133156-7faadd06c281 h1:ZYwrF0GAd859tU6oF63T2pIkZVQ4z9BosDVD7jYu93A= github.com/charmbracelet/x/exp/term v0.0.0-20240321133156-7faadd06c281/go.mod h1:madZtB2OVDOG+ZnLruGITVZceYy047W+BLQ1MNQzbWg= +github.com/charmbracelet/x/exp/term v0.0.0-20240506152644-8135bef4e495 h1:+0U9qX8Pv8KiYgRxfBvORRjgBzLgHMjtElP4O0PyKYA= +github.com/charmbracelet/x/exp/term v0.0.0-20240506152644-8135bef4e495/go.mod h1:qeR6w1zITbkF7vEhcx0CqX5GfnIiQloJWQghN6HfP+c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= @@ -48,8 +54,14 @@ golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/huh_test.go b/huh_test.go index cdae761d..19552c4e 100644 --- a/huh_test.go +++ b/huh_test.go @@ -12,6 +12,7 @@ import ( ) var pretty = lipgloss.NewStyle(). + Width(60). Border(lipgloss.NormalBorder()). MarginTop(1). Padding(1, 3, 1, 2) @@ -120,7 +121,7 @@ func TestForm(t *testing.T) { // ↑ up • ↓ down • / filter • enter select // - if !strings.Contains(view, "Shell?") { + if !strings.Contains(view, "┃ Shell?") { t.Log(pretty.Render(view)) t.Error("Expected form to contain Shell? title") } diff --git a/theme.go b/theme.go index 11badd13..7541a070 100644 --- a/theme.go +++ b/theme.go @@ -17,26 +17,6 @@ type Theme struct { Help help.Styles } -// copy returns a copy of a theme with all children styles copied. -func (t Theme) copy() Theme { - return Theme{ - Form: t.Form.Copy(), - Group: t.Group.Copy(), - FieldSeparator: t.FieldSeparator.Copy(), - Blurred: t.Blurred.copy(), - Focused: t.Focused.copy(), - Help: help.Styles{ - Ellipsis: t.Help.Ellipsis.Copy(), - ShortKey: t.Help.ShortKey.Copy(), - ShortDesc: t.Help.ShortDesc.Copy(), - ShortSeparator: t.Help.ShortSeparator.Copy(), - FullKey: t.Help.FullKey.Copy(), - FullDesc: t.Help.FullDesc.Copy(), - FullSeparator: t.Help.FullSeparator.Copy(), - }, - } -} - // FieldStyles are the styles for input fields. type FieldStyles struct { Base lipgloss.Style @@ -83,44 +63,6 @@ type TextInputStyles struct { Text lipgloss.Style } -// copy returns a copy of a TextInputStyles with all children styles copied. -func (t TextInputStyles) copy() TextInputStyles { - return TextInputStyles{ - Cursor: t.Cursor.Copy(), - Placeholder: t.Placeholder.Copy(), - Prompt: t.Prompt.Copy(), - Text: t.Text.Copy(), - } -} - -// copy returns a copy of a FieldStyles with all children styles copied. -func (f FieldStyles) copy() FieldStyles { - return FieldStyles{ - Base: f.Base.Copy(), - Title: f.Title.Copy(), - Description: f.Description.Copy(), - ErrorIndicator: f.ErrorIndicator.Copy(), - ErrorMessage: f.ErrorMessage.Copy(), - SelectSelector: f.SelectSelector.Copy(), - NextIndicator: f.NextIndicator.Copy(), - PrevIndicator: f.PrevIndicator.Copy(), - Option: f.Option.Copy(), - Directory: f.Directory.Copy(), - File: f.File.Copy(), - MultiSelectSelector: f.MultiSelectSelector.Copy(), - SelectedOption: f.SelectedOption.Copy(), - SelectedPrefix: f.SelectedPrefix.Copy(), - UnselectedOption: f.UnselectedOption.Copy(), - UnselectedPrefix: f.UnselectedPrefix.Copy(), - FocusedButton: f.FocusedButton.Copy(), - BlurredButton: f.BlurredButton.Copy(), - TextInput: f.TextInput.copy(), - Card: f.Card.Copy(), - NoteTitle: f.NoteTitle.Copy(), - Next: f.Next.Copy(), - } -} - const ( buttonPaddingHorizontal = 2 buttonPaddingVertical = 0 @@ -138,43 +80,24 @@ func ThemeBase() *Theme { MarginRight(1) // Focused styles. - f := &t.Focused - f.Base = lipgloss.NewStyle(). - PaddingLeft(1). - BorderStyle(lipgloss.ThickBorder()). - BorderLeft(true) - f.Card = lipgloss.NewStyle(). - PaddingLeft(1) - f.ErrorIndicator = lipgloss.NewStyle(). - SetString(" *") - f.ErrorMessage = lipgloss.NewStyle(). - SetString(" *") - f.SelectSelector = lipgloss.NewStyle(). - SetString("> ") - f.NextIndicator = lipgloss.NewStyle(). - MarginLeft(1). - SetString("→") - f.PrevIndicator = lipgloss.NewStyle(). - MarginRight(1). - SetString("←") - f.MultiSelectSelector = lipgloss.NewStyle(). - SetString("> ") - f.SelectedPrefix = lipgloss.NewStyle(). - SetString("[•] ") - f.UnselectedPrefix = lipgloss.NewStyle(). - SetString("[ ] ") - f.FocusedButton = button.Copy(). - Foreground(lipgloss.Color("0")). - Background(lipgloss.Color("7")) - f.BlurredButton = button.Copy(). - Foreground(lipgloss.Color("7")). - Background(lipgloss.Color("0")) - f.TextInput.Placeholder = lipgloss.NewStyle().Foreground(lipgloss.Color("8")) + t.Focused.Base = lipgloss.NewStyle().PaddingLeft(1).BorderStyle(lipgloss.ThickBorder()).BorderLeft(true) + t.Focused.Card = lipgloss.NewStyle().PaddingLeft(1) + t.Focused.ErrorIndicator = lipgloss.NewStyle().SetString(" *") + t.Focused.ErrorMessage = lipgloss.NewStyle().SetString(" *") + t.Focused.SelectSelector = lipgloss.NewStyle().SetString("> ") + t.Focused.NextIndicator = lipgloss.NewStyle().MarginLeft(1).SetString("→") + t.Focused.PrevIndicator = lipgloss.NewStyle().MarginRight(1).SetString("←") + t.Focused.MultiSelectSelector = lipgloss.NewStyle().SetString("> ") + t.Focused.SelectedPrefix = lipgloss.NewStyle().SetString("[•] ") + t.Focused.UnselectedPrefix = lipgloss.NewStyle().SetString("[ ] ") + t.Focused.FocusedButton = button.Foreground(lipgloss.Color("0")).Background(lipgloss.Color("7")) + t.Focused.BlurredButton = button.Foreground(lipgloss.Color("7")).Background(lipgloss.Color("0")) + t.Focused.TextInput.Placeholder = lipgloss.NewStyle().Foreground(lipgloss.Color("8")) t.Help = help.New().Styles // Blurred styles. - t.Blurred = f.copy() + t.Blurred = t.Focused t.Blurred.Base = t.Blurred.Base.BorderStyle(lipgloss.HiddenBorder()) t.Blurred.MultiSelectSelector = lipgloss.NewStyle().SetString(" ") t.Blurred.NextIndicator = lipgloss.NewStyle() @@ -185,7 +108,7 @@ func ThemeBase() *Theme { // ThemeCharm returns a new theme based on the Charm color scheme. func ThemeCharm() *Theme { - t := ThemeBase().copy() + t := ThemeBase() var ( normalFg = lipgloss.AdaptiveColor{Light: "235", Dark: "252"} @@ -196,42 +119,41 @@ func ThemeCharm() *Theme { red = lipgloss.AdaptiveColor{Light: "#FF4672", Dark: "#ED567A"} ) - f := &t.Focused - f.Base = f.Base.BorderForeground(lipgloss.Color("238")) - f.Title.Foreground(indigo).Bold(true) - f.NoteTitle.Foreground(indigo).Bold(true).MarginBottom(1) - f.Directory.Foreground(indigo) - f.Description.Foreground(lipgloss.AdaptiveColor{Light: "", Dark: "243"}) - f.ErrorIndicator.Foreground(red) - f.ErrorMessage.Foreground(red) - f.SelectSelector.Foreground(fuchsia) - f.NextIndicator.Foreground(fuchsia) - f.PrevIndicator.Foreground(fuchsia) - f.Option.Foreground(normalFg) - f.MultiSelectSelector.Foreground(fuchsia) - f.SelectedOption.Foreground(green) - f.SelectedPrefix = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#02CF92", Dark: "#02A877"}).SetString("✓ ") - f.UnselectedPrefix = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "", Dark: "243"}).SetString("• ") - f.UnselectedOption.Foreground(normalFg) - f.FocusedButton.Foreground(cream).Background(fuchsia) - f.Next = f.FocusedButton.Copy() - f.BlurredButton.Foreground(normalFg).Background(lipgloss.AdaptiveColor{Light: "252", Dark: "237"}) - - f.TextInput.Cursor.Foreground(green) - f.TextInput.Placeholder.Foreground(lipgloss.AdaptiveColor{Light: "248", Dark: "238"}) - f.TextInput.Prompt.Foreground(fuchsia) - - t.Blurred = f.copy() - t.Blurred.Base.BorderStyle(lipgloss.HiddenBorder()) + t.Focused.Base = t.Focused.Base.BorderForeground(lipgloss.Color("238")) + t.Focused.Title = t.Focused.Title.Foreground(indigo).Bold(true) + t.Focused.NoteTitle = t.Focused.NoteTitle.Foreground(indigo).Bold(true).MarginBottom(1) + t.Focused.Directory = t.Focused.Directory.Foreground(indigo) + t.Focused.Description = t.Focused.Description.Foreground(lipgloss.AdaptiveColor{Light: "", Dark: "243"}) + t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.Foreground(red) + t.Focused.ErrorMessage = t.Focused.ErrorMessage.Foreground(red) + t.Focused.SelectSelector = t.Focused.SelectSelector.Foreground(fuchsia) + t.Focused.NextIndicator = t.Focused.NextIndicator.Foreground(fuchsia) + t.Focused.PrevIndicator = t.Focused.PrevIndicator.Foreground(fuchsia) + t.Focused.Option = t.Focused.Option.Foreground(normalFg) + t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.Foreground(fuchsia) + t.Focused.SelectedOption = t.Focused.SelectedOption.Foreground(green) + t.Focused.SelectedPrefix = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#02CF92", Dark: "#02A877"}).SetString("✓ ") + t.Focused.UnselectedPrefix = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "", Dark: "243"}).SetString("• ") + t.Focused.UnselectedOption = t.Focused.UnselectedOption.Foreground(normalFg) + t.Focused.FocusedButton = t.Focused.FocusedButton.Foreground(cream).Background(fuchsia) + t.Focused.Next = t.Focused.FocusedButton + t.Focused.BlurredButton = t.Focused.BlurredButton.Foreground(normalFg).Background(lipgloss.AdaptiveColor{Light: "252", Dark: "237"}) + + t.Focused.TextInput.Cursor = t.Focused.TextInput.Cursor.Foreground(green) + t.Focused.TextInput.Placeholder = t.Focused.TextInput.Placeholder.Foreground(lipgloss.AdaptiveColor{Light: "248", Dark: "238"}) + t.Focused.TextInput.Prompt = t.Focused.TextInput.Prompt.Foreground(fuchsia) + + t.Blurred = t.Focused + t.Blurred.Base = t.Focused.Base.BorderStyle(lipgloss.HiddenBorder()) t.Blurred.NextIndicator = lipgloss.NewStyle() t.Blurred.PrevIndicator = lipgloss.NewStyle() - return &t + return t } // ThemeDracula returns a new theme based on the Dracula color scheme. func ThemeDracula() *Theme { - t := ThemeBase().copy() + t := ThemeBase() var ( background = lipgloss.AdaptiveColor{Dark: "#282a36"} @@ -244,81 +166,81 @@ func ThemeDracula() *Theme { yellow = lipgloss.AdaptiveColor{Dark: "#f1fa8c"} ) - f := &t.Focused - f.Base.BorderForeground(selection) - f.Title.Foreground(purple) - f.NoteTitle.Foreground(purple) - f.Description.Foreground(comment) - f.ErrorIndicator.Foreground(red) - f.Directory.Foreground(purple) - f.File.Foreground(foreground) - f.ErrorMessage.Foreground(red) - f.SelectSelector.Foreground(yellow) - f.NextIndicator.Foreground(yellow) - f.PrevIndicator.Foreground(yellow) - f.Option.Foreground(foreground) - f.MultiSelectSelector.Foreground(yellow) - f.SelectedOption.Foreground(green) - f.SelectedPrefix.Foreground(green) - f.UnselectedOption.Foreground(foreground) - f.UnselectedPrefix.Foreground(comment) - f.FocusedButton.Foreground(yellow).Background(purple).Bold(true) - f.BlurredButton.Foreground(foreground).Background(background) - - f.TextInput.Cursor.Foreground(yellow) - f.TextInput.Placeholder.Foreground(comment) - f.TextInput.Prompt.Foreground(yellow) - - t.Blurred = f.copy() + t.Focused.Base = t.Focused.Base.BorderForeground(selection) + t.Focused.Title = t.Focused.Title.Foreground(purple) + t.Focused.NoteTitle = t.Focused.NoteTitle.Foreground(purple) + t.Focused.Description = t.Focused.Description.Foreground(comment) + t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.Foreground(red) + t.Focused.Directory = t.Focused.Directory.Foreground(purple) + t.Focused.File = t.Focused.File.Foreground(foreground) + t.Focused.ErrorMessage = t.Focused.ErrorMessage.Foreground(red) + t.Focused.SelectSelector = t.Focused.SelectSelector.Foreground(yellow) + t.Focused.NextIndicator = t.Focused.NextIndicator.Foreground(yellow) + t.Focused.PrevIndicator = t.Focused.PrevIndicator.Foreground(yellow) + t.Focused.Option = t.Focused.Option.Foreground(foreground) + t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.Foreground(yellow) + t.Focused.SelectedOption = t.Focused.SelectedOption.Foreground(green) + t.Focused.SelectedPrefix = t.Focused.SelectedPrefix.Foreground(green) + t.Focused.UnselectedOption = t.Focused.UnselectedOption.Foreground(foreground) + t.Focused.UnselectedPrefix = t.Focused.UnselectedPrefix.Foreground(comment) + t.Focused.FocusedButton = t.Focused.FocusedButton.Foreground(yellow).Background(purple).Bold(true) + t.Focused.BlurredButton = t.Focused.BlurredButton.Foreground(foreground).Background(background) + + t.Focused.TextInput.Cursor = t.Focused.TextInput.Cursor.Foreground(yellow) + t.Focused.TextInput.Placeholder = t.Focused.TextInput.Placeholder.Foreground(comment) + t.Focused.TextInput.Prompt = t.Focused.TextInput.Prompt.Foreground(yellow) + + t.Blurred = t.Focused t.Blurred.Base = t.Blurred.Base.BorderStyle(lipgloss.HiddenBorder()) t.Blurred.NextIndicator = lipgloss.NewStyle() t.Blurred.PrevIndicator = lipgloss.NewStyle() - return &t + return t } // ThemeBase16 returns a new theme based on the base16 color scheme. func ThemeBase16() *Theme { - t := ThemeBase().copy() - - f := &t.Focused - f.Base.BorderForeground(lipgloss.Color("8")) - f.Title.Foreground(lipgloss.Color("6")) - f.NoteTitle.Foreground(lipgloss.Color("6")) - f.Directory.Foreground(lipgloss.Color("6")) - f.Description.Foreground(lipgloss.Color("8")) - f.ErrorIndicator.Foreground(lipgloss.Color("9")) - f.ErrorMessage.Foreground(lipgloss.Color("9")) - f.SelectSelector.Foreground(lipgloss.Color("3")) - f.NextIndicator.Foreground(lipgloss.Color("3")) - f.PrevIndicator.Foreground(lipgloss.Color("3")) - f.Option.Foreground(lipgloss.Color("7")) - f.MultiSelectSelector.Foreground(lipgloss.Color("3")) - f.SelectedOption.Foreground(lipgloss.Color("2")) - f.SelectedPrefix.Foreground(lipgloss.Color("2")) - f.UnselectedOption.Foreground(lipgloss.Color("7")) - f.FocusedButton.Foreground(lipgloss.Color("7")).Background(lipgloss.Color("5")) - f.BlurredButton.Foreground(lipgloss.Color("7")).Background(lipgloss.Color("0")) - - f.TextInput.Cursor.Foreground(lipgloss.Color("5")) - f.TextInput.Placeholder.Foreground(lipgloss.Color("8")) - f.TextInput.Prompt.Foreground(lipgloss.Color("3")) - - t.Blurred = f.copy() + t := ThemeBase() + + t.Focused.Base = t.Focused.Base.BorderForeground(lipgloss.Color("8")) + t.Focused.Title = t.Focused.Title.Foreground(lipgloss.Color("6")) + t.Focused.NoteTitle = t.Focused.NoteTitle.Foreground(lipgloss.Color("6")) + t.Focused.Directory = t.Focused.Directory.Foreground(lipgloss.Color("6")) + t.Focused.Description = t.Focused.Description.Foreground(lipgloss.Color("8")) + t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.Foreground(lipgloss.Color("9")) + t.Focused.ErrorMessage = t.Focused.ErrorMessage.Foreground(lipgloss.Color("9")) + t.Focused.SelectSelector = t.Focused.SelectSelector.Foreground(lipgloss.Color("3")) + t.Focused.NextIndicator = t.Focused.NextIndicator.Foreground(lipgloss.Color("3")) + t.Focused.PrevIndicator = t.Focused.PrevIndicator.Foreground(lipgloss.Color("3")) + t.Focused.Option = t.Focused.Option.Foreground(lipgloss.Color("7")) + t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.Foreground(lipgloss.Color("3")) + t.Focused.SelectedOption = t.Focused.SelectedOption.Foreground(lipgloss.Color("2")) + t.Focused.SelectedPrefix = t.Focused.SelectedPrefix.Foreground(lipgloss.Color("2")) + t.Focused.UnselectedOption = t.Focused.UnselectedOption.Foreground(lipgloss.Color("7")) + t.Focused.FocusedButton = t.Focused.FocusedButton.Foreground(lipgloss.Color("7")).Background(lipgloss.Color("5")) + t.Focused.BlurredButton = t.Focused.BlurredButton.Foreground(lipgloss.Color("7")).Background(lipgloss.Color("0")) + + t.Focused.TextInput.Cursor.Foreground(lipgloss.Color("5")) + t.Focused.TextInput.Placeholder.Foreground(lipgloss.Color("8")) + t.Focused.TextInput.Prompt.Foreground(lipgloss.Color("3")) + + t.Blurred = t.Focused t.Blurred.Base = t.Blurred.Base.BorderStyle(lipgloss.HiddenBorder()) - t.Blurred.Title.Foreground(lipgloss.Color("8")) - t.Blurred.NoteTitle.Foreground(lipgloss.Color("8")) - t.Blurred.TextInput.Prompt.Foreground(lipgloss.Color("8")) - t.Blurred.TextInput.Text.Foreground(lipgloss.Color("7")) + t.Blurred.NoteTitle = t.Blurred.NoteTitle.Foreground(lipgloss.Color("8")) + t.Blurred.Title = t.Blurred.NoteTitle.Foreground(lipgloss.Color("8")) + + t.Blurred.TextInput.Prompt = t.Blurred.TextInput.Prompt.Foreground(lipgloss.Color("8")) + t.Blurred.TextInput.Text = t.Blurred.TextInput.Text.Foreground(lipgloss.Color("7")) + t.Blurred.NextIndicator = lipgloss.NewStyle() t.Blurred.PrevIndicator = lipgloss.NewStyle() - return &t + return t } // ThemeCatppuccin returns a new theme based on the Catppuccin color scheme. func ThemeCatppuccin() *Theme { - t := ThemeBase().copy() + t := ThemeBase() light := catppuccin.Latte dark := catppuccin.Mocha @@ -336,40 +258,39 @@ func ThemeCatppuccin() *Theme { cursor = lipgloss.AdaptiveColor{Light: light.Rosewater().Hex, Dark: dark.Rosewater().Hex} ) - f := &t.Focused - f.Base.BorderForeground(subtext1) - f.Title.Foreground(mauve) - f.NoteTitle.Foreground(mauve) - f.Directory.Foreground(mauve) - f.Description.Foreground(subtext0) - f.ErrorIndicator.Foreground(red) - f.ErrorMessage.Foreground(red) - f.SelectSelector.Foreground(pink) - f.NextIndicator.Foreground(pink) - f.PrevIndicator.Foreground(pink) - f.Option.Foreground(text) - f.MultiSelectSelector.Foreground(pink) - f.SelectedOption.Foreground(green) - f.SelectedPrefix.Foreground(green) - f.UnselectedPrefix.Foreground(text) - f.UnselectedOption.Foreground(text) - f.FocusedButton.Foreground(base).Background(pink) - f.BlurredButton.Foreground(text).Background(base) - - f.TextInput.Cursor.Foreground(cursor) - f.TextInput.Placeholder.Foreground(overlay0) - f.TextInput.Prompt.Foreground(pink) - - t.Blurred = f.copy() - t.Blurred.Base.BorderStyle(lipgloss.HiddenBorder()) - - t.Help.Ellipsis.Foreground(subtext0) - t.Help.ShortKey.Foreground(subtext0) - t.Help.ShortDesc.Foreground(overlay1) - t.Help.ShortSeparator.Foreground(subtext0) - t.Help.FullKey.Foreground(subtext0) - t.Help.FullDesc.Foreground(overlay1) - t.Help.FullSeparator.Foreground(subtext0) + t.Focused.Base = t.Focused.Base.BorderForeground(subtext1) + t.Focused.Title = t.Focused.Title.Foreground(mauve) + t.Focused.NoteTitle = t.Focused.NoteTitle.Foreground(mauve) + t.Focused.Directory = t.Focused.Directory.Foreground(mauve) + t.Focused.Description = t.Focused.Description.Foreground(subtext0) + t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.Foreground(red) + t.Focused.ErrorMessage = t.Focused.ErrorMessage.Foreground(red) + t.Focused.SelectSelector = t.Focused.SelectSelector.Foreground(pink) + t.Focused.NextIndicator = t.Focused.NextIndicator.Foreground(pink) + t.Focused.PrevIndicator = t.Focused.PrevIndicator.Foreground(pink) + t.Focused.Option = t.Focused.Option.Foreground(text) + t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.Foreground(pink) + t.Focused.SelectedOption = t.Focused.SelectedOption.Foreground(green) + t.Focused.SelectedPrefix = t.Focused.SelectedPrefix.Foreground(green) + t.Focused.UnselectedPrefix = t.Focused.UnselectedPrefix.Foreground(text) + t.Focused.UnselectedOption = t.Focused.UnselectedOption.Foreground(text) + t.Focused.FocusedButton = t.Focused.FocusedButton.Foreground(base).Background(pink) + t.Focused.BlurredButton = t.Focused.BlurredButton.Foreground(text).Background(base) + + t.Focused.TextInput.Cursor = t.Focused.TextInput.Cursor.Foreground(cursor) + t.Focused.TextInput.Placeholder = t.Focused.TextInput.Placeholder.Foreground(overlay0) + t.Focused.TextInput.Prompt = t.Focused.TextInput.Prompt.Foreground(pink) + + t.Blurred = t.Focused + t.Blurred.Base = t.Blurred.Base.BorderStyle(lipgloss.HiddenBorder()) - return &t + t.Help.Ellipsis = t.Help.Ellipsis.Foreground(subtext0) + t.Help.ShortKey = t.Help.ShortKey.Foreground(subtext0) + t.Help.ShortDesc = t.Help.ShortDesc.Foreground(overlay1) + t.Help.ShortSeparator = t.Help.ShortSeparator.Foreground(subtext0) + t.Help.FullKey = t.Help.FullKey.Foreground(subtext0) + t.Help.FullDesc = t.Help.FullDesc.Foreground(overlay1) + t.Help.FullSeparator = t.Help.FullSeparator.Foreground(subtext0) + + return t }