mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
* 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>
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
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()
|