diff --git a/docs/examples/simple.py b/docs/examples/simple.py index 764afdba8..b4784ccd5 100644 --- a/docs/examples/simple.py +++ b/docs/examples/simple.py @@ -3,26 +3,9 @@ from textual.widgets import Static class TextApp(App): - CSS = """ - Screen { - background: darkblue; - color: white; - layout: vertical; - } - Static { - height: auto; - padding: 2; - border: heavy white; - background: #ffffff 30%; - content-align: center middle; - /**/ - } - - """ - def compose(self) -> ComposeResult: yield Static("Hello") yield Static("[b]World![/b]") -app = TextApp() +app = TextApp(css_path="simple.css") diff --git a/docs/index.md b/docs/index.md index 8e6772806..17ac22c5f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -16,10 +16,15 @@ Textual seeks to lower the difficulty level of building a TUI by borrowing devel --8<-- "docs/examples/simple.py" ``` +=== "CSS" + + ```python + --8<-- "docs/examples/simple.css" + ``` + === "Terminal" - ```{.textual columns="40" lines="10"} - --8<-- "docs/examples/simple.py" + ```{.textual path="docs/examples/simple.py" columns="80" lines="24"} ``` Textual also offers a number of enhancements over traditional TUI applications by taking advantage of improvements to terminal software and the hardware it runs on. Terminals are a far cry from their roots in ancient hardware and dial-up modems, yet much of the software that runs on them hasn't kept pace. diff --git a/poetry.lock b/poetry.lock index ee576a108..d0a40e58a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -650,7 +650,7 @@ pyyaml = "*" [[package]] name = "rich" -version = "12.4.2" +version = "12.4.3" description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" category = "main" optional = false @@ -773,7 +773,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "f84a265bad38b0894c5f13b1f1abeec5b5a9f4aab3aab44d90e761103a756743" +content-hash = "eba121f02e102fd9c551a654bcfab3028ec4fc05fe9b4cf7d5f64002e3586ba0" [metadata.files] aiohttp = [ @@ -1360,8 +1360,8 @@ pyyaml-env-tag = [ {file = "pyyaml_env_tag-0.1.tar.gz", hash = "sha256:70092675bda14fdec33b31ba77e7543de9ddc88f2e5b99160396572d11525bdb"}, ] rich = [ - {file = "rich-12.4.2-py3-none-any.whl", hash = "sha256:abcecd4444fa27cf84de412f713305e0d5481c941f12fc202fa4fc6711f80feb"}, - {file = "rich-12.4.2.tar.gz", hash = "sha256:cd8c809da089740f4bd94fa6d544cf23421d4bad34988569c2d03fdbdb858f0d"}, + {file = "rich-12.4.3-py3-none-any.whl", hash = "sha256:26ef784599a9ab905ade34ff28904e4fbe9bce16e02c33c78b0229551104c146"}, + {file = "rich-12.4.3.tar.gz", hash = "sha256:e7550ca19aec51b216ae4c34bfce82e94a0c79bdbf95cafbf42f343d0fb3f45a"}, ] six = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, diff --git a/pyproject.toml b/pyproject.toml index 57089f7fa..fb8460d6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,9 +22,8 @@ textual = "textual.cli.cli:run" [tool.poetry.dependencies] python = "^3.7" -rich = "^12.4.2" - -#rich = {git = "git@github.com:willmcgugan/rich", rev = "link-id"} +rich = "^12.4.3" +#rich = {path="../rich", develop=true} click = "8.1.2" importlib-metadata = "^4.11.3" typing-extensions = { version = "^4.0.0", python = "<3.8" } diff --git a/src/textual/_compositor.py b/src/textual/_compositor.py index 631292e98..f04d42888 100644 --- a/src/textual/_compositor.py +++ b/src/textual/_compositor.py @@ -561,14 +561,14 @@ class Compositor: width, height = self.size screen_region = Region(0, 0, width, height) - if not full: + if full: + update_regions: set[Region] = set() + else: update_regions = self._dirty_regions.copy() self._dirty_regions.clear() if screen_region in update_regions: # If one of the updates is the entire screen, then we only need one update update_regions.clear() - else: - update_regions = set() if update_regions: # Create a crop regions that surrounds all updates diff --git a/src/textual/_doc.py b/src/textual/_doc.py index 755eab1b5..56083ece1 100644 --- a/src/textual/_doc.py +++ b/src/textual/_doc.py @@ -2,13 +2,35 @@ import os def format_svg(source, language, css_class, options, md, attrs, **kwargs): + os.environ["TEXTUAL"] = "headless" os.environ["TEXTUAL_SCREENSHOT"] = "0.1" os.environ["COLUMNS"] = attrs.get("columns", "80") os.environ["LINES"] = attrs.get("lines", "24") - app_vars = {} - exec(source, app_vars) - app = app_vars["app"] - app.run() - svg = app._screenshot + path = attrs.get("path") + + print("PATH", path) + if path: + cwd = os.getcwd() + examples_path, filename = os.path.split(path) + print(examples_path, filename) + try: + os.chdir(examples_path) + with open(filename, "rt") as python_code: + source = python_code.read() + app_vars = {} + exec(source, app_vars) + app = app_vars["app"] + app.run() + svg = app._screenshot + + finally: + os.chdir(cwd) + + else: + app_vars = {} + exec(source, app_vars) + app = app_vars["app"] + app.run() + svg = app._screenshot return svg diff --git a/src/textual/layouts/vertical.py b/src/textual/layouts/vertical.py index e216f963d..34cabea02 100644 --- a/src/textual/layouts/vertical.py +++ b/src/textual/layouts/vertical.py @@ -38,7 +38,12 @@ class VerticalLayout(Layout): displayed_children = cast("list[Widget]", parent.displayed_children) for widget, box_model, margin in zip(displayed_children, box_models, margins): content_width, content_height = box_model.size - offset_x = widget.styles.align_width(content_width, size.width) + offset_x = ( + widget.styles.align_width( + content_width, size.width - box_model.margin.width + ) + + box_model.margin.left + ) region = Region(offset_x, y, content_width, content_height) add_placement(WidgetPlacement(region, widget, 0)) y += region.height + margin