mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
refactor: switch to x/ansi for text manipulation (#505)
Need to be consistent with Lipgloss and https://github.com/charmbracelet/lipgloss/pull/279
This commit is contained in:
@@ -12,7 +12,6 @@ require (
|
|||||||
github.com/dustin/go-humanize v1.0.1
|
github.com/dustin/go-humanize v1.0.1
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0
|
github.com/lucasb-eyer/go-colorful v1.2.0
|
||||||
github.com/mattn/go-runewidth v0.0.15
|
github.com/mattn/go-runewidth v0.0.15
|
||||||
github.com/muesli/reflow v0.3.0
|
|
||||||
github.com/muesli/termenv v0.15.2
|
github.com/muesli/termenv v0.15.2
|
||||||
github.com/rivo/uniseg v0.4.7
|
github.com/rivo/uniseg v0.4.7
|
||||||
github.com/sahilm/fuzzy v0.1.1
|
github.com/sahilm/fuzzy v0.1.1
|
||||||
@@ -26,6 +25,7 @@ require (
|
|||||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||||
|
github.com/muesli/reflow v0.3.0 // indirect
|
||||||
golang.org/x/sync v0.7.0 // indirect
|
golang.org/x/sync v0.7.0 // indirect
|
||||||
golang.org/x/sys v0.20.0 // indirect
|
golang.org/x/sys v0.20.0 // indirect
|
||||||
golang.org/x/term v0.20.0 // indirect
|
golang.org/x/term v0.20.0 // indirect
|
||||||
|
|||||||
+4
-4
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/charmbracelet/bubbles/key"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/muesli/reflow/truncate"
|
"github.com/charmbracelet/x/ansi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultItemStyles defines styling for a default list item.
|
// DefaultItemStyles defines styling for a default list item.
|
||||||
@@ -155,15 +155,15 @@ func (d DefaultDelegate) Render(w io.Writer, m Model, index int, item Item) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prevent text from exceeding list width
|
// Prevent text from exceeding list width
|
||||||
textwidth := uint(m.width - s.NormalTitle.GetPaddingLeft() - s.NormalTitle.GetPaddingRight())
|
textwidth := m.width - s.NormalTitle.GetPaddingLeft() - s.NormalTitle.GetPaddingRight()
|
||||||
title = truncate.StringWithTail(title, textwidth, ellipsis)
|
title = ansi.Truncate(title, textwidth, ellipsis)
|
||||||
if d.ShowDescription {
|
if d.ShowDescription {
|
||||||
var lines []string
|
var lines []string
|
||||||
for i, line := range strings.Split(desc, "\n") {
|
for i, line := range strings.Split(desc, "\n") {
|
||||||
if i >= d.height-1 {
|
if i >= d.height-1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
lines = append(lines, truncate.StringWithTail(line, textwidth, ellipsis))
|
lines = append(lines, ansi.Truncate(line, textwidth, ellipsis))
|
||||||
}
|
}
|
||||||
desc = strings.Join(lines, "\n")
|
desc = strings.Join(lines, "\n")
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-5
@@ -17,8 +17,7 @@ import (
|
|||||||
"github.com/charmbracelet/bubbles/textinput"
|
"github.com/charmbracelet/bubbles/textinput"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/muesli/reflow/ansi"
|
"github.com/charmbracelet/x/ansi"
|
||||||
"github.com/muesli/reflow/truncate"
|
|
||||||
"github.com/sahilm/fuzzy"
|
"github.com/sahilm/fuzzy"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1075,7 +1074,7 @@ func (m Model) titleView() string {
|
|||||||
// Status message
|
// Status message
|
||||||
if m.filterState != Filtering {
|
if m.filterState != Filtering {
|
||||||
view += " " + m.statusMessage
|
view += " " + m.statusMessage
|
||||||
view = truncate.StringWithTail(view, uint(m.width-spinnerWidth), ellipsis)
|
view = ansi.Truncate(view, m.width-spinnerWidth, ellipsis)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1126,7 +1125,7 @@ func (m Model) statusView() string {
|
|||||||
|
|
||||||
if filtered {
|
if filtered {
|
||||||
f := strings.TrimSpace(m.FilterInput.Value())
|
f := strings.TrimSpace(m.FilterInput.Value())
|
||||||
f = truncate.StringWithTail(f, 10, "…")
|
f = ansi.Truncate(f, 10, "…")
|
||||||
status += fmt.Sprintf("“%s” ", f)
|
status += fmt.Sprintf("“%s” ", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1151,7 +1150,7 @@ func (m Model) paginationView() string {
|
|||||||
|
|
||||||
// If the dot pagination is wider than the width of the window
|
// If the dot pagination is wider than the width of the window
|
||||||
// use the arabic paginator.
|
// use the arabic paginator.
|
||||||
if ansi.PrintableRuneWidth(s) > m.width {
|
if ansi.StringWidth(s) > m.width {
|
||||||
m.Paginator.Type = paginator.Arabic
|
m.Paginator.Type = paginator.Arabic
|
||||||
s = m.Styles.ArabicPagination.Render(m.Paginator.View())
|
s = m.Styles.ArabicPagination.Render(m.Paginator.View())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import (
|
|||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/harmonica"
|
"github.com/charmbracelet/harmonica"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
"github.com/charmbracelet/x/ansi"
|
||||||
"github.com/lucasb-eyer/go-colorful"
|
"github.com/lucasb-eyer/go-colorful"
|
||||||
"github.com/muesli/reflow/ansi"
|
|
||||||
"github.com/muesli/termenv"
|
"github.com/muesli/termenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -283,7 +283,7 @@ func (m Model) View() string {
|
|||||||
func (m Model) ViewAs(percent float64) string {
|
func (m Model) ViewAs(percent float64) string {
|
||||||
b := strings.Builder{}
|
b := strings.Builder{}
|
||||||
percentView := m.percentageView(percent)
|
percentView := m.percentageView(percent)
|
||||||
m.barView(&b, percent, ansi.PrintableRuneWidth(percentView))
|
m.barView(&b, percent, ansi.StringWidth(percentView))
|
||||||
b.WriteString(percentView)
|
b.WriteString(percentView)
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user