Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(v2) tidying up #649

Merged
merged 6 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion filepicker/filepicker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1.0.20240919172237-265996c29bea
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1.0.20240919172237-265996c29b
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1.0.20240919172237-265996c29bea/go.mod h1:j0gn4ft5CE7NDYNZjAA3hBM8t2OPjI8urxuAD0oR4w8=
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=
Expand Down
3 changes: 1 addition & 2 deletions help/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package memoization implement a simple memoization cache. It's designed to
// improve performance in textarea.
package memoization

import (
Expand Down
4 changes: 2 additions & 2 deletions runeutil/runeutil.go → internal/runeutil/runeutil.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
File renamed without changes.
10 changes: 6 additions & 4 deletions list/defaultitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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"})
Expand Down Expand Up @@ -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,
}
}

Expand Down
12 changes: 6 additions & 6 deletions list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,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)
Expand All @@ -284,7 +284,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
Expand Down Expand Up @@ -717,7 +717,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)
Expand Down Expand Up @@ -1148,7 +1148,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")
Expand All @@ -1164,7 +1164,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)
}

Expand All @@ -1181,7 +1181,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 ""
}

Expand Down
8 changes: 4 additions & 4 deletions list/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")).
Expand All @@ -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)

Expand All @@ -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"}).
Expand Down
2 changes: 1 addition & 1 deletion paginator/paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,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:
Expand Down
2 changes: 1 addition & 1 deletion progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,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
}
Expand Down
24 changes: 12 additions & 12 deletions spinner/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
)

Expand Down
6 changes: 3 additions & 3 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,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(),
Expand Down Expand Up @@ -215,9 +215,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):
Expand Down
16 changes: 9 additions & 7 deletions textarea/textarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -1121,7 +1123,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)))
Expand Down Expand Up @@ -1200,7 +1202,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.
Expand Down Expand Up @@ -1409,7 +1411,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{})
Expand Down
6 changes: 3 additions & 3 deletions textinput/textinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -553,7 +553,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.KeyPressMsg:
Expand Down Expand Up @@ -649,7 +649,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
Expand Down
6 changes: 3 additions & 3 deletions viewport/viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (m *Model) HalfViewDown() {
return
}

m.LineDown(m.Height / 2)
m.LineDown(m.Height / 2) //nolint:mnd
}

// HalfViewUp moves the view up by half the height of the viewport.
Expand All @@ -153,7 +153,7 @@ func (m *Model) HalfViewUp() {
return
}

m.LineUp(m.Height / 2)
m.LineUp(m.Height / 2) //nolint:mnd
}

// LineDown moves the view down by the given number of lines.
Expand Down Expand Up @@ -246,7 +246,7 @@ func (m Model) updateAsModel(msg tea.Msg) Model {
break
}

switch msg.Button {
switch msg.Button { //nolint:exhaustive
case tea.MouseWheelDown:
m.LineDown(m.MouseWheelDelta)

Expand Down
Loading