Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v2-exp' into v2-area
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Feb 5, 2025
2 parents 4a3501c + 64c16e9 commit 55a73b9
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [~1.18, ^1]
go-version: [~1.22, ^1]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
coverage:
strategy:
matrix:
go-version: [^1.18]
go-version: [^1.22]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
env:
Expand Down
7 changes: 0 additions & 7 deletions filepicker/filepicker.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,3 @@ func (m Model) canSelect(file string) bool {
}
return false
}

func max(a, b int) int {
if a > b {
return a
}
return b
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/charmbracelet/bubbles/v2

go 1.18
go 1.22

require (
github.com/MakeNowJust/heredoc v1.0.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
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/charmbracelet/bubbletea/v2 v2.0.0-alpha.2.0.20250203222705-2e91ec2235cd h1:u+kqgSbIL4pnP7huv4kaYUCmuN2L4yyDvdH81QJ4FZ0=
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.2.0.20250203222705-2e91ec2235cd/go.mod h1:zaWGYfO6cBtu4dRgGbVN7yMYUz3j9sVIzHy2gn0jdo8=
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.2.0.20250204175057-2a96bc438da6 h1:KbLqbYgHC5JZWks50WjBJr92Hs+GpiauwZaDObw9vxE=
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.2.0.20250204175057-2a96bc438da6/go.mod h1:zaWGYfO6cBtu4dRgGbVN7yMYUz3j9sVIzHy2gn0jdo8=
github.com/charmbracelet/colorprofile v0.2.0 h1:iiIQlp3LSvoJPtR11KoDfIf9wqWm2mn/iU420rHOZ/A=
Expand Down Expand Up @@ -34,11 +33,13 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
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/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-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
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/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=
Expand All @@ -47,6 +48,7 @@ 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/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
Expand Down
7 changes: 0 additions & 7 deletions list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,10 +1323,3 @@ func countEnabledBindings(groups [][]key.Binding) (agg int) {
}
return agg
}

func max(a, b int) int {
if a > b {
return a
}
return b
}
4 changes: 2 additions & 2 deletions list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"reflect"
"slices"
"strings"
"testing"

Expand Down Expand Up @@ -82,8 +83,7 @@ func TestSetFilterText(t *testing.T) {

list.SetFilterState(Unfiltered)
expected := tc
// TODO: replace with slices.Equal() when project move to go1.18 or later
if !reflect.DeepEqual(list.VisibleItems(), expected) {
if !slices.Equal(list.VisibleItems(), expected) {
t.Fatalf("Error: expected view to contain only %s", expected)
}

Expand Down
7 changes: 0 additions & 7 deletions paginator/paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,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
}
14 changes: 0 additions & 14 deletions progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,22 +345,8 @@ func (m *Model) setRamp(colorA, colorB string, scaled bool) {
m.rampColorB = b
}

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
}
16 changes: 0 additions & 16 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,22 +437,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)
}
14 changes: 0 additions & 14 deletions textarea/textarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,20 +1818,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 abs(n int) int {
if n < 0 {
return -n
Expand Down
14 changes: 0 additions & 14 deletions textinput/textinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,20 +761,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 (m Model) completionView(offset int) string {
var (
value = m.value
Expand Down
59 changes: 28 additions & 31 deletions viewport/viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ func (m Model) calculateLine(yoffset int) (total, idx int) {
return len(m.lines), yoffset
}
maxWidth := m.maxWidth()
gutterSize := lipgloss.Width(m.LeftGutterFunc(GutterContext{}))

var gutterSize int
if m.LeftGutterFunc != nil {
gutterSize = lipgloss.Width(m.LeftGutterFunc(GutterContext{}))
}
for i, line := range m.lines {
adjust := max(1, ansi.StringWidth(line)/(maxWidth-gutterSize))
if yoffset >= total && yoffset < total+adjust {
Expand Down Expand Up @@ -281,9 +285,13 @@ func (m Model) maxXOffset() int {
}

func (m Model) maxWidth() int {
var gutterSize int
if m.LeftGutterFunc != nil {
gutterSize = lipgloss.Width(m.LeftGutterFunc(GutterContext{}))
}
return m.Width() -
m.Style.GetHorizontalFrameSize() -
lipgloss.Width(m.LeftGutterFunc(GutterContext{}))
gutterSize
}

func (m Model) maxHeight() int {
Expand Down Expand Up @@ -361,11 +369,14 @@ func (m Model) softWrap(lines []string, maxWidth int) []string {
idx := 0
for ansi.StringWidth(line) >= idx {
truncatedLine := ansi.Cut(line, idx, maxWidth+idx)
wrappedLines = append(wrappedLines, m.LeftGutterFunc(GutterContext{
Index: i + m.YOffset,
TotalLines: m.TotalLineCount(),
Soft: idx > 0,
})+truncatedLine)
if m.LeftGutterFunc != nil {
truncatedLine = m.LeftGutterFunc(GutterContext{
Index: i + m.YOffset,
TotalLines: m.TotalLineCount(),
Soft: idx > 0,
}) + truncatedLine
}
wrappedLines = append(wrappedLines, truncatedLine)
idx += maxWidth
}
}
Expand All @@ -375,10 +386,13 @@ func (m Model) softWrap(lines []string, maxWidth int) []string {
func (m Model) prependColumn(lines []string) []string {
result := make([]string, len(lines))
for i, line := range lines {
result[i] = m.LeftGutterFunc(GutterContext{
Index: i + m.YOffset,
TotalLines: m.TotalLineCount(),
}) + line
if m.LeftGutterFunc != nil {
line = m.LeftGutterFunc(GutterContext{
Index: i + m.YOffset,
TotalLines: m.TotalLineCount(),
}) + line
}
result[i] = line
}
return result
}
Expand Down Expand Up @@ -687,27 +701,10 @@ 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 maxLineWidth(lines []string) int {
maxlen := 0
result := 0
for _, line := range lines {
llen := ansi.StringWidth(line)
if llen > maxlen {
maxlen = llen
}
result = max(result, ansi.StringWidth(line))
}
return maxlen
return result
}

0 comments on commit 55a73b9

Please sign in to comment.