From 06824cb77d65c6fa770a10b6e5aba9e7b73308e1 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Wed, 19 Mar 2025 13:38:46 -0300 Subject: [PATCH 01/13] chore: add taskfile --- Taskfile.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Taskfile.yaml diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000..3507203 --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,14 @@ +# https://taskfile.dev + +version: '3' + +tasks: + lint: + desc: Run lint + cmds: + - golangci-lint run + + test: + desc: Run tests + cmds: + - go test ./... {{.CLI_ARGS}} From 976d9a1108dbf0839c4a92b2f06db0e8217a50fe Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Wed, 19 Mar 2025 13:32:22 -0300 Subject: [PATCH 02/13] chore(go.mod): update to go 1.23 --- .github/workflows/build.yml | 4 +++- go.mod | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f804b0c..4f21e85 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,12 @@ name: build + on: [push, pull_request] + jobs: test: strategy: matrix: - go-version: [~1.18, ^1] + go-version: ['1.23', '1.24'] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} env: diff --git a/go.mod b/go.mod index c35957b..5606819 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/charmbracelet/bubbles -go 1.18 +go 1.23.0 + +toolchain go1.23.7 require ( github.com/MakeNowJust/heredoc v1.0.0 From 76433f714329061315a81c98362468def335c1dd Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Wed, 19 Mar 2025 13:33:28 -0300 Subject: [PATCH 03/13] ci: fix linting on windows --- filepicker/hidden_windows.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filepicker/hidden_windows.go b/filepicker/hidden_windows.go index d9ec5ad..b5f8126 100644 --- a/filepicker/hidden_windows.go +++ b/filepicker/hidden_windows.go @@ -11,11 +11,11 @@ import ( func IsHidden(file string) (bool, error) { pointer, err := syscall.UTF16PtrFromString(file) if err != nil { - return false, err + return false, err //nolint:wrapcheck } attributes, err := syscall.GetFileAttributes(pointer) if err != nil { - return false, err + return false, err //nolint:wrapcheck } return attributes&syscall.FILE_ATTRIBUTE_HIDDEN != 0, nil } From fff86382cc63991dad9f8ccc2530e36d69a5c468 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Wed, 19 Mar 2025 13:41:07 -0300 Subject: [PATCH 04/13] chore(lint): remove custom `min` and `max` functions These are now available as builtins. --- filepicker/filepicker.go | 13 +++---------- list/list.go | 7 ------- paginator/paginator.go | 7 ------- progress/progress.go | 14 -------------- table/table.go | 16 ---------------- textarea/textarea.go | 26 ++++++-------------------- textinput/textinput.go | 14 -------------- viewport/viewport.go | 14 -------------- 8 files changed, 9 insertions(+), 102 deletions(-) diff --git a/filepicker/filepicker.go b/filepicker/filepicker.go index 113c6c9..ec96e3d 100644 --- a/filepicker/filepicker.go +++ b/filepicker/filepicker.go @@ -188,10 +188,10 @@ func newStack() stack { } } -func (m *Model) pushView(selected, min, max int) { +func (m *Model) pushView(selected, minimum, maximum int) { m.selectedStack.Push(selected) - m.minStack.Push(min) - m.maxStack.Push(max) + m.minStack.Push(minimum) + m.maxStack.Push(maximum) } func (m *Model) popView() (int, int, int) { @@ -507,10 +507,3 @@ func (m Model) canSelect(file string) bool { } return false } - -func max(a, b int) int { - if a > b { - return a - } - return b -} diff --git a/list/list.go b/list/list.go index 6808142..9e3cd03 100644 --- a/list/list.go +++ b/list/list.go @@ -1326,10 +1326,3 @@ func countEnabledBindings(groups [][]key.Binding) (agg int) { } return agg } - -func max(a, b int) int { - if a > b { - return a - } - return b -} diff --git a/paginator/paginator.go b/paginator/paginator.go index 961b4e5..12e4e93 100644 --- a/paginator/paginator.go +++ b/paginator/paginator.go @@ -212,10 +212,3 @@ func (m Model) dotsView() string { func (m Model) arabicView() string { return fmt.Sprintf(m.ArabicFormat, m.Page+1, m.TotalPages) } - -func min(a, b int) int { - if a < b { - return a - } - return b -} diff --git a/progress/progress.go b/progress/progress.go index cfd18cb..b5d9f34 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -357,22 +357,8 @@ func (m Model) color(c string) termenv.Color { return m.colorProfile.Color(c) } -func max(a, b int) int { - if a > b { - return a - } - return b -} - // IsAnimating returns false if the progress bar reached equilibrium and is no longer animating. func (m *Model) IsAnimating() bool { dist := math.Abs(m.percentShown - m.targetPercent) return !(dist < 0.001 && m.velocity < 0.01) } - -func min(a, b int) int { - if a < b { - return a - } - return b -} diff --git a/table/table.go b/table/table.go index d68b626..86151f6 100644 --- a/table/table.go +++ b/table/table.go @@ -438,22 +438,6 @@ func (m *Model) renderRow(r int) string { return row } -func max(a, b int) int { - if a > b { - return a - } - - return b -} - -func min(a, b int) int { - if a < b { - return a - } - - return b -} - func clamp(v, low, high int) int { return min(max(v, low), high) } diff --git a/textarea/textarea.go b/textarea/textarea.go index 8a2071f..88bc979 100644 --- a/textarea/textarea.go +++ b/textarea/textarea.go @@ -853,13 +853,13 @@ func (m Model) LineInfo() LineInfo { // repositionView repositions the view of the viewport based on the defined // scrolling behavior. func (m *Model) repositionView() { - min := m.viewport.YOffset - max := min + m.viewport.Height - 1 + minimum := m.viewport.YOffset + maximum := minimum + m.viewport.Height - 1 - if row := m.cursorLineNumber(); row < min { - m.viewport.LineUp(min - row) - } else if row > max { - m.viewport.LineDown(row - max) + if row := m.cursorLineNumber(); row < minimum { + m.viewport.LineUp(minimum - row) + } else if row > maximum { + m.viewport.LineDown(row - maximum) } } @@ -1466,17 +1466,3 @@ func clamp(v, low, high int) int { } return min(high, max(low, v)) } - -func min(a, b int) int { - if a < b { - return a - } - return b -} - -func max(a, b int) int { - if a > b { - return a - } - return b -} diff --git a/textinput/textinput.go b/textinput/textinput.go index 1b44ab2..4c5c10d 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -758,20 +758,6 @@ func clamp(v, low, high int) int { return min(high, max(low, v)) } -func min(a, b int) int { - if a < b { - return a - } - return b -} - -func max(a, b int) int { - if a > b { - return a - } - return b -} - // Deprecated. // Deprecated: use cursor.Mode. diff --git a/viewport/viewport.go b/viewport/viewport.go index 11c6da7..0a818c0 100644 --- a/viewport/viewport.go +++ b/viewport/viewport.go @@ -484,20 +484,6 @@ func clamp(v, low, high int) int { return min(high, max(low, v)) } -func min(a, b int) int { - if a < b { - return a - } - return b -} - -func max(a, b int) int { - if a > b { - return a - } - return b -} - func findLongestLineWidth(lines []string) int { w := 0 for _, l := range lines { From 54f28b650198f96080f16c0cba1e480f4457ec0a Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 20 Mar 2025 14:00:29 -0300 Subject: [PATCH 05/13] fix(filepicker): properly scrolling filepicker (#753) * fix(filepicker): properly scrolling filepicker Signed-off-by: Carlos Alexandro Becker * fix: SetHeight Signed-off-by: Carlos Alexandro Becker --------- Signed-off-by: Carlos Alexandro Becker --- filepicker/filepicker.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/filepicker/filepicker.go b/filepicker/filepicker.go index ec96e3d..487ca96 100644 --- a/filepicker/filepicker.go +++ b/filepicker/filepicker.go @@ -158,6 +158,9 @@ type Model struct { maxStack stack minStack stack + // Height of the picker. + // + // Deprecated: use [Model.SetHeight] instead. Height int AutoHeight bool @@ -233,6 +236,14 @@ func (m Model) Init() tea.Cmd { return m.readDir(m.CurrentDirectory, m.ShowHidden) } +// SetHeight sets the height of the filepicker. +func (m *Model) SetHeight(height int) { + m.Height = height + if m.max > m.Height-1 { + m.max = m.min + m.Height - 1 + } +} + // Update handles user interactions within the file picker model. func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { switch msg := msg.(type) { From d91c9aa894a6d861f0c139839593b53cd2b2f729 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 25 Mar 2025 10:23:38 -0300 Subject: [PATCH 06/13] ci: rm .golangci-soft.yml --- .golangci-soft.yml | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 .golangci-soft.yml diff --git a/.golangci-soft.yml b/.golangci-soft.yml deleted file mode 100644 index d325d4f..0000000 --- a/.golangci-soft.yml +++ /dev/null @@ -1,40 +0,0 @@ -run: - tests: false - issues-exit-code: 0 - -issues: - include: - - EXC0001 - - EXC0005 - - EXC0011 - - EXC0012 - - EXC0013 - - max-issues-per-linter: 0 - max-same-issues: 0 - -linters: - enable: - - exhaustive - - goconst - - godot - - godox - - mnd - - gomoddirectives - - goprintffuncname - - misspell - - nakedret - - nestif - - noctx - - nolintlint - - prealloc - - wrapcheck - - # disable default linters, they are already enabled in .golangci.yml - disable: - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - unused From d58217bded070d5dba742eccfa9dfe2523f71ee1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 25 Mar 2025 10:24:22 -0300 Subject: [PATCH 07/13] ci: sync golangci-lint config (#750) Co-authored-by: aymanbagabas <3187948+aymanbagabas@users.noreply.github.com> --- .golangci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index d6789e0..90c5c08 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,10 +15,22 @@ issues: linters: enable: - bodyclose + - exhaustive + - goconst + - godot + - godox - gofumpt - goimports + - gomoddirectives + - goprintffuncname - gosec + - misspell + - nakedret + - nestif - nilerr + - noctx + - nolintlint + - prealloc - revive - rowserrcheck - sqlclosecheck @@ -26,3 +38,4 @@ linters: - unconvert - unparam - whitespace + - wrapcheck From 43aa82c87e638221a3e00affd35f300cb2901eac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Mar 2025 10:24:46 -0300 Subject: [PATCH 08/13] feat(deps): bump github.com/charmbracelet/x/ansi (#716) Bumps [github.com/charmbracelet/x/ansi](https://github.com/charmbracelet/x) from 0.6.1-0.20250107110353-48b574af22a5 to 0.8.0. - [Release notes](https://github.com/charmbracelet/x/releases) - [Commits](https://github.com/charmbracelet/x/commits/ansi/v0.8.0) --- updated-dependencies: - dependency-name: github.com/charmbracelet/x/ansi dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5606819..bf51ed9 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/charmbracelet/bubbletea v1.1.2 github.com/charmbracelet/harmonica v0.2.0 github.com/charmbracelet/lipgloss v1.0.0 - github.com/charmbracelet/x/ansi v0.6.1-0.20250107110353-48b574af22a5 + github.com/charmbracelet/x/ansi v0.8.0 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 diff --git a/go.sum b/go.sum index 7542d37..793e79f 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,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/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg= github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo= -github.com/charmbracelet/x/ansi v0.6.1-0.20250107110353-48b574af22a5 h1:TSjbA80sXnABV/Vxhnb67Ho7p8bEYqz6NIdhLAx+1yg= -github.com/charmbracelet/x/ansi v0.6.1-0.20250107110353-48b574af22a5/go.mod h1:KBUFw1la39nl0dLl10l5ORDAqGXaeurTQmwyyVKse/Q= +github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE= +github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q= 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= From 4e8b6b2043b4cb4d2a37acc64f737b0ba3318252 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Mar 2025 10:25:04 -0300 Subject: [PATCH 09/13] chore(deps): bump github.com/charmbracelet/bubbletea from 1.1.2 to 1.3.4 (#745) Bumps [github.com/charmbracelet/bubbletea](https://github.com/charmbracelet/bubbletea) from 1.1.2 to 1.3.4. - [Release notes](https://github.com/charmbracelet/bubbletea/releases) - [Changelog](https://github.com/charmbracelet/bubbletea/blob/main/.goreleaser.yml) - [Commits](https://github.com/charmbracelet/bubbletea/compare/v1.1.2...v1.3.4) --- updated-dependencies: - dependency-name: github.com/charmbracelet/bubbletea dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index bf51ed9..2449bbf 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.23.7 require ( github.com/MakeNowJust/heredoc v1.0.0 github.com/atotto/clipboard v0.1.4 - github.com/charmbracelet/bubbletea v1.1.2 + github.com/charmbracelet/bubbletea v1.3.4 github.com/charmbracelet/harmonica v0.2.0 github.com/charmbracelet/lipgloss v1.0.0 github.com/charmbracelet/x/ansi v0.8.0 @@ -23,14 +23,14 @@ require ( require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymanbagabas/go-udiff v0.2.0 // indirect - github.com/charmbracelet/x/term v0.2.0 // indirect + github.com/charmbracelet/x/term v0.2.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-localereader v0.0.1 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect - golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.26.0 // indirect + golang.org/x/sync v0.11.0 // indirect + golang.org/x/sys v0.30.0 // indirect golang.org/x/text v0.3.8 // indirect ) diff --git a/go.sum b/go.sum index 793e79f..dca06bf 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ 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 v1.1.2 h1:naQXF2laRxyLyil/i7fxdpiz1/k06IKquhm4vBfHsIc= -github.com/charmbracelet/bubbletea v1.1.2/go.mod h1:9HIU/hBV24qKjlehyj8z1r/tR9TYTQEag+cWZnuXo8E= +github.com/charmbracelet/bubbletea v1.3.4 h1:kCg7B+jSCFPLYRA52SDZjr51kG/fMUEoPoZrkaDHyoI= +github.com/charmbracelet/bubbletea v1.3.4/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo= 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 v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg= @@ -16,8 +16,8 @@ github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2ll github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q= 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/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= +github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= 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= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= @@ -43,11 +43,11 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA= github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= -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.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= +golang.org/x/sync v0.11.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.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= From 0305695768261fac9cf3d55a3ac0b79542552c64 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 25 Mar 2025 10:41:59 -0300 Subject: [PATCH 10/13] ci: test on oldstable and stable go versions, automerge dependabot (#755) --- .github/workflows/build.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f21e85..72bed38 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,11 +6,9 @@ jobs: test: strategy: matrix: - go-version: ['1.23', '1.24'] + go-version: [stable, oldstable] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} - env: - GO111MODULE: "on" steps: - name: Install Go uses: actions/setup-go@v5 @@ -28,3 +26,22 @@ jobs: - name: Test run: go test ./... + + dependabot: + needs: [test] + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: write + if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}} + steps: + - id: metadata + uses: dependabot/fetch-metadata@v2 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + - run: | + gh pr review --approve "$PR_URL" + gh pr merge --squash --auto "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} From 3befcccf8702cb29ad196acc10b4899aa16b47f0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Mar 2025 10:42:12 -0300 Subject: [PATCH 11/13] chore(deps): bump github.com/muesli/termenv from 0.15.2 to 0.16.0 (#740) Bumps [github.com/muesli/termenv](https://github.com/muesli/termenv) from 0.15.2 to 0.16.0. - [Release notes](https://github.com/muesli/termenv/releases) - [Commits](https://github.com/muesli/termenv/compare/v0.15.2...v0.16.0) --- updated-dependencies: - dependency-name: github.com/muesli/termenv dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2449bbf..dfa320a 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/dustin/go-humanize v1.0.1 github.com/lucasb-eyer/go-colorful v1.2.0 github.com/mattn/go-runewidth v0.0.16 - github.com/muesli/termenv v0.15.2 + github.com/muesli/termenv v0.16.0 github.com/rivo/uniseg v0.4.7 github.com/sahilm/fuzzy v0.1.1 ) diff --git a/go.sum b/go.sum index dca06bf..4e081ad 100644 --- a/go.sum +++ b/go.sum @@ -36,8 +36,8 @@ github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= -github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= -github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= +github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= +github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= From c814ac75c3b4be111bf163c07655971543be33f9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Mar 2025 10:42:23 -0300 Subject: [PATCH 12/13] chore(deps): bump github.com/charmbracelet/lipgloss from 1.0.0 to 1.1.0 (#751) Bumps [github.com/charmbracelet/lipgloss](https://github.com/charmbracelet/lipgloss) from 1.0.0 to 1.1.0. - [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/v1.0.0...v1.1.0) --- updated-dependencies: - dependency-name: github.com/charmbracelet/lipgloss dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 5 ++++- go.sum | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index dfa320a..e316a0a 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/atotto/clipboard v0.1.4 github.com/charmbracelet/bubbletea v1.3.4 github.com/charmbracelet/harmonica v0.2.0 - github.com/charmbracelet/lipgloss v1.0.0 + github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/ansi v0.8.0 github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 github.com/dustin/go-humanize v1.0.1 @@ -23,6 +23,8 @@ 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.2.3-0.20250311203215-f60798e515dc // indirect + github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect github.com/charmbracelet/x/term v0.2.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/kylelemons/godebug v1.1.0 // indirect @@ -30,6 +32,7 @@ require ( github.com/mattn/go-localereader v0.0.1 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect golang.org/x/sync v0.11.0 // indirect golang.org/x/sys v0.30.0 // indirect golang.org/x/text v0.3.8 // indirect diff --git a/go.sum b/go.sum index 4e081ad..bb1720b 100644 --- a/go.sum +++ b/go.sum @@ -8,12 +8,16 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA= github.com/charmbracelet/bubbletea v1.3.4 h1:kCg7B+jSCFPLYRA52SDZjr51kG/fMUEoPoZrkaDHyoI= github.com/charmbracelet/bubbletea v1.3.4/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo= +github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs= +github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk= 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 v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg= -github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo= +github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= +github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE= github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q= +github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8= +github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= 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.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= @@ -43,6 +47,10 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA= github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= +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-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= +golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 9e5365e0ec0c4005efc7a3cc47f67941840e4144 Mon Sep 17 00:00:00 2001 From: bashbunni <15822994+bashbunni@users.noreply.github.com> Date: Tue, 25 Mar 2025 06:51:14 -0700 Subject: [PATCH 13/13] docs: add example for ValidateFunc (#705) * docs(textinput): add ValidateFunc example * chore: remove print statement * chore: rename the -> this anonymous func --- textinput/textinput_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/textinput/textinput_test.go b/textinput/textinput_test.go index 6c288ab..162167e 100644 --- a/textinput/textinput_test.go +++ b/textinput/textinput_test.go @@ -1,6 +1,8 @@ package textinput import ( + "fmt" + "strconv" "strings" "testing" ) @@ -43,3 +45,36 @@ func Test_SlicingOutsideCap(t *testing.T) { textinput.Width = 32 textinput.View() } + +func ExampleValidateFunc() { + creditCardNumber := New() + creditCardNumber.Placeholder = "4505 **** **** 1234" + creditCardNumber.Focus() + creditCardNumber.CharLimit = 20 + creditCardNumber.Width = 30 + creditCardNumber.Prompt = "" + // This anonymous function is a valid function for ValidateFunc. + creditCardNumber.Validate = func(s string) error { + // Credit Card Number should a string less than 20 digits + // It should include 16 integers and 3 spaces + if len(s) > 16+3 { + return fmt.Errorf("CCN is too long") + } + + if len(s) == 0 || len(s)%5 != 0 && (s[len(s)-1] < '0' || s[len(s)-1] > '9') { + return fmt.Errorf("CCN is invalid") + } + + // The last digit should be a number unless it is a multiple of 4 in which + // case it should be a space + if len(s)%5 == 0 && s[len(s)-1] != ' ' { + return fmt.Errorf("CCN must separate groups with spaces") + } + + // The remaining digits should be integers + c := strings.ReplaceAll(s, " ", "") + _, err := strconv.ParseInt(c, 10, 64) + + return err + } +}