From 8e4b39d6349ef857ed47195f55dfe1a05f7510ee Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Jun 2025 10:01:44 +0000 Subject: [PATCH 01/14] chore(deps): bump github.com/aymanbagabas/go-udiff from 0.2.0 to 0.3.1 (#798) Bumps [github.com/aymanbagabas/go-udiff](https://github.com/aymanbagabas/go-udiff) from 0.2.0 to 0.3.1. - [Release notes](https://github.com/aymanbagabas/go-udiff/releases) - [Commits](https://github.com/aymanbagabas/go-udiff/compare/v0.2.0...v0.3.1) --- updated-dependencies: - dependency-name: github.com/aymanbagabas/go-udiff dependency-version: 0.3.1 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 b4c92ee..4688bcc 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/aymanbagabas/go-udiff v0.2.0 + github.com/aymanbagabas/go-udiff v0.3.1 github.com/charmbracelet/bubbletea v1.3.5 github.com/charmbracelet/harmonica v0.2.0 github.com/charmbracelet/lipgloss v1.1.0 diff --git a/go.sum b/go.sum index 41b06ec..4b3190b 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= 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/aymanbagabas/go-udiff v0.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY= +github.com/aymanbagabas/go-udiff v0.3.1/go.mod h1:G0fsKmG+P6ylD0r6N/KgQD/nWzgfnl8ZBcNLgcbrw8E= github.com/charmbracelet/bubbletea v1.3.5 h1:JAMNLTbqMOhSwoELIr0qyP4VidFq72/6E9j7HHmRKQc= github.com/charmbracelet/bubbletea v1.3.5/go.mod h1:TkCnmH+aBd4LrXhXcqrKiYwRs7qyQx5rBgH5fVY3v54= github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs= From 23b8fd6302d7af858f8c971d121a9fe44a47fe37 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Jun 2025 10:34:23 +0000 Subject: [PATCH 02/14] chore(deps): bump github.com/charmbracelet/x/ansi from 0.9.2 to 0.9.3 (#803) Bumps [github.com/charmbracelet/x/ansi](https://github.com/charmbracelet/x) from 0.9.2 to 0.9.3. - [Commits](https://github.com/charmbracelet/x/compare/ansi/v0.9.2...ansi/v0.9.3) --- updated-dependencies: - dependency-name: github.com/charmbracelet/x/ansi dependency-version: 0.9.3 dependency-type: direct:production update-type: version-update:semver-patch ... 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 4688bcc..99957c5 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.5 github.com/charmbracelet/harmonica v0.2.0 github.com/charmbracelet/lipgloss v1.1.0 - github.com/charmbracelet/x/ansi v0.9.2 + github.com/charmbracelet/x/ansi v0.9.3 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 4b3190b..eb26064 100644 --- a/go.sum +++ b/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/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.9.2 h1:92AGsQmNTRMzuzHEYfCdjQeUzTrgE1vfO5/7fEVoXdY= -github.com/charmbracelet/x/ansi v0.9.2/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= +github.com/charmbracelet/x/ansi v0.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0= +github.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= 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= From d66fddf5e780b2bf30e386dbf4e65b55b258197f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Jul 2025 11:56:01 +0000 Subject: [PATCH 03/14] chore(deps): bump github.com/charmbracelet/bubbletea from 1.3.5 to 1.3.6 (#813) Bumps [github.com/charmbracelet/bubbletea](https://github.com/charmbracelet/bubbletea) from 1.3.5 to 1.3.6. - [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.3.5...v1.3.6) --- updated-dependencies: - dependency-name: github.com/charmbracelet/bubbletea dependency-version: 1.3.6 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 99957c5..6a60537 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/MakeNowJust/heredoc v1.0.0 github.com/atotto/clipboard v0.1.4 github.com/aymanbagabas/go-udiff v0.3.1 - github.com/charmbracelet/bubbletea v1.3.5 + github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/harmonica v0.2.0 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/ansi v0.9.3 @@ -33,7 +33,7 @@ require ( 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.13.0 // indirect - golang.org/x/sys v0.32.0 // indirect + golang.org/x/sync v0.15.0 // indirect + golang.org/x/sys v0.33.0 // indirect golang.org/x/text v0.3.8 // indirect ) diff --git a/go.sum b/go.sum index eb26064..f1b398f 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.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY= github.com/aymanbagabas/go-udiff v0.3.1/go.mod h1:G0fsKmG+P6ylD0r6N/KgQD/nWzgfnl8ZBcNLgcbrw8E= -github.com/charmbracelet/bubbletea v1.3.5 h1:JAMNLTbqMOhSwoELIr0qyP4VidFq72/6E9j7HHmRKQc= -github.com/charmbracelet/bubbletea v1.3.5/go.mod h1:TkCnmH+aBd4LrXhXcqrKiYwRs7qyQx5rBgH5fVY3v54= +github.com/charmbracelet/bubbletea v1.3.6 h1:VkHIxPJQeDt0aFJIsVxw8BQdh/F/L2KKZGsK6et5taU= +github.com/charmbracelet/bubbletea v1.3.6/go.mod h1:oQD9VCRQFF8KplacJLo28/jofOI2ToOfGYeFgBBxHOc= 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= @@ -51,11 +51,11 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM 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.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= -golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= +golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 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.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= -golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= From 3cadd53d27552f644e0a5f8b3c9ffbc5fc296fab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Aug 2025 13:25:27 +0000 Subject: [PATCH 04/14] chore(deps): bump github.com/charmbracelet/x/ansi from 0.9.3 to 0.10.1 (#826) Bumps [github.com/charmbracelet/x/ansi](https://github.com/charmbracelet/x) from 0.9.3 to 0.10.1. - [Commits](https://github.com/charmbracelet/x/compare/ansi/v0.9.3...ansi/v0.10.1) --- updated-dependencies: - dependency-name: github.com/charmbracelet/x/ansi dependency-version: 0.10.1 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 6a60537..74bf586 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/harmonica v0.2.0 github.com/charmbracelet/lipgloss v1.1.0 - github.com/charmbracelet/x/ansi v0.9.3 + github.com/charmbracelet/x/ansi v0.10.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 diff --git a/go.sum b/go.sum index f1b398f..13d8a4c 100644 --- a/go.sum +++ b/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/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.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0= -github.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= +github.com/charmbracelet/x/ansi v0.10.1 h1:rL3Koar5XvX0pHGfovN03f5cxLbCF2YvLeyz7D2jVDQ= +github.com/charmbracelet/x/ansi v0.10.1/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= 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= From 7fcf75da535ee7db938586044a02f0f74f40339e Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 13 Aug 2025 08:11:33 -0400 Subject: [PATCH 05/14] docs(readme): update footer image and copyright date --- LICENSE | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 31d76c1..be3f0c1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2023 Charmbracelet, Inc +Copyright (c) 2020-2025 Charmbracelet, Inc Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 8c3c0b5..2c2aca7 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,6 @@ We’d love to hear your thoughts on this project. Feel free to drop us a note! Part of [Charm](https://charm.sh). -The Charm logo +The Charm logo Charm热爱开源 • Charm loves open source From 6de30985f1cdd61e90efe76f037bddb748642dfa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 12:54:20 +0000 Subject: [PATCH 06/14] chore(deps): bump actions/checkout from 4 to 5 (#828) Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/build.yml | 2 +- .github/workflows/coverage.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 72bed38..0557da8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Download Go modules run: go mod download diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 7998ddf..91b0900 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -17,7 +17,7 @@ jobs: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Coverage env: From 4b2d311076480670a00b3f24fd9ad280c35c7c57 Mon Sep 17 00:00:00 2001 From: Charm <124303983+charmcli@users.noreply.github.com> Date: Tue, 26 Aug 2025 13:01:25 -0300 Subject: [PATCH 07/14] ci: sync dependabot config (#835) --- .github/dependabot.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 63ed01f..271179a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -13,6 +13,10 @@ updates: commit-message: prefix: "chore" include: "scope" + groups: + all: + patterns: + - "*" - package-ecosystem: "github-actions" directory: "/" @@ -26,6 +30,10 @@ updates: commit-message: prefix: "chore" include: "scope" + groups: + all: + patterns: + - "*" - package-ecosystem: "docker" directory: "/" @@ -39,3 +47,7 @@ updates: commit-message: prefix: "chore" include: "scope" + groups: + all: + patterns: + - "*" From 7c44f63d3185e6f1d795e9369ba85185e6efe956 Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Mon, 1 Sep 2025 09:50:17 -0400 Subject: [PATCH 08/14] v1: fix(list): ensure correct cursor positions with page/cursor methods (#831) * fix(list): misc cursor position fixes Signed-off-by: Liam Stanley * chore(list): add low/high check in clamp --------- Signed-off-by: Liam Stanley Co-authored-by: Christian Rocha --- list/list.go | 89 ++++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/list/list.go b/list/list.go index fc7c6b1..d82a12c 100644 --- a/list/list.go +++ b/list/list.go @@ -4,6 +4,7 @@ package list import ( + "cmp" "fmt" "io" "sort" @@ -22,6 +23,13 @@ import ( "github.com/charmbracelet/bubbles/textinput" ) +func clamp[T cmp.Ordered](v, low, high T) T { + if low > high { + low, high = high, low + } + return min(high, max(low, v)) +} + // Item is an item that appears in the list. type Item interface { // FilterValue is the value we use when filtering against this item when @@ -282,8 +290,7 @@ func (m *Model) SetFilterText(filter string) { fmm, _ := msg.(FilterMatchesMsg) m.filteredItems = filteredItems(fmm) m.filterState = FilterApplied - m.Paginator.Page = 0 - m.cursor = 0 + m.GoToStart() m.FilterInput.CursorEnd() m.updatePagination() m.updateKeybindings() @@ -291,8 +298,7 @@ func (m *Model) SetFilterText(filter string) { // SetFilterState allows setting the filtering state manually. func (m *Model) SetFilterState(state FilterState) { - m.Paginator.Page = 0 - m.cursor = 0 + m.GoToStart() m.filterState = state m.FilterInput.CursorEnd() m.FilterInput.Focus() @@ -516,14 +522,12 @@ func (m *Model) CursorUp() { m.cursor-- // If we're at the start, stop - if m.cursor < 0 && m.Paginator.Page == 0 { + if m.cursor < 0 && m.Paginator.OnFirstPage() { // if infinite scrolling is enabled, go to the last item if m.InfiniteScrolling { - m.Paginator.Page = m.Paginator.TotalPages - 1 - m.cursor = m.Paginator.ItemsOnPage(len(m.VisibleItems())) - 1 + m.GoToEnd() return } - m.cursor = 0 return } @@ -535,18 +539,18 @@ func (m *Model) CursorUp() { // Go to the previous page m.Paginator.PrevPage() - m.cursor = m.Paginator.ItemsOnPage(len(m.VisibleItems())) - 1 + m.cursor = m.maxCursorIndex() } // CursorDown moves the cursor down. This can also advance the state to the // next page. func (m *Model) CursorDown() { - itemsOnPage := m.Paginator.ItemsOnPage(len(m.VisibleItems())) + maxCursorIndex := m.maxCursorIndex() m.cursor++ - // If we're at the end, stop - if m.cursor < itemsOnPage { + // We're still within bounds of the current page, so no need to do anything. + if m.cursor <= maxCursorIndex { return } @@ -557,31 +561,40 @@ func (m *Model) CursorDown() { return } - // During filtering the cursor position can exceed the number of - // itemsOnPage. It's more intuitive to start the cursor at the - // topmost position when moving it down in this scenario. - if m.cursor > itemsOnPage { - m.cursor = 0 - return - } + m.cursor = max(0, maxCursorIndex) - m.cursor = itemsOnPage - 1 - - // if infinite scrolling is enabled, go to the first item + // if infinite scrolling is enabled, go to the first item. if m.InfiniteScrolling { - m.Paginator.Page = 0 - m.cursor = 0 + m.GoToStart() } } +// GoToStart moves to the first page, and first item on the first page. +func (m *Model) GoToStart() { + m.Paginator.Page = 0 + m.cursor = 0 +} + +// GoToEnd moves to the last page, and last item on the last page. +func (m *Model) GoToEnd() { + m.Paginator.Page = max(0, m.Paginator.TotalPages-1) + m.cursor = m.maxCursorIndex() +} + // PrevPage moves to the previous page, if available. func (m *Model) PrevPage() { m.Paginator.PrevPage() + m.cursor = clamp(m.cursor, 0, m.maxCursorIndex()) } // NextPage moves to the next page, if available. func (m *Model) NextPage() { m.Paginator.NextPage() + m.cursor = clamp(m.cursor, 0, m.maxCursorIndex()) +} + +func (m *Model) maxCursorIndex() int { + return max(0, m.Paginator.ItemsOnPage(len(m.VisibleItems()))-1) } // FilterState returns the current filter state. @@ -673,22 +686,18 @@ func (m *Model) NewStatusMessage(s string) tea.Cmd { } } -// SetSize sets the width and height of this component. -func (m *Model) SetSize(width, height int) { - m.setSize(width, height) -} - // SetWidth sets the width of this component. func (m *Model) SetWidth(v int) { - m.setSize(v, m.height) + m.SetSize(v, m.height) } // SetHeight sets the height of this component. func (m *Model) SetHeight(v int) { - m.setSize(m.width, v) + m.SetSize(m.width, v) } -func (m *Model) setSize(width, height int) { +// SetSize sets the width and height of this component. +func (m *Model) SetSize(width, height int) { promptWidth := lipgloss.Width(m.Styles.Title.Render(m.FilterInput.Prompt)) m.width = width @@ -848,7 +857,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { // Updates for when a user is browsing the list. func (m *Model) handleBrowsing(msg tea.Msg) tea.Cmd { var cmds []tea.Cmd - numItems := len(m.VisibleItems()) switch msg := msg.(type) { case tea.KeyMsg: @@ -874,12 +882,10 @@ func (m *Model) handleBrowsing(msg tea.Msg) tea.Cmd { m.Paginator.NextPage() case key.Matches(msg, m.KeyMap.GoToStart): - m.Paginator.Page = 0 - m.cursor = 0 + m.GoToStart() case key.Matches(msg, m.KeyMap.GoToEnd): - m.Paginator.Page = m.Paginator.TotalPages - 1 - m.cursor = m.Paginator.ItemsOnPage(numItems) - 1 + m.GoToEnd() case key.Matches(msg, m.KeyMap.Filter): m.hideStatusMessage() @@ -887,8 +893,7 @@ func (m *Model) handleBrowsing(msg tea.Msg) tea.Cmd { // Populate filter with all items only if the filter is empty. m.filteredItems = m.itemsAsFilterItems() } - m.Paginator.Page = 0 - m.cursor = 0 + m.GoToStart() m.filterState = Filtering m.FilterInput.CursorEnd() m.FilterInput.Focus() @@ -906,11 +911,7 @@ func (m *Model) handleBrowsing(msg tea.Msg) tea.Cmd { cmd := m.delegate.Update(msg, m) cmds = append(cmds, cmd) - // Keep the index in bounds when paginating - itemsOnPage := m.Paginator.ItemsOnPage(len(m.VisibleItems())) - if m.cursor > itemsOnPage-1 { - m.cursor = max(0, itemsOnPage-1) - } + m.cursor = clamp(m.cursor, 0, m.maxCursorIndex()) return tea.Batch(cmds...) } From 3532a3291430c9273201119c1fdb31a61cd78edf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Sep 2025 09:18:08 +0000 Subject: [PATCH 09/14] chore(deps): bump github.com/charmbracelet/bubbletea in the all group (#841) Bumps the all group with 1 update: [github.com/charmbracelet/bubbletea](https://github.com/charmbracelet/bubbletea). Updates `github.com/charmbracelet/bubbletea` from 1.3.6 to 1.3.7 - [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.3.6...v1.3.7) --- updated-dependencies: - dependency-name: github.com/charmbracelet/bubbletea dependency-version: 1.3.7 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: all ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 5 ++--- go.sum | 10 ++++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 74bf586..b601549 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/MakeNowJust/heredoc v1.0.0 github.com/atotto/clipboard v0.1.4 github.com/aymanbagabas/go-udiff v0.3.1 - github.com/charmbracelet/bubbletea v1.3.6 + github.com/charmbracelet/bubbletea v1.3.7 github.com/charmbracelet/harmonica v0.2.0 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/ansi v0.10.1 @@ -33,7 +33,6 @@ require ( 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.15.0 // indirect - golang.org/x/sys v0.33.0 // indirect + golang.org/x/sys v0.34.0 // indirect golang.org/x/text v0.3.8 // indirect ) diff --git a/go.sum b/go.sum index 13d8a4c..aad90b4 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.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY= github.com/aymanbagabas/go-udiff v0.3.1/go.mod h1:G0fsKmG+P6ylD0r6N/KgQD/nWzgfnl8ZBcNLgcbrw8E= -github.com/charmbracelet/bubbletea v1.3.6 h1:VkHIxPJQeDt0aFJIsVxw8BQdh/F/L2KKZGsK6et5taU= -github.com/charmbracelet/bubbletea v1.3.6/go.mod h1:oQD9VCRQFF8KplacJLo28/jofOI2ToOfGYeFgBBxHOc= +github.com/charmbracelet/bubbletea v1.3.7 h1:FNaEEFEenOEPnZsY9MI64thl2c84MI66+1QaQbxGOl4= +github.com/charmbracelet/bubbletea v1.3.7/go.mod h1:PEOcbQCNzJ2BYUd484kHPO5g3kLO28IffOdFeI2EWus= 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= @@ -51,11 +51,9 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM 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.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= -golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 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.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= -golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= +golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= From cfdc19ba97aea803f26c3775f2518c0dfd1b940a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:06:26 +0000 Subject: [PATCH 10/14] chore(deps): bump actions/setup-go from 5 to 6 in the all group (#842) Bumps the all group with 1 update: [actions/setup-go](https://github.com/actions/setup-go). Updates `actions/setup-go` from 5 to 6 - [Release notes](https://github.com/actions/setup-go/releases) - [Commits](https://github.com/actions/setup-go/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/setup-go dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major dependency-group: all ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/build.yml | 2 +- .github/workflows/coverage.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0557da8..18f695c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Install Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v6 with: go-version: ${{ matrix.go-version }} diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 91b0900..7c9e2ce 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -12,7 +12,7 @@ jobs: GO111MODULE: "on" steps: - name: Install Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v6 with: go-version: ${{ matrix.go-version }} From 5caedd7607ed3e58a5baac7d0c5bdaacee5115d6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:56:29 +0000 Subject: [PATCH 11/14] chore(deps): bump the all group with 2 updates (#848) Bumps the all group with 2 updates: [github.com/charmbracelet/bubbletea](https://github.com/charmbracelet/bubbletea) and [github.com/lucasb-eyer/go-colorful](https://github.com/lucasb-eyer/go-colorful). Updates `github.com/charmbracelet/bubbletea` from 1.3.7 to 1.3.9 - [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.3.7...v1.3.9) Updates `github.com/lucasb-eyer/go-colorful` from 1.2.0 to 1.3.0 - [Release notes](https://github.com/lucasb-eyer/go-colorful/releases) - [Changelog](https://github.com/lucasb-eyer/go-colorful/blob/master/CHANGELOG.md) - [Commits](https://github.com/lucasb-eyer/go-colorful/compare/v1.2.0...v1.3.0) --- updated-dependencies: - dependency-name: github.com/charmbracelet/bubbletea dependency-version: 1.3.9 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: all - dependency-name: github.com/lucasb-eyer/go-colorful dependency-version: 1.3.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: all ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 10 ++++------ go.sum | 12 ++++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index b601549..b5cdcba 100644 --- a/go.mod +++ b/go.mod @@ -1,20 +1,18 @@ module github.com/charmbracelet/bubbles -go 1.23.0 - -toolchain go1.23.7 +go 1.24.0 require ( github.com/MakeNowJust/heredoc v1.0.0 github.com/atotto/clipboard v0.1.4 github.com/aymanbagabas/go-udiff v0.3.1 - github.com/charmbracelet/bubbletea v1.3.7 + github.com/charmbracelet/bubbletea v1.3.9 github.com/charmbracelet/harmonica v0.2.0 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/ansi v0.10.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 + github.com/lucasb-eyer/go-colorful v1.3.0 github.com/mattn/go-runewidth v0.0.16 github.com/muesli/termenv v0.16.0 github.com/rivo/uniseg v0.4.7 @@ -33,6 +31,6 @@ require ( 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/sys v0.34.0 // indirect + golang.org/x/sys v0.36.0 // indirect golang.org/x/text v0.3.8 // indirect ) diff --git a/go.sum b/go.sum index aad90b4..a1e95b8 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.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY= github.com/aymanbagabas/go-udiff v0.3.1/go.mod h1:G0fsKmG+P6ylD0r6N/KgQD/nWzgfnl8ZBcNLgcbrw8E= -github.com/charmbracelet/bubbletea v1.3.7 h1:FNaEEFEenOEPnZsY9MI64thl2c84MI66+1QaQbxGOl4= -github.com/charmbracelet/bubbletea v1.3.7/go.mod h1:PEOcbQCNzJ2BYUd484kHPO5g3kLO28IffOdFeI2EWus= +github.com/charmbracelet/bubbletea v1.3.9 h1:OBYdfRo6QnlIcXNmcoI2n1NNS65Nk6kI2L2FO1puS/4= +github.com/charmbracelet/bubbletea v1.3.9/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4= 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= @@ -28,8 +28,8 @@ github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6 github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= -github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag= +github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= @@ -53,7 +53,7 @@ golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZ golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= 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.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= -golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= +golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= From f2d12667c41159491f8bdbac2f301db032073d05 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Sep 2025 09:16:56 +0000 Subject: [PATCH 12/14] chore(deps): bump github.com/charmbracelet/bubbletea in the all group (#850) Bumps the all group with 1 update: [github.com/charmbracelet/bubbletea](https://github.com/charmbracelet/bubbletea). Updates `github.com/charmbracelet/bubbletea` from 1.3.9 to 1.3.10 - [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.3.9...v1.3.10) --- updated-dependencies: - dependency-name: github.com/charmbracelet/bubbletea dependency-version: 1.3.10 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: all ... 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 b5cdcba..fadc0a4 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/MakeNowJust/heredoc v1.0.0 github.com/atotto/clipboard v0.1.4 github.com/aymanbagabas/go-udiff v0.3.1 - github.com/charmbracelet/bubbletea v1.3.9 + github.com/charmbracelet/bubbletea v1.3.10 github.com/charmbracelet/harmonica v0.2.0 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/ansi v0.10.1 diff --git a/go.sum b/go.sum index a1e95b8..8a7302a 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.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY= github.com/aymanbagabas/go-udiff v0.3.1/go.mod h1:G0fsKmG+P6ylD0r6N/KgQD/nWzgfnl8ZBcNLgcbrw8E= -github.com/charmbracelet/bubbletea v1.3.9 h1:OBYdfRo6QnlIcXNmcoI2n1NNS65Nk6kI2L2FO1puS/4= -github.com/charmbracelet/bubbletea v1.3.9/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4= +github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw= +github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4= 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= From d6934a175bbbc1154ba37f8030d5b4bd8ecd876c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Sep 2025 10:54:36 +0000 Subject: [PATCH 13/14] chore(deps): bump github.com/mattn/go-runewidth in the all group (#852) Bumps the all group with 1 update: [github.com/mattn/go-runewidth](https://github.com/mattn/go-runewidth). Updates `github.com/mattn/go-runewidth` from 0.0.16 to 0.0.17 - [Commits](https://github.com/mattn/go-runewidth/compare/v0.0.16...v0.0.17) --- updated-dependencies: - dependency-name: github.com/mattn/go-runewidth dependency-version: 0.0.17 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: all ... 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 fadc0a4..e939d1e 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( 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.3.0 - github.com/mattn/go-runewidth v0.0.16 + github.com/mattn/go-runewidth v0.0.17 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 8a7302a..bb4af8e 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= -github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= -github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.17 h1:78v8ZlW0bP43XfmAfPsdXcoNCelfMHsDmd/pkENfrjQ= +github.com/mattn/go-runewidth v0.0.17/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= 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= From 49ff5c03b7bada572da36c79269dc15ab03d569b Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 1 Oct 2025 10:22:53 -0300 Subject: [PATCH 14/14] fix(textinput): improve placeholder (#768) similar to #767 but for textinputs --- textinput/textinput.go | 30 +++++++++++------------------ textinput/textinput_test.go | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/textinput/textinput.go b/textinput/textinput.go index 9c6666e..1b02034 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -14,6 +14,7 @@ import ( "github.com/charmbracelet/bubbles/runeutil" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/x/ansi" rw "github.com/mattn/go-runewidth" "github.com/rivo/uniseg" ) @@ -703,40 +704,31 @@ func (m Model) placeholderView() string { var ( v string style = m.PlaceholderStyle.Inline(true).Render + p = m.PromptStyle.Render(m.Prompt) ) - p := make([]rune, m.Width+1) - copy(p, []rune(m.Placeholder)) - m.Cursor.TextStyle = m.PlaceholderStyle - m.Cursor.SetChar(string(p[:1])) + first, rest, _, _ := uniseg.FirstGraphemeClusterInString(m.Placeholder, 0) + m.Cursor.SetChar(first) v += m.Cursor.View() // If the entire placeholder is already set and no padding is needed, finish - if m.Width < 1 && len(p) <= 1 { + if m.Width < 1 && uniseg.StringWidth(rest) <= 1 { return m.PromptStyle.Render(m.Prompt) + v } // If Width is set then size placeholder accordingly if m.Width > 0 { - // available width is width - len + cursor offset of 1 - minWidth := lipgloss.Width(m.Placeholder) - availWidth := m.Width - minWidth + 1 - - // if width < len, 'subtract'(add) number to len and dont add padding - if availWidth < 0 { - minWidth += availWidth - availWidth = 0 - } - // append placeholder[len] - cursor, append padding - v += style(string(p[1:minWidth])) - v += style(strings.Repeat(" ", availWidth)) + width := m.Width - lipgloss.Width(p) - lipgloss.Width(v) + placeholderRest := ansi.Truncate(rest, width, "…") + availWidth := max(0, width-lipgloss.Width(placeholderRest)) + v += style(placeholderRest) + strings.Repeat(" ", availWidth) } else { // if there is no width, the placeholder can be any length - v += style(string(p[1:])) + v += style(rest) } - return m.PromptStyle.Render(m.Prompt) + v + return p + v } // Blink is a command used to initialize cursor blinking. diff --git a/textinput/textinput_test.go b/textinput/textinput_test.go index 162167e..a055ab6 100644 --- a/textinput/textinput_test.go +++ b/textinput/textinput_test.go @@ -5,6 +5,8 @@ import ( "strconv" "strings" "testing" + + tea "github.com/charmbracelet/bubbletea" ) func Test_CurrentSuggestion(t *testing.T) { @@ -46,6 +48,30 @@ func Test_SlicingOutsideCap(t *testing.T) { textinput.View() } +func TestChinesePlaceholder(t *testing.T) { + textinput := New() + textinput.Placeholder = "输入消息..." + textinput.Width = 20 + + got := textinput.View() + expected := "> 输入消息... " + if got != expected { + t.Fatalf("expected %q but got %q", expected, got) + } +} + +func TestPlaceholderTruncate(t *testing.T) { + textinput := New() + textinput.Placeholder = "A very long placeholder, or maybe not so much" + textinput.Width = 10 + + got := textinput.View() + expected := "> A very …" + if got != expected { + t.Fatalf("expected %q but got %q", expected, got) + } +} + func ExampleValidateFunc() { creditCardNumber := New() creditCardNumber.Placeholder = "4505 **** **** 1234" @@ -78,3 +104,15 @@ func ExampleValidateFunc() { return err } } + +func keyPress(key rune) tea.Msg { + return tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{key}, Alt: false} +} + +func sendString(m Model, str string) Model { + for _, k := range str { + m, _ = m.Update(keyPress(k)) + } + + return m +}