Skip to content

[BUG] First style of assembled text affects subsequent non-styled Text #3847

@antoine-gallix

Description

@antoine-gallix
  • [ x] I've checked docs and closed issues for possible solutions.
  • [ x] I can't find my issue in the FAQ.

Describe the bug

I build a Text instance by adding multiple Text together with +. When the first element has a color style, it becomes the default for subsequent non-styled elements. This does not happen when the first element has no style. The following code reproduces this:

from rich import print
from rich.text import Text

# works as expected
print(
    Text("normal") # white
    + Text("red", style="red") # red
    + Text("blue", style="blue") # blue
    + Text("normal") # white
)

# first style becomes default for non-styled elements
print(
    Text("red", style="red") # red
    + Text("normal") # also red!
    + Text("blue", style="blue") # blue
    + Text("normal") # red again!
)

# workaround; start with empty text
print(
    Text() # invisible
    + Text("red", style="red") # red
    + Text("normal") # white
    + Text("blue", style="blue") # blue
    + Text("normal") # white
)

Platform

Click to expand

platform: Fedora Linux 42 (Workstation Edition)
terminal: alacritty 0.15.1
python: 3.13.7
rich: 14.1.0

rich diagnose

╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface. │
│ │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ color_system = None │
│ encoding = 'utf-8' │
│ file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> │
│ height = 38 │
│ is_alt_screen = False │
│ is_dumb_terminal = False │
│ is_interactive = False │
│ is_jupyter = False │
│ is_terminal = False │
│ legacy_windows = False │
│ no_color = False │
│ options = ConsoleOptions( │
│ size=ConsoleDimensions(width=169, height=38), │
│ legacy_windows=False, │
│ min_width=1, │
│ max_width=169, │
│ is_terminal=False, │
│ encoding='utf-8', │
│ max_height=38, │
│ justify=None, │
│ overflow=None, │
│ no_wrap=False, │
│ highlight=None, │
│ markup=None, │
│ height=None │
│ ) │
│ quiet = False │
│ record = False │
│ safe_box = True │
│ size = ConsoleDimensions(width=169, height=38) │
│ soft_wrap = False │
│ stderr = False │
│ style = None │
│ tab_size = 8 │
│ width = 169 │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─── <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': 'alacritty', │
│ 'TTY_COMPATIBLE': None, │
│ 'TTY_INTERACTIVE': None, │
│ 'VSCODE_VERBOSE_LOGGING': None │
│ } │
╰────────────────────────────────────╯
platform="Linux"

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