File: screenshot.py

package info (click to toggle)
textual-textarea 0.17.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 720 kB
  • sloc: python: 3,195; makefile: 25
file content (33 lines) | stat: -rw-r--r-- 835 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import asyncio
from pathlib import Path

from textual.app import App, ComposeResult
from textual.widgets.text_area import Selection

from textual_textarea import TextEditor

contents = (Path(__file__).parent / "sample_code.py").open("r").read()


class TextApp(App, inherit_bindings=False):
    def compose(self) -> ComposeResult:
        self.editor = TextEditor(
            language="python",
            theme="monokai",
            use_system_clipboard=True,
        )
        yield self.editor

    def on_mount(self) -> None:
        self.editor.focus()


async def take_screenshot() -> None:
    app = TextApp()
    async with app.run_test(size=(80, 24)):
        app.editor.text = contents
        app.editor.selection = Selection((7, 12), (8, 12))
        app.save_screenshot("textarea.svg")


asyncio.run(take_screenshot())