Text log scroll end (#2127)

* added switches

* snapshot

* changelog

* tweak docstrings

* Update src/textual/widgets/_text_log.py

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>

---------

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
This commit is contained in:
Will McGugan
2023-03-23 17:21:13 +00:00
committed by GitHub
parent 8fd3ccb32c
commit 3fe04f7b2d
5 changed files with 211 additions and 3 deletions

View File

@@ -0,0 +1,35 @@
from textual.app import App, ComposeResult
from textual.widgets import TextLog
from textual.containers import Horizontal
class TextLogScrollApp(App):
CSS = """
TextLog{
width: 1fr;
height: 10;
}
"""
def compose(self) -> ComposeResult:
with Horizontal():
# Don't scroll on write
yield TextLog(id="textlog1", auto_scroll=False)
# Scroll on write
yield TextLog(id="textlog2", auto_scroll=True)
# Scroll on write, but disabled on write()
yield TextLog(id="textlog3", auto_scroll=True)
def on_ready(self) -> None:
lines = [f"Line {n}" for n in range(20)]
for line in lines:
self.query_one("#textlog1", TextLog).write(line)
for line in lines:
self.query_one("#textlog2", TextLog).write(line)
for line in lines:
self.query_one("#textlog3", TextLog).write(line, scroll_end=False)
if __name__ == "__main__":
app = TextLogScrollApp()
app.run()