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

Table Centering #576

Open
englid-sf opened this issue Aug 6, 2024 · 0 comments
Open

Table Centering #576

englid-sf opened this issue Aug 6, 2024 · 0 comments
Milestone

Comments

@englid-sf
Copy link

Describe the bug
Between bubbles v1.17.1 and v1.18.0 table centering has changed. In the latter version, table contents does not line up with titles under certain conditions.

Setup
Please complete the following information along with version numbers, if applicable.

  • OS - macOS
  • Shell - zsh
  • Terminal Emulator - iTerm
  • Terminal Multiplexer - n/a
  • Locale - en_US.UTF-8

To Reproduce
Steps to reproduce the behavior:

  1. Create a table model from bubbles
  2. Include Align(lipgloss.Center) in the table's style.
  3. Include some other line of text that exceeds the the table's width.
  4. Run

Source Code
The issue can be easily reproduced using the table examples within bubbletea by adding the following diff:

diff --git a/examples/table/main.go b/examples/table/main.go
index 76736f3..acbda6a 100644
--- a/examples/table/main.go
+++ b/examples/table/main.go
@@ -3,6 +3,7 @@ package main
 import (
        "fmt"
        "os"
+    "strings"

        "github.com/charmbracelet/bubbles/table"
        tea "github.com/charmbracelet/bubbletea"
@@ -11,7 +12,8 @@ import (

 var baseStyle = lipgloss.NewStyle().
        BorderStyle(lipgloss.NormalBorder()).
-       BorderForeground(lipgloss.Color("240"))
+       BorderForeground(lipgloss.Color("240")).
+       Align(lipgloss.Center)

 type model struct {
        table table.Model
@@ -43,7 +45,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 }

 func (m model) View() string {
-       return baseStyle.Render(m.table.View()) + "\n"
+       return baseStyle.Render(strings.Repeat("*", 80) + "\n" + m.table.View()) + "\n"
 }

 func main() {
@@ -162,6 +164,7 @@ func main() {
                table.WithRows(rows),
                table.WithFocused(true),
                table.WithHeight(7),
+               table.WithWidth(80),
        )

        s := table.DefaultStyles()

Expected behavior
I expect the contents of the table to be aligned with the titles of the table.

Screenshots
Before:
before

After:
after

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

No branches or pull requests

3 participants