From 461db5dcd6c1862d281a4798d26eb3808ccbba53 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Thu, 23 Mar 2023 14:56:35 +0000 Subject: [PATCH] enable console markup (#2122) * enable console markup * changelog * snapshot --- CHANGELOG.md | 6 + src/textual/app.py | 2 +- .../__snapshots__/test_snapshots.ambr | 160 ++++++++++++++++++ .../snapshot_apps/table_markup.py | 16 ++ tests/snapshot_tests/test_snapshots.py | 4 + 5 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 tests/snapshot_tests/snapshot_apps/table_markup.py diff --git a/CHANGELOG.md b/CHANGELOG.md index cc1be2443..82fcf0e5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Changed + +- Textual will now render strings within renderables (such as tables) as Console Markup by default. You can wrap your text with rich.Text() if you want the original behavior. https://github.com/Textualize/textual/issues/2120 + ## [0.16.0] - 2023-03-22 ### Added diff --git a/src/textual/app.py b/src/textual/app.py index 69b93f8e0..d024e43ef 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -319,7 +319,7 @@ class App(Generic[ReturnType], DOMNode): self.console = Console( file=file, - markup=False, + markup=True, highlight=False, emoji=False, legacy_windows=False, diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index a12d9621b..dcebac8a1 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -18553,6 +18553,166 @@ ''' # --- +# name: test_table_markup + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TableStaticApp + + + + + + + + + + ┏━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┓ + FooBar   baz       + ┡━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━┩ + Hello World!ItalicUnderline + └──────────────┴────────┴───────────┘ + + + + + + + + + + + + + + + + + + + + + + + + ''' +# --- # name: test_textlog_max_lines ''' diff --git a/tests/snapshot_tests/snapshot_apps/table_markup.py b/tests/snapshot_tests/snapshot_apps/table_markup.py new file mode 100644 index 000000000..a1f9e5a6c --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/table_markup.py @@ -0,0 +1,16 @@ +from textual.app import App, ComposeResult +from textual.widgets import Static + +from rich.table import Table + + +class TableStaticApp(App): + def compose(self) -> ComposeResult: + table = Table("[i green]Foo", "Bar", "baz") + table.add_row("Hello [bold magenta]World!", "[i]Italic", "[u]Underline") + yield Static(table) + + +if __name__ == "__main__": + app = TableStaticApp() + app.run() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 27676eb23..b7b003347 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -319,3 +319,7 @@ def test_remove_with_auto_height(snap_compare): def test_auto_table(snap_compare): assert snap_compare(SNAPSHOT_APPS_DIR / "auto-table.py", terminal_size=(120, 40)) + + +def test_table_markup(snap_compare): + assert snap_compare(SNAPSHOT_APPS_DIR / "table_markup.py")