Skip to content

Commit c0c03e8

Browse files
authored
Merge pull request #1039 from Textualize/unmount
unmount event
2 parents 7b31f63 + 07dced3 commit c0c03e8

26 files changed

+591
-721
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [0.2.2] - Unreleased
99

10+
### Fixed
11+
12+
- Fixed issue where scrollbars weren't being unmounted
13+
1014
### Changed
1115

1216
- DOMQuery now raises InvalidQueryFormat in response to invalid query strings, rather than cryptic CSS error
17+
- Dropped quit_after, screenshot, and screenshot_title from App.run, which can all be done via auto_pilot
18+
- Widgets are now closed in reversed DOM order
19+
20+
### Added
21+
22+
- Added Unmount event
23+
- Added App.run_async method
24+
- Added App.run_test context manager
25+
- Added auto_pilot to App.run and App.run_async
26+
- Added Widget._get_virtual_dom to get scrollbars
27+
- Added size parameter to run and run_async
1328

1429
## [0.2.1] - 2022-10-23
1530

docs/reference/pilot.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: textual.pilot

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ nav:
107107
- "reference/index.md"
108108
- "reference/message_pump.md"
109109
- "reference/message.md"
110+
- "reference/pilot.md"
110111
- "reference/query.md"
111112
- "reference/reactive.md"
112113
- "reference/screen.md"

src/textual/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def __call__(self, *args: object, **kwargs) -> None:
5151
try:
5252
app = active_app.get()
5353
except LookupError:
54-
raise LoggerError("Unable to log without an active app.") from None
54+
print_args = (*args, *[f"{key}={value!r}" for key, value in kwargs.items()])
55+
print(*print_args)
56+
return
5557
if app.devtools is None or not app.devtools.is_connected:
5658
return
5759

src/textual/_doc.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Iterable
66

77
from textual.app import App
8+
from textual.pilot import Pilot
89
from textual._import_app import import_app
910

1011

@@ -18,7 +19,7 @@ def format_svg(source, language, css_class, options, md, attrs, **kwargs) -> str
1819
path = cmd[0]
1920

2021
_press = attrs.get("press", None)
21-
press = [*_press.split(",")] if _press else ["_"]
22+
press = [*_press.split(",")] if _press else []
2223
title = attrs.get("title")
2324

2425
print(f"screenshotting {path!r}")
@@ -28,7 +29,7 @@ def format_svg(source, language, css_class, options, md, attrs, **kwargs) -> str
2829
rows = int(attrs.get("lines", 24))
2930
columns = int(attrs.get("columns", 80))
3031
svg = take_svg_screenshot(
31-
None, path, press, title, terminal_size=(rows, columns)
32+
None, path, press, title, terminal_size=(columns, rows)
3233
)
3334
finally:
3435
os.chdir(cwd)
@@ -45,9 +46,9 @@ def format_svg(source, language, css_class, options, md, attrs, **kwargs) -> str
4546
def take_svg_screenshot(
4647
app: App | None = None,
4748
app_path: str | None = None,
48-
press: Iterable[str] = ("_",),
49+
press: Iterable[str] = (),
4950
title: str | None = None,
50-
terminal_size: tuple[int, int] = (24, 80),
51+
terminal_size: tuple[int, int] = (80, 24),
5152
) -> str:
5253
"""
5354
@@ -63,25 +64,29 @@ def take_svg_screenshot(
6364
the screenshot was taken.
6465
6566
"""
66-
rows, columns = terminal_size
67-
68-
os.environ["COLUMNS"] = str(columns)
69-
os.environ["LINES"] = str(rows)
7067

7168
if app is None:
69+
assert app_path is not None
7270
app = import_app(app_path)
7371

72+
assert app is not None
73+
7474
if title is None:
7575
title = app.title
7676

77-
app.run(
78-
quit_after=5,
79-
press=press or ["ctrl+c"],
77+
async def auto_pilot(pilot: Pilot) -> None:
78+
app = pilot.app
79+
await pilot.press(*press)
80+
svg = app.export_screenshot(title=title)
81+
app.exit(svg)
82+
83+
svg = app.run(
8084
headless=True,
81-
screenshot=True,
82-
screenshot_title=title,
85+
auto_pilot=auto_pilot,
86+
size=terminal_size,
8387
)
84-
svg = app._screenshot
88+
assert svg is not None
89+
8590
return svg
8691

8792

0 commit comments

Comments
 (0)