Files
textual/tests/snapshot_tests/snapshot_apps/scroll_to_center.py
Rodrigo Girão Serrão bb2c31ba35 Add --port option to textual console. (#2258)
* Add --port option to textual console.

* Changelog.

* Address review feedback.

* Mark unpredictable test as xfail.

This test gets an xfail mark until #2254 is open.

* Make DEVTOOLS_PORT a constant.

Related review: https://github.com/Textualize/textual/pull/2258\#discussion_r1165210395

* Factor logic into function.

Related review: https://github.com/Textualize/textual/pull/2258\#discussion_r1165298259

* Remove dead import.
2023-04-13 11:57:35 +01:00

41 lines
1.2 KiB
Python

from textual.app import App, ComposeResult
from textual.containers import HorizontalScroll, VerticalScroll
from textual.widgets import Label
class MyApp(App[None]):
CSS = """
VerticalScroll, HorizontalScroll {
border: round $primary;
}
#vertical {
height: 21;
}
HorizontalScroll {
height: auto;
}
"""
def compose(self) -> ComposeResult:
with VerticalScroll():
yield Label(("SPAM\n" * 205)[:-1])
with VerticalScroll():
yield Label(("SPAM\n" * 53)[:-1])
with VerticalScroll(id="vertical"):
yield Label(("SPAM\n" * 78)[:-1])
with HorizontalScroll():
yield Label(("v\n" * 17)[:-1])
yield Label("@" * 302)
yield Label("[red]>>bullseye<<[/red]", id="bullseye")
yield Label("@" * 99)
yield Label(("SPAM\n" * 49)[:-1])
yield Label(("SPAM\n" * 51)[:-1])
yield Label(("SPAM\n" * 59)[:-1])
def key_s(self) -> None:
self.screen.scroll_to_center(self.query_one("#bullseye"))
if __name__ == "__main__":
MyApp().run()