fix: use lipgloss.Width instead of runewidth.StringWidth

This commit is contained in:
Maas Lalani 2023-05-11 22:21:09 -04:00
parent ece25c7789
commit 92c890e717
No known key found for this signature in database
GPG key ID: 5A6ED5CBF1A0A000
4 changed files with 5 additions and 8 deletions

View file

@ -16,7 +16,6 @@ import (
"github.com/charmbracelet/bubbles/paginator"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/mattn/go-runewidth"
)
type model struct {
@ -158,7 +157,7 @@ func (m model) View() string {
if i == m.index%m.height {
s.WriteString(m.cursorStyle.Render(m.cursor))
} else {
s.WriteString(strings.Repeat(" ", runewidth.StringWidth(m.cursor)))
s.WriteString(strings.Repeat(" ", lipgloss.Width(m.cursor)))
}
if item.selected {

View file

@ -17,7 +17,6 @@ import (
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/mattn/go-runewidth"
"github.com/sahilm/fuzzy"
)
@ -77,7 +76,7 @@ func (m model) View() string {
if i == m.cursor {
s.WriteString(m.indicatorStyle.Render(m.indicator))
} else {
s.WriteString(strings.Repeat(" ", runewidth.StringWidth(m.indicator)))
s.WriteString(strings.Repeat(" ", lipgloss.Width(m.indicator)))
}
// If there are multiple selections mark them, otherwise leave an empty space

View file

@ -11,7 +11,6 @@ import (
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/mattn/go-runewidth"
)
type model struct {
@ -41,7 +40,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
if m.autoWidth {
m.textinput.Width = msg.Width - runewidth.StringWidth(m.textinput.Prompt) - 1
m.textinput.Width = msg.Width - lipgloss.Width(m.textinput.Prompt) - 1
}
case tea.KeyMsg:
switch msg.String() {

View file

@ -8,7 +8,7 @@ import (
"github.com/alecthomas/kong"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/mattn/go-runewidth"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/gum/internal/stdin"
"github.com/charmbracelet/gum/style"
@ -59,7 +59,7 @@ func (o Options) Run() error {
var columns = make([]table.Column, 0, len(columnNames))
for i, title := range columnNames {
width := runewidth.StringWidth(title)
width := lipgloss.Width(title)
if len(o.Widths) > i {
width = o.Widths[i]
}