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):
|
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:
|
def compose(self) -> ComposeResult:
|
||||||
yield Static("Hello")
|
yield Static("Hello")
|
||||||
yield Static("[b]World![/b]")
|
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"
|
--8<-- "docs/examples/simple.py"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
=== "CSS"
|
||||||
|
|
||||||
|
```python
|
||||||
|
--8<-- "docs/examples/simple.css"
|
||||||
|
```
|
||||||
|
|
||||||
=== "Terminal"
|
=== "Terminal"
|
||||||
|
|
||||||
```{.textual columns="40" lines="10"}
|
```{.textual path="docs/examples/simple.py" columns="80" lines="24"}
|
||||||
--8<-- "docs/examples/simple.py"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
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]]
|
[[package]]
|
||||||
name = "rich"
|
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"
|
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
|
||||||
category = "main"
|
category = "main"
|
||||||
optional = false
|
optional = false
|
||||||
@@ -773,7 +773,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.7"
|
python-versions = "^3.7"
|
||||||
content-hash = "f84a265bad38b0894c5f13b1f1abeec5b5a9f4aab3aab44d90e761103a756743"
|
content-hash = "eba121f02e102fd9c551a654bcfab3028ec4fc05fe9b4cf7d5f64002e3586ba0"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
aiohttp = [
|
aiohttp = [
|
||||||
@@ -1360,8 +1360,8 @@ pyyaml-env-tag = [
|
|||||||
{file = "pyyaml_env_tag-0.1.tar.gz", hash = "sha256:70092675bda14fdec33b31ba77e7543de9ddc88f2e5b99160396572d11525bdb"},
|
{file = "pyyaml_env_tag-0.1.tar.gz", hash = "sha256:70092675bda14fdec33b31ba77e7543de9ddc88f2e5b99160396572d11525bdb"},
|
||||||
]
|
]
|
||||||
rich = [
|
rich = [
|
||||||
{file = "rich-12.4.2-py3-none-any.whl", hash = "sha256:abcecd4444fa27cf84de412f713305e0d5481c941f12fc202fa4fc6711f80feb"},
|
{file = "rich-12.4.3-py3-none-any.whl", hash = "sha256:26ef784599a9ab905ade34ff28904e4fbe9bce16e02c33c78b0229551104c146"},
|
||||||
{file = "rich-12.4.2.tar.gz", hash = "sha256:cd8c809da089740f4bd94fa6d544cf23421d4bad34988569c2d03fdbdb858f0d"},
|
{file = "rich-12.4.3.tar.gz", hash = "sha256:e7550ca19aec51b216ae4c34bfce82e94a0c79bdbf95cafbf42f343d0fb3f45a"},
|
||||||
]
|
]
|
||||||
six = [
|
six = [
|
||||||
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
|
{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]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.7"
|
python = "^3.7"
|
||||||
rich = "^12.4.2"
|
rich = "^12.4.3"
|
||||||
|
#rich = {path="../rich", develop=true}
|
||||||
#rich = {git = "git@github.com:willmcgugan/rich", rev = "link-id"}
|
|
||||||
click = "8.1.2"
|
click = "8.1.2"
|
||||||
importlib-metadata = "^4.11.3"
|
importlib-metadata = "^4.11.3"
|
||||||
typing-extensions = { version = "^4.0.0", python = "<3.8" }
|
typing-extensions = { version = "^4.0.0", python = "<3.8" }
|
||||||
|
|||||||
@@ -561,14 +561,14 @@ class Compositor:
|
|||||||
width, height = self.size
|
width, height = self.size
|
||||||
screen_region = Region(0, 0, width, height)
|
screen_region = Region(0, 0, width, height)
|
||||||
|
|
||||||
if not full:
|
if full:
|
||||||
|
update_regions: set[Region] = set()
|
||||||
|
else:
|
||||||
update_regions = self._dirty_regions.copy()
|
update_regions = self._dirty_regions.copy()
|
||||||
self._dirty_regions.clear()
|
self._dirty_regions.clear()
|
||||||
if screen_region in update_regions:
|
if screen_region in update_regions:
|
||||||
# If one of the updates is the entire screen, then we only need one update
|
# If one of the updates is the entire screen, then we only need one update
|
||||||
update_regions.clear()
|
update_regions.clear()
|
||||||
else:
|
|
||||||
update_regions = set()
|
|
||||||
|
|
||||||
if update_regions:
|
if update_regions:
|
||||||
# Create a crop regions that surrounds all updates
|
# Create a crop regions that surrounds all updates
|
||||||
|
|||||||
@@ -2,10 +2,32 @@ import os
|
|||||||
|
|
||||||
|
|
||||||
def format_svg(source, language, css_class, options, md, attrs, **kwargs):
|
def format_svg(source, language, css_class, options, md, attrs, **kwargs):
|
||||||
|
|
||||||
os.environ["TEXTUAL"] = "headless"
|
os.environ["TEXTUAL"] = "headless"
|
||||||
os.environ["TEXTUAL_SCREENSHOT"] = "0.1"
|
os.environ["TEXTUAL_SCREENSHOT"] = "0.1"
|
||||||
os.environ["COLUMNS"] = attrs.get("columns", "80")
|
os.environ["COLUMNS"] = attrs.get("columns", "80")
|
||||||
os.environ["LINES"] = attrs.get("lines", "24")
|
os.environ["LINES"] = attrs.get("lines", "24")
|
||||||
|
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 = {}
|
app_vars = {}
|
||||||
exec(source, app_vars)
|
exec(source, app_vars)
|
||||||
app = app_vars["app"]
|
app = app_vars["app"]
|
||||||
|
|||||||
@@ -38,7 +38,12 @@ class VerticalLayout(Layout):
|
|||||||
displayed_children = cast("list[Widget]", parent.displayed_children)
|
displayed_children = cast("list[Widget]", parent.displayed_children)
|
||||||
for widget, box_model, margin in zip(displayed_children, box_models, margins):
|
for widget, box_model, margin in zip(displayed_children, box_models, margins):
|
||||||
content_width, content_height = box_model.size
|
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)
|
region = Region(offset_x, y, content_width, content_height)
|
||||||
add_placement(WidgetPlacement(region, widget, 0))
|
add_placement(WidgetPlacement(region, widget, 0))
|
||||||
y += region.height + margin
|
y += region.height + margin
|
||||||
|
|||||||
Reference in New Issue
Block a user