From a9b780a96c9796826dcad68ea14f5050d613b1cf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:28:20 +0000 Subject: [PATCH 1/4] feat(deps): bump github.com/charmbracelet/lipgloss from 0.13.0 to 0.13.1 Bumps [github.com/charmbracelet/lipgloss](https://github.com/charmbracelet/lipgloss) from 0.13.0 to 0.13.1. - [Release notes](https://github.com/charmbracelet/lipgloss/releases) - [Changelog](https://github.com/charmbracelet/lipgloss/blob/master/.goreleaser.yml) - [Commits](https://github.com/charmbracelet/lipgloss/compare/v0.13.0...v0.13.1) --- updated-dependencies: - dependency-name: github.com/charmbracelet/lipgloss dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 95d681773..13ee2147e 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/atotto/clipboard v0.1.4 github.com/charmbracelet/bubbletea v1.1.1 github.com/charmbracelet/harmonica v0.2.0 - github.com/charmbracelet/lipgloss v0.13.0 + github.com/charmbracelet/lipgloss v0.13.1 github.com/charmbracelet/x/ansi v0.3.2 github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 github.com/dustin/go-humanize v1.0.1 diff --git a/go.sum b/go.sum index bbb72b1ef..8411f1efc 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/charmbracelet/bubbletea v1.1.1 h1:KJ2/DnmpfqFtDNVTvYZ6zpPFL9iRCRr0qqK github.com/charmbracelet/bubbletea v1.1.1/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4= 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 v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw= -github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY= +github.com/charmbracelet/lipgloss v0.13.1 h1:Oik/oqDTMVA01GetT4JdEC033dNzWoQHdWnHnQmXE2A= +github.com/charmbracelet/lipgloss v0.13.1/go.mod h1:zaYVJ2xKSKEnTEEbX6uAHabh2d975RJ+0yfkFpRBz5U= github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY= github.com/charmbracelet/x/ansi v0.3.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ= From 358a6c58c88c1f9ecef350f1d5db775cdbdd7283 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 24 Oct 2024 12:09:01 -0400 Subject: [PATCH 2/4] chore(lint): fix and suppress all soft lint issues; update directives --- filepicker/filepicker.go | 2 +- list/defaultitem.go | 10 ++++++---- list/list.go | 12 ++++++------ list/style.go | 8 ++++---- paginator/paginator.go | 2 +- progress/progress.go | 2 +- spinner/spinner.go | 24 ++++++++++++------------ table/table.go | 6 +++--- textarea/textarea.go | 12 +++++++----- textinput/textinput.go | 4 ++-- viewport/viewport.go | 6 +++--- 11 files changed, 46 insertions(+), 42 deletions(-) diff --git a/filepicker/filepicker.go b/filepicker/filepicker.go index 57fe02d5f..113c6c963 100644 --- a/filepicker/filepicker.go +++ b/filepicker/filepicker.go @@ -379,7 +379,7 @@ func (m Model) View() string { disabled := !m.canSelect(name) && !f.IsDir() - if m.selected == i { + if m.selected == i { //nolint:nestif selected := "" if m.ShowPermissions { selected += " " + info.Mode().String() diff --git a/list/defaultitem.go b/list/defaultitem.go index 763dad1c8..4affe342a 100644 --- a/list/defaultitem.go +++ b/list/defaultitem.go @@ -35,7 +35,7 @@ type DefaultItemStyles struct { func NewDefaultItemStyles() (s DefaultItemStyles) { s.NormalTitle = lipgloss.NewStyle(). Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#dddddd"}). - Padding(0, 0, 0, 2) + Padding(0, 0, 0, 2) //nolint:mnd s.NormalDesc = s.NormalTitle. Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"}) @@ -51,7 +51,7 @@ func NewDefaultItemStyles() (s DefaultItemStyles) { s.DimmedTitle = lipgloss.NewStyle(). Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"}). - Padding(0, 0, 0, 2) + Padding(0, 0, 0, 2) //nolint:mnd s.DimmedDesc = s.DimmedTitle. Foreground(lipgloss.AdaptiveColor{Light: "#C2B8C2", Dark: "#4D4D4D"}) @@ -93,11 +93,13 @@ type DefaultDelegate struct { // NewDefaultDelegate creates a new delegate with default styles. func NewDefaultDelegate() DefaultDelegate { + const defaultHeight = 2 + const defaultSpacing = 1 return DefaultDelegate{ ShowDescription: true, Styles: NewDefaultItemStyles(), - height: 2, - spacing: 1, + height: defaultHeight, + spacing: defaultSpacing, } } diff --git a/list/list.go b/list/list.go index 9ee1643d3..6808142b3 100644 --- a/list/list.go +++ b/list/list.go @@ -273,7 +273,7 @@ func (m *Model) SetShowTitle(v bool) { // SetFilterText explicitly sets the filter text without relying on user input. // It also sets the filterState to a sane default of FilterApplied, but this -// can be changed with SetFilterState +// can be changed with SetFilterState. func (m *Model) SetFilterText(filter string) { m.filterState = Filtering m.FilterInput.SetValue(filter) @@ -289,7 +289,7 @@ func (m *Model) SetFilterText(filter string) { m.updateKeybindings() } -// Helper method for setting the filtering state manually +// Helper method for setting the filtering state manually. func (m *Model) SetFilterState(state FilterState) { m.Paginator.Page = 0 m.cursor = 0 @@ -722,7 +722,7 @@ func (m Model) itemsAsFilterItems() filteredItems { // Set keybindings according to the filter state. func (m *Model) updateKeybindings() { - switch m.filterState { + switch m.filterState { //nolint:exhaustive case Filtering: m.KeyMap.CursorUp.SetEnabled(false) m.KeyMap.CursorDown.SetEnabled(false) @@ -1153,7 +1153,7 @@ func (m Model) statusView() string { itemsDisplay := fmt.Sprintf("%d %s", visibleItems, itemName) - if m.filterState == Filtering { + if m.filterState == Filtering { //nolint:nestif // Filter results if visibleItems == 0 { status = m.Styles.StatusEmpty.Render("Nothing matched") @@ -1169,7 +1169,7 @@ func (m Model) statusView() string { if filtered { f := strings.TrimSpace(m.FilterInput.Value()) - f = ansi.Truncate(f, 10, "…") + f = ansi.Truncate(f, 10, "…") //nolint:mnd status += fmt.Sprintf("“%s” ", f) } @@ -1186,7 +1186,7 @@ func (m Model) statusView() string { } func (m Model) paginationView() string { - if m.Paginator.TotalPages < 2 { //nolint:gomnd + if m.Paginator.TotalPages < 2 { //nolint:mnd return "" } diff --git a/list/style.go b/list/style.go index e4451f87b..e663c07b8 100644 --- a/list/style.go +++ b/list/style.go @@ -45,7 +45,7 @@ func DefaultStyles() (s Styles) { verySubduedColor := lipgloss.AdaptiveColor{Light: "#DDDADA", Dark: "#3C3C3C"} subduedColor := lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"} - s.TitleBar = lipgloss.NewStyle().Padding(0, 0, 1, 2) + s.TitleBar = lipgloss.NewStyle().Padding(0, 0, 1, 2) //nolint:mnd s.Title = lipgloss.NewStyle(). Background(lipgloss.Color("62")). @@ -65,7 +65,7 @@ func DefaultStyles() (s Styles) { s.StatusBar = lipgloss.NewStyle(). Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"}). - Padding(0, 0, 1, 2) + Padding(0, 0, 1, 2) //nolint:mnd s.StatusEmpty = lipgloss.NewStyle().Foreground(subduedColor) @@ -79,9 +79,9 @@ func DefaultStyles() (s Styles) { s.ArabicPagination = lipgloss.NewStyle().Foreground(subduedColor) - s.PaginationStyle = lipgloss.NewStyle().PaddingLeft(2) //nolint:gomnd + s.PaginationStyle = lipgloss.NewStyle().PaddingLeft(2) //nolint:mnd - s.HelpStyle = lipgloss.NewStyle().Padding(1, 0, 0, 2) + s.HelpStyle = lipgloss.NewStyle().Padding(1, 0, 0, 2) //nolint:mnd s.ActivePaginationDot = lipgloss.NewStyle(). Foreground(lipgloss.AdaptiveColor{Light: "#847A85", Dark: "#979797"}). diff --git a/paginator/paginator.go b/paginator/paginator.go index de05a85bc..961b4e560 100644 --- a/paginator/paginator.go +++ b/paginator/paginator.go @@ -189,7 +189,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { // View renders the pagination to a string. func (m Model) View() string { - switch m.Type { + switch m.Type { //nolint:exhaustive case Dots: return m.dotsView() default: diff --git a/progress/progress.go b/progress/progress.go index cf3dbb4af..cfd18cb56 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -335,7 +335,7 @@ func (m Model) percentageView(percent float64) string { return "" } percent = math.Max(0, math.Min(1, percent)) - percentage := fmt.Sprintf(m.PercentFormat, percent*100) //nolint:gomnd + percentage := fmt.Sprintf(m.PercentFormat, percent*100) //nolint:mnd percentage = m.PercentageStyle.Inline(true).Render(percentage) return percentage } diff --git a/spinner/spinner.go b/spinner/spinner.go index 7138af1bc..ac6e34aba 100644 --- a/spinner/spinner.go +++ b/spinner/spinner.go @@ -26,39 +26,39 @@ type Spinner struct { var ( Line = Spinner{ Frames: []string{"|", "/", "-", "\\"}, - FPS: time.Second / 10, //nolint:gomnd + FPS: time.Second / 10, //nolint:mnd } Dot = Spinner{ Frames: []string{"⣾ ", "⣽ ", "⣻ ", "⢿ ", "⡿ ", "⣟ ", "⣯ ", "⣷ "}, - FPS: time.Second / 10, //nolint:gomnd + FPS: time.Second / 10, //nolint:mnd } MiniDot = Spinner{ Frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}, - FPS: time.Second / 12, //nolint:gomnd + FPS: time.Second / 12, //nolint:mnd } Jump = Spinner{ Frames: []string{"⢄", "⢂", "⢁", "⡁", "⡈", "⡐", "⡠"}, - FPS: time.Second / 10, //nolint:gomnd + FPS: time.Second / 10, //nolint:mnd } Pulse = Spinner{ Frames: []string{"█", "▓", "▒", "░"}, - FPS: time.Second / 8, //nolint:gomnd + FPS: time.Second / 8, //nolint:mnd } Points = Spinner{ Frames: []string{"∙∙∙", "●∙∙", "∙●∙", "∙∙●"}, - FPS: time.Second / 7, //nolint:gomnd + FPS: time.Second / 7, //nolint:mnd } Globe = Spinner{ Frames: []string{"🌍", "🌎", "🌏"}, - FPS: time.Second / 4, //nolint:gomnd + FPS: time.Second / 4, //nolint:mnd } Moon = Spinner{ Frames: []string{"🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘"}, - FPS: time.Second / 8, //nolint:gomnd + FPS: time.Second / 8, //nolint:mnd } Monkey = Spinner{ Frames: []string{"🙈", "🙉", "🙊"}, - FPS: time.Second / 3, //nolint:gomnd + FPS: time.Second / 3, //nolint:mnd } Meter = Spinner{ Frames: []string{ @@ -70,15 +70,15 @@ var ( "▰▱▱", "▱▱▱", }, - FPS: time.Second / 7, //nolint:gomnd + FPS: time.Second / 7, //nolint:mnd } Hamburger = Spinner{ Frames: []string{"☱", "☲", "☴", "☲"}, - FPS: time.Second / 3, //nolint:gomnd + FPS: time.Second / 3, //nolint:mnd } Ellipsis = Spinner{ Frames: []string{"", ".", "..", "..."}, - FPS: time.Second / 3, //nolint:gomnd + FPS: time.Second / 3, //nolint:mnd } ) diff --git a/table/table.go b/table/table.go index 73687b97b..d68b626ff 100644 --- a/table/table.go +++ b/table/table.go @@ -133,7 +133,7 @@ type Option func(*Model) func New(opts ...Option) Model { m := Model{ cursor: 0, - viewport: viewport.New(0, 20), + viewport: viewport.New(0, 20), //nolint:mnd KeyMap: DefaultKeyMap(), Help: help.New(), @@ -216,9 +216,9 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { case key.Matches(msg, m.KeyMap.PageDown): m.MoveDown(m.viewport.Height) case key.Matches(msg, m.KeyMap.HalfPageUp): - m.MoveUp(m.viewport.Height / 2) + m.MoveUp(m.viewport.Height / 2) //nolint:mnd case key.Matches(msg, m.KeyMap.HalfPageDown): - m.MoveDown(m.viewport.Height / 2) + m.MoveDown(m.viewport.Height / 2) //nolint:mnd case key.Matches(msg, m.KeyMap.GotoTop): m.GotoTop() case key.Matches(msg, m.KeyMap.GotoBottom): diff --git a/textarea/textarea.go b/textarea/textarea.go index 153f39ef3..95c435156 100644 --- a/textarea/textarea.go +++ b/textarea/textarea.go @@ -492,7 +492,8 @@ func (m *Model) CursorDown() { // Move the cursor to the start of the next line so that we can get // the line information. We need to add 2 columns to account for the // trailing space wrapping. - m.col = min(li.StartColumn+li.Width+2, len(m.value[m.row])-1) + const trailingSpace = 2 + m.col = min(li.StartColumn+li.Width+trailingSpace, len(m.value[m.row])-1) } nli := m.LineInfo() @@ -526,7 +527,8 @@ func (m *Model) CursorUp() { // This can be done by moving the cursor to the start of the line and // then subtracting 2 to account for the trailing space we keep on // soft-wrapped lines. - m.col = li.StartColumn - 2 + const trailingSpace = 2 + m.col = li.StartColumn - trailingSpace } nli := m.LineInfo() @@ -1119,7 +1121,7 @@ func (m Model) View() string { displayLine++ var ln string - if m.ShowLineNumbers { + if m.ShowLineNumbers { //nolint:nestif if wl == 0 { if m.row == l { ln = style.Render(m.style.computedCursorLineNumber().Render(m.formatLineNumber(l + 1))) @@ -1198,7 +1200,7 @@ func (m Model) View() string { } // formatLineNumber formats the line number for display dynamically based on -// the maximum number of lines +// the maximum number of lines. func (m Model) formatLineNumber(x any) string { // XXX: ultimately we should use a max buffer height, which has yet to be // implemented. @@ -1407,7 +1409,7 @@ func wrap(runes []rune, width int) [][]rune { word = append(word, r) } - if spaces > 0 { + if spaces > 0 { //nolint:nestif if uniseg.StringWidth(string(lines[row]))+uniseg.StringWidth(string(word))+spaces > width { row++ lines = append(lines, []rune{}) diff --git a/textinput/textinput.go b/textinput/textinput.go index cf944b89f..d1abf1247 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -565,7 +565,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { // Let's remember where the position of the cursor currently is so that if // the cursor position changes, we can reset the blink. - oldPos := m.pos //nolint + oldPos := m.pos switch msg := msg.(type) { case tea.KeyMsg: @@ -658,7 +658,7 @@ func (m Model) View() string { pos := max(0, m.pos-m.offset) v := styleText(m.echoTransform(string(value[:pos]))) - if pos < len(value) { + if pos < len(value) { //nolint:nestif char := m.echoTransform(string(value[pos])) m.Cursor.SetChar(char) v += m.Cursor.View() // cursor and text under it diff --git a/viewport/viewport.go b/viewport/viewport.go index 1d2423a6e..f220d1eb6 100644 --- a/viewport/viewport.go +++ b/viewport/viewport.go @@ -168,7 +168,7 @@ func (m *Model) HalfViewDown() (lines []string) { return nil } - return m.LineDown(m.Height / 2) + return m.LineDown(m.Height / 2) //nolint:mnd } // HalfViewUp moves the view up by half the height of the viewport. @@ -177,7 +177,7 @@ func (m *Model) HalfViewUp() (lines []string) { return nil } - return m.LineUp(m.Height / 2) + return m.LineUp(m.Height / 2) //nolint:mnd } // LineDown moves the view down by the given number of lines. @@ -350,7 +350,7 @@ func (m Model) updateAsModel(msg tea.Msg) (Model, tea.Cmd) { if !m.MouseWheelEnabled || msg.Action != tea.MouseActionPress { break } - switch msg.Button { + switch msg.Button { //nolint:exhaustive case tea.MouseButtonWheelUp: lines := m.LineUp(m.MouseWheelDelta) if m.HighPerformanceRendering { From 4e05c24fc4acdb5b384ff4b577f6c5ba9d6e7dad Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 24 Oct 2024 15:21:20 -0400 Subject: [PATCH 3/4] chore: move runeutil and memoization into internal --- {textarea => internal}/memoization/memoization.go | 2 ++ {textarea => internal}/memoization/memoization_test.go | 0 {runeutil => internal/runeutil}/runeutil.go | 4 ++-- {runeutil => internal/runeutil}/runeutil_test.go | 0 textarea/textarea.go | 4 ++-- textinput/textinput.go | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) rename {textarea => internal}/memoization/memoization.go (97%) rename {textarea => internal}/memoization/memoization_test.go (100%) rename {runeutil => internal/runeutil}/runeutil.go (95%) rename {runeutil => internal/runeutil}/runeutil_test.go (100%) diff --git a/textarea/memoization/memoization.go b/internal/memoization/memoization.go similarity index 97% rename from textarea/memoization/memoization.go rename to internal/memoization/memoization.go index ccb80a9f1..46c347a67 100644 --- a/textarea/memoization/memoization.go +++ b/internal/memoization/memoization.go @@ -1,3 +1,5 @@ +// Package memoization implement a simple memoization cache. It's designed to +// improve performance in textarea. package memoization import ( diff --git a/textarea/memoization/memoization_test.go b/internal/memoization/memoization_test.go similarity index 100% rename from textarea/memoization/memoization_test.go rename to internal/memoization/memoization_test.go diff --git a/runeutil/runeutil.go b/internal/runeutil/runeutil.go similarity index 95% rename from runeutil/runeutil.go rename to internal/runeutil/runeutil.go index 82ea90a2e..6856cc87f 100644 --- a/runeutil/runeutil.go +++ b/internal/runeutil/runeutil.go @@ -1,5 +1,5 @@ -// Package runeutil provides a utility function for use in Bubbles -// that can process Key messages containing runes. +// Package runeutil provides utility functions for tidying up incoming runes +// from Key messages. package runeutil import ( diff --git a/runeutil/runeutil_test.go b/internal/runeutil/runeutil_test.go similarity index 100% rename from runeutil/runeutil_test.go rename to internal/runeutil/runeutil_test.go diff --git a/textarea/textarea.go b/textarea/textarea.go index 1ae9290fb..877737a5e 100644 --- a/textarea/textarea.go +++ b/textarea/textarea.go @@ -9,9 +9,9 @@ import ( "github.com/atotto/clipboard" "github.com/charmbracelet/bubbles/v2/cursor" + "github.com/charmbracelet/bubbles/v2/internal/memoization" + "github.com/charmbracelet/bubbles/v2/internal/runeutil" "github.com/charmbracelet/bubbles/v2/key" - "github.com/charmbracelet/bubbles/v2/runeutil" - "github.com/charmbracelet/bubbles/v2/textarea/memoization" "github.com/charmbracelet/bubbles/v2/viewport" tea "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss" diff --git a/textinput/textinput.go b/textinput/textinput.go index 2359d92c7..d550e239c 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -7,8 +7,8 @@ import ( "github.com/atotto/clipboard" "github.com/charmbracelet/bubbles/v2/cursor" + "github.com/charmbracelet/bubbles/v2/internal/runeutil" "github.com/charmbracelet/bubbles/v2/key" - "github.com/charmbracelet/bubbles/v2/runeutil" tea "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss" rw "github.com/mattn/go-runewidth" From 4070e9cc1f03fc82c4004eeaa68b0ce9996dbb34 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 24 Oct 2024 15:24:20 -0400 Subject: [PATCH 4/4] chore(help): fix tests --- help/help_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/help/help_test.go b/help/help_test.go index 79601d789..ee1f7e687 100644 --- a/help/help_test.go +++ b/help/help_test.go @@ -4,9 +4,8 @@ import ( "fmt" "testing" + "github.com/charmbracelet/bubbles/v2/key" "github.com/charmbracelet/x/exp/golden" - - "github.com/charmbracelet/bubbles/key" ) func TestFullHelp(t *testing.T) {