mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
docs framework
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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.
|
||||
|
||||
8
poetry.lock
generated
8
poetry.lock
generated
@@ -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"},
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user