summaryrefslogtreecommitdiff
path: root/rag/tui.py
blob: ead4f717f2ce168acf00b3de93938ec70834888f (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from textual import events
from textual.app import App, ComposeResult
from textual.containers import Vertical, Container, VerticalScroll
from textual.widgets import Input, Label, Markdown, Static, TabbedContent, TabPane

JESSICA = """
# Lady Jessica

Bene Gesserit and concubine of Leto, and mother of Paul and Alia.
"""

PAUL = """
# Paul Atreides

Son of Leto and Jessica.
"""

TEXT = """\
Docking a widget removes it from the layout and fixes its position, aligned to either the top, right, bottom, or left edges of a container.

Docked widgets will not scroll out of view, making them ideal for sticky headers, footers, and sidebars.

"""

class TabbedApp(App):
    """An example of tabbed content."""

    CSS_PATH = "static/styles.tcss"

    BINDINGS = [
        ("n", "show_tab('rag')", "Rag"),
        ("e", "show_tab('settings')", "Settings"),
    ]

    def compose(self) -> ComposeResult:
        """Compose app with tabbed content."""
        # Add the TabbedContent widget
        with Container(id="rag"):
            with VerticalScroll(id="references"):
                yield Static("test3", classes="context")
            with VerticalScroll(id="history"):
                yield Static(TEXT * 10, classes="output")
            with Vertical(id="chat"):
                yield Static("test2", classes="input")
        # with TabbedContent(initial="rag"):
        #     with TabPane("RAG", id="rag"):  # First tab
        #         # yield Input(placeholder=">>", id="chat")
        #         yield Static("test1", classes="chat")
        #         yield Static("test", classes="context")
            # with TabPane("Settings", id="settings"):
            #     yield Markdown(JESSICA)
            #     with TabbedContent("Paul", "Alia"):
            #         yield TabPane("Paul", Label("First child"))
            #         yield TabPane("Alia", Label("Second child"))

    def action_show_tab(self, tab: str) -> None:
        """Switch to a new tab."""
        self.get_child_by_type(TabbedContent).active = tab

    def on_key(self, event: events.Key) -> None:
        if event.key == "s":
            self.action_show_tab("settings")
        if event.key == "r":
            self.action_show_tab("rag")
        if event.key == "q":
            self.exit()


if __name__ == "__main__":
    app = TabbedApp()
    app.run()