Skip to content

fix(table): Use ansi.Truncate instead of runewidth.Truncate#884

Merged
andreynering merged 1 commit intocharmbracelet:v2-expfrom
jedevc:fix-table-truncate-v2
Feb 13, 2026
Merged

fix(table): Use ansi.Truncate instead of runewidth.Truncate#884
andreynering merged 1 commit intocharmbracelet:v2-expfrom
jedevc:fix-table-truncate-v2

Conversation

@jedevc
Copy link

@jedevc jedevc commented Feb 13, 2026

Originally from #883, retargeted against v2-exp as suggested by @andreynering.

runewidth.Truncate does not consider terminal escape characters - this means that if a table cell contains funky characters, then it will be incorrectly truncated.

  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

Minimal reproducer:

package main

import (
	"fmt"

	"charm.land/bubbles/v2/table"
	"charm.land/lipgloss/v2"
)

func main() {
	cols := []table.Column{{Title: "Name", Width: 7}}
	value := lipgloss.NewStyle().Foreground(lipgloss.Color("1")).Render("ABCDEFGH")
	rows := []table.Row{{value}}

	t := table.New(
		table.WithColumns(cols),
		table.WithWidth(20),
		table.WithRows(rows),
	)

	fmt.Println(t.View())
}

Before:

image

After:

image

runewidth.Truncate does not consider terminal escape characters - this
means that if a table cell contains funky characters, then it will be
incorrectly truncated.

Signed-off-by: Justin Chadwell <me@jedevc.com>
@jedevc jedevc requested a review from aymanbagabas as a code owner February 13, 2026 09:33
@jedevc
Copy link
Author

jedevc commented Feb 13, 2026

One thing I noted in v2 - if WithWidth isn't specified, then no output appears in the table body at all. Not sure if this is intended.

Copy link
Member

@andreynering andreynering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jedevc!

@andreynering andreynering merged commit d004225 into charmbracelet:v2-exp Feb 13, 2026
8 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants