Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed
- Fixed `ConsoleOptions` propagation https://github.com/Textualize/rich/issues/4028

## [15.0.0] - 2026-04-12

### Changed
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ The following people have contributed to the development of Rich:
- [Aaron Stephens](https://github.com/aaronst)
- [Karolina Surma](https://github.com/befeleme)
- [Gabriele N. Tornetta](https://github.com/p403n1x87)
- [Kevin Van Brunt](https://github.com/kmvanbrunt)
- [Nils Vu](https://github.com/nilsvu)
- [Arian Mollik Wasi](https://github.com/wasi-master)
- [Jan van Wijk](https://github.com/jdvanwijk)
Expand Down
9 changes: 8 additions & 1 deletion rich/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ def __rich_console__(
) -> RenderResult:
render_str = console.render_str
renderables = [
render_str(renderable) if isinstance(renderable, str) else renderable
render_str(
renderable,
markup=options.markup,
emoji=options.emoji,
highlight=False,
)
if isinstance(renderable, str)
else renderable
for renderable in self.renderables
]
if not renderables:
Expand Down
18 changes: 16 additions & 2 deletions rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class ConsoleOptions:
"""Highlight override for render_str."""
markup: Optional[bool] = None
"""Enable markup when rendering strings."""
emoji: Optional[bool] = None
"""Enable emoji code."""
height: Optional[int] = None

@property
Expand Down Expand Up @@ -165,6 +167,7 @@ def update(
no_wrap: Union[Optional[bool], NoChange] = NO_CHANGE,
highlight: Union[Optional[bool], NoChange] = NO_CHANGE,
markup: Union[Optional[bool], NoChange] = NO_CHANGE,
emoji: Union[Optional[bool], NoChange] = NO_CHANGE,
height: Union[Optional[int], NoChange] = NO_CHANGE,
) -> "ConsoleOptions":
"""Update values, return a copy."""
Expand All @@ -185,6 +188,8 @@ def update(
options.highlight = highlight
if not isinstance(markup, NoChange):
options.markup = markup
if not isinstance(emoji, NoChange):
options.emoji = emoji
if not isinstance(height, NoChange):
if height is not None:
options.max_height = height
Expand Down Expand Up @@ -1319,7 +1324,10 @@ def render(
render_iterable = renderable.__rich_console__(self, _options)
elif isinstance(renderable, str):
text_renderable = self.render_str(
renderable, highlight=_options.highlight, markup=_options.markup
renderable,
highlight=_options.highlight,
markup=_options.markup,
emoji=_options.emoji,
)
render_iterable = text_renderable.__rich_console__(self, _options)
else:
Expand Down Expand Up @@ -1721,6 +1729,7 @@ def print(
no_wrap=no_wrap,
markup=markup,
highlight=highlight,
emoji=emoji,
)

new_segments: List[Segment] = []
Expand Down Expand Up @@ -2018,7 +2027,12 @@ def log(
new_segments: List[Segment] = []
extend = new_segments.extend
render = self.render
render_options = self.options
render_options = self.options.update(
justify=justify,
emoji=emoji,
markup=markup,
highlight=highlight,
)
for renderable in renderables:
extend(render(renderable, render_options))
buffer_extend = self._buffer.extend
Expand Down
2 changes: 1 addition & 1 deletion rich/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get(
return Measurement(0, 0)
if isinstance(renderable, str):
renderable = console.render_str(
renderable, markup=options.markup, highlight=False
renderable, markup=options.markup, emoji=options.emoji, highlight=False
)
renderable = rich_cast(renderable)
if is_renderable(renderable):
Expand Down
8 changes: 7 additions & 1 deletion rich/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ def __rich_console__(
if isinstance(self.title, Text):
title_text = self.title
else:
title_text = console.render_str(self.title, style="rule.text")
title_text = console.render_str(
self.title,
style="rule.text",
markup=options.markup,
emoji=options.emoji,
highlight=False,
)

title_text.plain = title_text.plain.replace("\n", " ")
title_text.expand_tabs()
Expand Down
8 changes: 7 additions & 1 deletion rich/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,13 @@ def render_annotation(
text: TextType, style: StyleType, justify: "JustifyMethod" = "center"
) -> "RenderResult":
render_text = (
console.render_str(text, style=style, highlight=False)
console.render_str(
text,
style=style,
highlight=False,
markup=render_options.markup,
emoji=render_options.emoji,
)
if isinstance(text, str)
else text
)
Expand Down
26 changes: 26 additions & 0 deletions tests/test_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,29 @@ def test_render():
result = render()
print(result)
print(repr(result))


def test_columns_emoji_propagation():
console = Console()
columns = Columns([":1234:"])

with console.capture() as capture:
console.print(columns, emoji=True)
assert "🔢" in capture.get()

with console.capture() as capture:
console.print(columns, emoji=False)
assert ":1234:" in capture.get()


def test_columns_markup_propagation():
console = Console(force_terminal=True, _environ={})
columns = Columns(["[blue]text[/blue]"])

with console.capture() as capture:
console.print(columns, markup=True)
assert "\x1b[34mtext\x1b[0m" in capture.get()

with console.capture() as capture:
console.print(columns, markup=False)
assert "[blue]text[/blue]" in capture.get()
18 changes: 18 additions & 0 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,24 @@ def test_update_options_markup() -> None:
assert options.update(markup=True).markup == True


def test_update_options_emoji() -> None:
console = Console()
options = console.options
assert options.update(emoji=False).emoji == False
assert options.update(emoji=True).emoji == True


def test_print_emoji() -> None:
console = Console()
with console.capture() as capture:
console.print(":1234:", emoji=True)
assert "🔢" in capture.get()

with console.capture() as capture:
console.print(":1234:", emoji=False)
assert ":1234:" in capture.get()


def test_print_width_zero() -> None:
console = Console()
with console.capture() as capture:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ def test_clamp():
assert measurement.clamp(None, 50) == Measurement(20, 50)
assert measurement.clamp(30, None) == Measurement(30, 100)
assert measurement.clamp(None, None) == Measurement(20, 100)


def test_measurement_emoji_propagation():
console = Console()
options = console.options

m_emoji = Measurement.get(console, options.update(emoji=True), ":1234:")
m_no_emoji = Measurement.get(console, options.update(emoji=False), ":1234:")

assert m_emoji.maximum < m_no_emoji.maximum
26 changes: 26 additions & 0 deletions tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,29 @@ def test_repr():
def test_error():
with pytest.raises(ValueError):
Rule(characters="")


def test_rule_emoji_propagation():
console = Console()
rule = Rule(title=":1234:")

with console.capture() as capture:
console.print(rule, emoji=True)
assert "🔢" in capture.get()

with console.capture() as capture:
console.print(rule, emoji=False)
assert ":1234:" in capture.get()


def test_rule_markup_propagation():
console = Console(force_terminal=True, _environ={})
rule = Rule(title="[blue]text[/blue]")

with console.capture() as capture:
console.print(rule, markup=True)
assert "\x1b[34mtext\x1b[0m" in capture.get()

with console.capture() as capture:
console.print(rule, markup=False)
assert "[blue]text[/blue]" in capture.get()
28 changes: 28 additions & 0 deletions tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,31 @@ def test_padding_width():
render = render_tables()
print(render)
print(repr(render))


def test_table_emoji_propagation():
console = Console()
table = Table()
table.add_row(":1234:")

with console.capture() as capture:
console.print(table, emoji=True)
assert "🔢" in capture.get()

with console.capture() as capture:
console.print(table, emoji=False)
assert ":1234:" in capture.get()


def test_table_markup_propagation():
console = Console(force_terminal=True, _environ={})
table = Table()
table.add_row("[blue]text[/blue]")

with console.capture() as capture:
console.print(table, markup=True)
assert "\x1b[34mtext\x1b[0m" in capture.get()

with console.capture() as capture:
console.print(table, markup=False)
assert "[blue]text[/blue]" in capture.get()