diff --git a/go.mod b/go.mod index fc5b693a..6c74148e 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,10 @@ go 1.18 require ( github.com/MakeNowJust/heredoc v1.0.0 github.com/atotto/clipboard v0.1.4 - github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.2 + github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.2.0.20241121171714-fbd5423ea935 github.com/charmbracelet/harmonica v0.2.0 - github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2 - github.com/charmbracelet/x/ansi v0.4.3 + github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2.0.20241121164047-8448a9be4804 + github.com/charmbracelet/x/ansi v0.5.1 github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 github.com/dustin/go-humanize v1.0.1 github.com/lucasb-eyer/go-colorful v1.2.0 @@ -21,16 +21,17 @@ require ( require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymanbagabas/go-udiff v0.2.0 // indirect - github.com/charmbracelet/colorprofile v0.1.6 // indirect - github.com/charmbracelet/x/cellbuf v0.0.3 // indirect - github.com/charmbracelet/x/term v0.2.0 // indirect - github.com/charmbracelet/x/wcwidth v0.0.0-20241011142426-46044092ad91 // indirect + github.com/charmbracelet/colorprofile v0.1.8 // indirect + github.com/charmbracelet/x/cellbuf v0.0.6 // indirect + github.com/charmbracelet/x/term v0.2.1 // indirect + github.com/charmbracelet/x/vt v0.0.0-20241121165045-a3720547cbb4 // indirect + github.com/charmbracelet/x/wcwidth v0.0.0-20241113152101-0af7d04e9f32 // indirect github.com/charmbracelet/x/windows v0.2.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect - golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.26.0 // indirect - golang.org/x/text v0.19.0 // indirect + golang.org/x/sync v0.9.0 // indirect + golang.org/x/sys v0.27.0 // indirect + golang.org/x/text v0.20.0 // indirect ) diff --git a/go.sum b/go.sum index 39d72cbb..dfc40798 100644 --- a/go.sum +++ b/go.sum @@ -6,24 +6,26 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8= github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA= -github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.2 h1:NkQFWhCii9NtL7Q0L/4mNKtZFgrDpfPSVZAzTwEJdGg= -github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.2/go.mod h1:24niqT9RbtXhWg8zLRU/v/xTixlo1+DUsHQZ3+kez5Y= -github.com/charmbracelet/colorprofile v0.1.6 h1:nMMqCns0c0DfCwNGdagBh6SxutFqkltSxxKk5S9kt+Y= -github.com/charmbracelet/colorprofile v0.1.6/go.mod h1:3EMXDxwRDJl0c17eJ1jX99MhtlP9OxE/9Qw0C5lvyUg= +github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.2.0.20241121171714-fbd5423ea935 h1:S+hhEwWnJxDeZMtHqIHgGVilNWsez3xmFOpwSc9GbcE= +github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.2.0.20241121171714-fbd5423ea935/go.mod h1:BbC4R+6e9TLjbskxrjISt/DDCn4OiB6v+ArqfYiPyyg= +github.com/charmbracelet/colorprofile v0.1.8 h1:PywDeXsiAzlPtkiiKgMEVLvb6nlEuKrMj9+FJBtj4jU= +github.com/charmbracelet/colorprofile v0.1.8/go.mod h1:+jpmObxZl1Dab3H3IMVIPSZTsKcFpjJUv97G0dLqM60= github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ= github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao= -github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2 h1:Gp+S9hMymU6HmxD1dihbnoMOGwt6wDMMvf0jyw3gEc0= -github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2/go.mod h1:72/7KVsLdRldv/CeBjZx6igXIZ9CFtBzQUmDEbhXZ3w= -github.com/charmbracelet/x/ansi v0.4.3 h1:wcdDrW0ejaaZGJxCyxVNzzmctqV+oARIudaFGQvsRkA= -github.com/charmbracelet/x/ansi v0.4.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= -github.com/charmbracelet/x/cellbuf v0.0.3 h1:HapUUjlo0pZ7iGijrTer1f4X8Uvq17l0zR+80Oh+iJg= -github.com/charmbracelet/x/cellbuf v0.0.3/go.mod h1:SF8R3AqchNzYKKJCFT7co8wt1HgQDfAitQ+SBoxWLNc= +github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2.0.20241121164047-8448a9be4804 h1:7CYjb9YMZA4kMhLgGdtlXvq+nu1oyENpMyMQlTvqSFw= +github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2.0.20241121164047-8448a9be4804/go.mod h1:F/6E/LGdH3eHCJf2rG8/O3CjlW8cZFL5YJCknJs1GkI= +github.com/charmbracelet/x/ansi v0.5.1 h1:+mg6abP9skvsu/JQZrIJ9Z/4O1YDnLVkpfutar3dUnc= +github.com/charmbracelet/x/ansi v0.5.1/go.mod h1:KBUFw1la39nl0dLl10l5ORDAqGXaeurTQmwyyVKse/Q= +github.com/charmbracelet/x/cellbuf v0.0.6 h1:pJUWN/G1jbt1Nj/+ILfC2/ABQoZzWu1vG73yHQEYELI= +github.com/charmbracelet/x/cellbuf v0.0.6/go.mod h1:d72o71glp8flkCz54PHLe3+nuw5u2v3UxmKqruUERWQ= github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ= github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= -github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0= -github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0= -github.com/charmbracelet/x/wcwidth v0.0.0-20241011142426-46044092ad91 h1:D5OO0lVavz7A+Swdhp62F9gbkibxmz9B2hZ/jVdMPf0= -github.com/charmbracelet/x/wcwidth v0.0.0-20241011142426-46044092ad91/go.mod h1:Ey8PFmYwH+/td9bpiEx07Fdx9ZVkxfIjWXxBluxF4Nw= +github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= +github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= +github.com/charmbracelet/x/vt v0.0.0-20241121165045-a3720547cbb4 h1:EacjHxcQEEgOZ7TbkAU3b84hd1Bn5NwA8YV5uyJ9EI4= +github.com/charmbracelet/x/vt v0.0.0-20241121165045-a3720547cbb4/go.mod h1:1/jFoHl7/I4br0StC9OXXEondkK9qi3nUtKoqI35HcI= +github.com/charmbracelet/x/wcwidth v0.0.0-20241113152101-0af7d04e9f32 h1:14czE6R5CgOlvONsJYa2B1uTyLvXzGXpBqw2AyZeTh4= +github.com/charmbracelet/x/wcwidth v0.0.0-20241113152101-0af7d04e9f32/go.mod h1:hyua5CY63kyl7IfyIxv1SjVEqoKze/XmDkEglItuVjA= github.com/charmbracelet/x/windows v0.2.0 h1:ilXA1GJjTNkgOm94CLPeSz7rar54jtFatdmoiONPuEw= github.com/charmbracelet/x/windows v0.2.0/go.mod h1:ZibNFR49ZFqCXgP76sYanisxRyC+EYrBE7TTknD8s1s= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= @@ -48,10 +50,10 @@ github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8 github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= +golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= -golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= +golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= diff --git a/help/help.go b/help/help.go index 11dc0c72..e2cd44a0 100644 --- a/help/help.go +++ b/help/help.go @@ -47,9 +47,9 @@ type Styles struct { func DefaultStyles(isDark bool) Styles { lightDark := lipgloss.LightDark(isDark) - keyStyle := lipgloss.NewStyle().Foreground(lightDark("#909090", "#626262")) - descStyle := lipgloss.NewStyle().Foreground(lightDark("#B2B2B2", "#4A4A4A")) - sepStyle := lipgloss.NewStyle().Foreground(lightDark("#DADADA", "#3C3C3C")) + keyStyle := lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("#909090"), lipgloss.Color("#626262"))) + descStyle := lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("#B2B2B2"), lipgloss.Color("#4A4A4A"))) + sepStyle := lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("#DADADA"), lipgloss.Color("#3C3C3C"))) return Styles{ ShortKey: keyStyle, diff --git a/list/defaultitem.go b/list/defaultitem.go index e28d1a02..20572940 100644 --- a/list/defaultitem.go +++ b/list/defaultitem.go @@ -36,27 +36,27 @@ func NewDefaultItemStyles(isDark bool) (s DefaultItemStyles) { lightDark := lipgloss.LightDark(isDark) s.NormalTitle = lipgloss.NewStyle(). - Foreground(lightDark("#1a1a1a", "#dddddd")). + Foreground(lightDark(lipgloss.Color("#1a1a1a"), lipgloss.Color("#dddddd"))). Padding(0, 0, 0, 2) //nolint:mnd s.NormalDesc = s.NormalTitle. - Foreground(lightDark("#A49FA5", "#777777")) + Foreground(lightDark(lipgloss.Color("#A49FA5"), lipgloss.Color("#777777"))) s.SelectedTitle = lipgloss.NewStyle(). Border(lipgloss.NormalBorder(), false, false, false, true). - BorderForeground(lightDark("#F793FF", "#AD58B4")). - Foreground(lightDark("#EE6FF8", "#EE6FF8")). + BorderForeground(lightDark(lipgloss.Color("#F793FF"), lipgloss.Color("#AD58B4"))). + Foreground(lightDark(lipgloss.Color("#EE6FF8"), lipgloss.Color("#EE6FF8"))). Padding(0, 0, 0, 1) s.SelectedDesc = s.SelectedTitle. - Foreground(lightDark("#F793FF", "#AD58B4")) + Foreground(lightDark(lipgloss.Color("#F793FF"), lipgloss.Color("#AD58B4"))) s.DimmedTitle = lipgloss.NewStyle(). - Foreground(lightDark("#A49FA5", "#777777")). + Foreground(lightDark(lipgloss.Color("#A49FA5"), lipgloss.Color("#777777"))). Padding(0, 0, 0, 2) //nolint:mnd s.DimmedDesc = s.DimmedTitle. - Foreground(lightDark("#C2B8C2", "#4D4D4D")) + Foreground(lightDark(lipgloss.Color("#C2B8C2"), lipgloss.Color("#4D4D4D"))) s.FilterMatch = lipgloss.NewStyle().Underline(true) diff --git a/list/style.go b/list/style.go index 20843903..60b1c889 100644 --- a/list/style.go +++ b/list/style.go @@ -44,8 +44,8 @@ type Styles struct { func DefaultStyles(isDark bool) (s Styles) { lightDark := lipgloss.LightDark(isDark) - verySubduedColor := lightDark("#DDDADA", "#3C3C3C") - subduedColor := lightDark("#9B9B9B", "#5C5C5C") + verySubduedColor := lightDark(lipgloss.Color("#DDDADA"), lipgloss.Color("#3C3C3C")) + subduedColor := lightDark(lipgloss.Color("#9B9B9B"), lipgloss.Color("#5C5C5C")) s.TitleBar = lipgloss.NewStyle().Padding(0, 0, 1, 2) //nolint:mnd @@ -55,29 +55,29 @@ func DefaultStyles(isDark bool) (s Styles) { Padding(0, 1) s.Spinner = lipgloss.NewStyle(). - Foreground(lightDark("#8E8E8E", "#747373")) + Foreground(lightDark(lipgloss.Color("#8E8E8E"), lipgloss.Color("#747373"))) s.FilterPrompt = lipgloss.NewStyle(). - Foreground(lightDark("#04B575", "#ECFD65")) + Foreground(lightDark(lipgloss.Color("#04B575"), lipgloss.Color("#ECFD65"))) s.FilterCursor = lipgloss.NewStyle(). - Foreground(lightDark("#EE6FF8", "#EE6FF8")) + Foreground(lightDark(lipgloss.Color("#EE6FF8"), lipgloss.Color("#EE6FF8"))) s.DefaultFilterCharacterMatch = lipgloss.NewStyle().Underline(true) s.StatusBar = lipgloss.NewStyle(). - Foreground(lightDark("#A49FA5", "#777777")). + Foreground(lightDark(lipgloss.Color("#A49FA5"), lipgloss.Color("#777777"))). Padding(0, 0, 1, 2) //nolint:mnd s.StatusEmpty = lipgloss.NewStyle().Foreground(subduedColor) s.StatusBarActiveFilter = lipgloss.NewStyle(). - Foreground(lightDark("#1a1a1a", "#dddddd")) + Foreground(lightDark(lipgloss.Color("#1a1a1a"), lipgloss.Color("#dddddd"))) s.StatusBarFilterCount = lipgloss.NewStyle().Foreground(verySubduedColor) s.NoItems = lipgloss.NewStyle(). - Foreground(lightDark("#909090", "#626262")) + Foreground(lightDark(lipgloss.Color("#909090"), lipgloss.Color("#626262"))) s.ArabicPagination = lipgloss.NewStyle().Foreground(subduedColor) @@ -86,7 +86,7 @@ func DefaultStyles(isDark bool) (s Styles) { s.HelpStyle = lipgloss.NewStyle().Padding(1, 0, 0, 2) //nolint:mnd s.ActivePaginationDot = lipgloss.NewStyle(). - Foreground(lightDark("#847A85", "#979797")). + Foreground(lightDark(lipgloss.Color("#847A85"), lipgloss.Color("#979797"))). SetString(bullet) s.InactivePaginationDot = lipgloss.NewStyle(). diff --git a/textarea/textarea.go b/textarea/textarea.go index ee905de7..c792d246 100644 --- a/textarea/textarea.go +++ b/textarea/textarea.go @@ -24,9 +24,12 @@ const ( minHeight = 1 defaultHeight = 6 defaultWidth = 40 - defaultCharLimit = 400 + defaultCharLimit = 0 // no limit defaultMaxHeight = 99 defaultMaxWidth = 500 + + // XXX: in v2, make max lines dynamic and default max lines configurable. + maxLines = 10000 ) // Internal messages for clipboard operations. @@ -305,13 +308,13 @@ func New() Model { Prompt: lipgloss.ThickBorder().Left + " ", Styles: styles, activeStyle: &styles.Blurred, - cache: memoization.NewMemoCache[line, [][]rune](defaultMaxHeight), + cache: memoization.NewMemoCache[line, [][]rune](maxLines), EndOfBufferCharacter: ' ', ShowLineNumbers: true, Cursor: cur, KeyMap: DefaultKeyMap(), - value: make([][]rune, minHeight, defaultMaxHeight), + value: make([][]rune, minHeight, maxLines), focus: false, col: 0, row: 0, @@ -333,23 +336,23 @@ func DefaultStyles(isDark bool) Styles { var s Styles s.Focused = StyleState{ Base: lipgloss.NewStyle(), - CursorLine: lipgloss.NewStyle().Background(lightDark("255", "0")), - CursorLineNumber: lipgloss.NewStyle().Foreground(lightDark("240", "240")), - EndOfBuffer: lipgloss.NewStyle().Foreground(lightDark("254", "0")), - LineNumber: lipgloss.NewStyle().Foreground(lightDark("249", "7")), + CursorLine: lipgloss.NewStyle().Background(lightDark(lipgloss.Color("255"), lipgloss.Color("0"))), + CursorLineNumber: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("240"), lipgloss.Color("240"))), + EndOfBuffer: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("254"), lipgloss.Color("0"))), + LineNumber: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("249"), lipgloss.Color("7"))), Placeholder: lipgloss.NewStyle().Foreground(lipgloss.Color("240")), Prompt: lipgloss.NewStyle().Foreground(lipgloss.Color("7")), Text: lipgloss.NewStyle(), } s.Blurred = StyleState{ Base: lipgloss.NewStyle(), - CursorLine: lipgloss.NewStyle().Foreground(lightDark("245", "7")), - CursorLineNumber: lipgloss.NewStyle().Foreground(lightDark("249", "7")), - EndOfBuffer: lipgloss.NewStyle().Foreground(lightDark("254", "0")), - LineNumber: lipgloss.NewStyle().Foreground(lightDark("249", "7")), + CursorLine: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("245"), lipgloss.Color("7"))), + CursorLineNumber: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("249"), lipgloss.Color("7"))), + EndOfBuffer: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("254"), lipgloss.Color("0"))), + LineNumber: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("249"), lipgloss.Color("7"))), Placeholder: lipgloss.NewStyle().Foreground(lipgloss.Color("240")), Prompt: lipgloss.NewStyle().Foreground(lipgloss.Color("7")), - Text: lipgloss.NewStyle().Foreground(lightDark("245", "7")), + Text: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("245"), lipgloss.Color("7"))), } return s } @@ -392,9 +395,8 @@ func (m *Model) insertRunesFromUserInput(runes []rune) { // whatnot. runes = m.san().Sanitize(runes) - var availSpace int if m.CharLimit > 0 { - availSpace = m.CharLimit - m.Length() + availSpace := m.CharLimit - m.Length() // If the char limit's been reached, cancel. if availSpace <= 0 { return @@ -425,9 +427,9 @@ func (m *Model) insertRunesFromUserInput(runes []rune) { lines = append(lines, runes[lstart:]) } - // Obey the maximum height limit. - if m.MaxHeight > 0 && len(m.value)+len(lines)-1 > m.MaxHeight { - allowedHeight := max(0, m.MaxHeight-len(m.value)+1) + // Obey the maximum line limit. + if maxLines > 0 && len(m.value)+len(lines)-1 > maxLines { + allowedHeight := max(0, maxLines-len(m.value)+1) lines = lines[:allowedHeight] } @@ -622,11 +624,7 @@ func (m *Model) Blur() { // Reset sets the input to its default state with no input. func (m *Model) Reset() { - startCap := m.MaxHeight - if startCap <= 0 { - startCap = defaultMaxHeight - } - m.value = make([][]rune, minHeight, startCap) + m.value = make([][]rune, minHeight, maxLines) m.col = 0 m.row = 0 m.realCol = 0