Skip to content

[BUG] Ellipsize last column in a table #4097

@elboulangero

Description

@elboulangero

Hello,

I'm trying to create a table where the last column ellipsizes.

First try

#!/usr/bin/python3

from rich.console import Console
from rich.table import Table

console = Console()
table = Table()
table.add_column("Name")
table.add_column("Age")
table.add_column("Country")
table.add_column("Biography", overflow='ellipsis')
table.add_row("Louis", "14", "France", "The quick brown fox jumps over the lazy dog. " * 2)
console.print(table)
$ COLUMNS=80 ./rich-test.py 
┏━━━━━━━┳━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Name  ┃ Age ┃ Country ┃ Biography                                            ┃
┡━━━━━━━╇━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Louis │ 14  │ France  │ The quick brown fox jumps over the lazy dog. The     │
│       │     │         │ quick brown fox jumps over the lazy dog.             │
└───────┴─────┴─────────┴──────────────────────────────────────────────────────┘

The last column doesn't ellipsize, instead it wraps. Let's try again with no_wrap=True.

Second try

#!/usr/bin/python3

from rich.console import Console
from rich.table import Table

console = Console()
table = Table()
table.add_column("Name")
table.add_column("Age")
table.add_column("Country")
table.add_column("Biography", no_wrap=True, overflow='ellipsis')
table.add_row("Louis", "14", "France", "The quick brown fox jumps over the lazy dog. " * 2)
console.print(table)
$ COLUMNS=80 ./rich-test.py 
┏┳┳┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃┃┃┃ Biography                                                                 ┃
┡╇╇╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
││││ The quick brown fox jumps over the lazy dog. The quick brown fox jumps o… │
└┴┴┴───────────────────────────────────────────────────────────────────────────┘

The last column does ellipsize, however all the other columns are useless. Is it a bug in the way rich allocates the width?

Expected output

What I'm trying to achieve is that:

┏━━━━━━━┳━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Name  ┃ Age ┃ Country ┃ Biography                                            ┃
┡━━━━━━━╇━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Louis │ 14  │ France  │ The quick brown fox jumps over the lazy dog. The…    │
└───────┴─────┴─────────┴──────────────────────────────────────────────────────┘

Ie. the last column should display as much as it can of the text, and ellipsize the rest. Other columns shouldn't be affected and should have enough width to display their content.

Am I doing it wrong, or is there a bug with column width allocation?

Platform

I'm running Linux Debian unstable.

$ python3 --version
Python 3.13.12

$ dpkg -l | grep -E '(python3-rich)'
ii  python3-rich     15.0.0-1 
Details

If you're using Rich in a terminal:

$ python3 -m rich.diagnose
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=211 ColorSystem.TRUECOLOR>                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = 'truecolor'                                                   │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 52                                                            │
│    is_alt_screen = False                                                         │
│ is_dumb_terminal = False                                                         │
│   is_interactive = True                                                          │
│       is_jupyter = False                                                         │
│      is_terminal = True                                                          │
│   legacy_windows = False                                                         │
│         no_color = False                                                         │
│          options = ConsoleOptions(                                               │
│                        size=ConsoleDimensions(width=211, height=52),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=211,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=52,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=211, height=52)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 211                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'CLICOLOR': None,              │
│     'COLORTERM': 'truecolor',      │
│     'COLUMNS': None,               │
│     'JPY_PARENT_PID': None,        │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'LINES': None,                 │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': None,          │
│     'TERM': 'xterm-256color',      │
│     'TTY_COMPATIBLE': None,        │
│     'TTY_INTERACTIVE': None,       │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Linux"
pip freeze | grep rich
I am not using pip to install anything on my system, only debian packages.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions