Пример #1
0
    def __init__(self):
        self.lira = LiraApp()
        self.lira.setup()

        self.content = ContentArea(self)
        self.status = StatusBar(self)

        self.menu = SidebarMenu(self)
        self.menu.reset(BooksList(self))

        self.container = HSplit(
            [
                VSplit(
                    [
                        self.menu,
                        self.content,
                    ],
                    padding=Dimension.exact(1),
                    padding_char="│",
                    padding_style=theme["separator"],
                ),
                self.status,
            ],
            padding=Dimension.exact(1),
            padding_char="─",
            padding_style=theme["separator"],
        )
        self.app = Application(
            layout=Layout(self.container),
            key_bindings=self.get_key_bindings(),
            mouse_support=True,
            full_screen=True,
            style=style,
            after_render=self._ready,
        )
Пример #2
0
class TestStatusBar:
    def _get_current_status(self, window):
        return to_container(window).get_children()[0].content.buffer.text

    def setup_method(self):
        tui = mock.MagicMock()
        self.window = StatusBar(tui=tui)

    def test_update_status(self):
        assert self._get_current_status(self.window) == ""

        msg = "Hello world!"
        self.window.update_status(msg)
        assert self._get_current_status(self.window) == msg

        assert len(self.window.history) == 1
        assert self.window.history[0] == msg

    @pytest.mark.asyncio
    async def test_notify(self):
        assert self._get_current_status(self.window) == ""

        msg = "Hello world!"
        await self.window.notify(msg, delay=0.1)

        assert len(self.window.history) == 2
        assert self.window.history[0] == msg
        assert self.window.history[1] == ""
        assert self._get_current_status(self.window) == ""
Пример #3
0
 def setup_method(self):
     tui = mock.MagicMock()
     self.window = StatusBar(tui=tui)
Пример #4
0
class TerminalUI:
    def __init__(self):
        self.lira = LiraApp()
        self.lira.setup()

        self.content = ContentArea(self)
        self.status = StatusBar(self)

        self.menu = SidebarMenu(self)
        self.menu.reset(BooksList(self))

        self.container = HSplit(
            [
                VSplit(
                    [
                        self.menu,
                        self.content,
                    ],
                    padding=Dimension.exact(1),
                    padding_char="│",
                    padding_style=theme["separator"],
                ),
                self.status,
            ],
            padding=Dimension.exact(1),
            padding_char="─",
            padding_style=theme["separator"],
        )
        self.app = Application(
            layout=Layout(self.container),
            key_bindings=self.get_key_bindings(),
            mouse_support=True,
            full_screen=True,
            style=style,
            after_render=self._ready,
        )

    def get_key_bindings(self):
        keys = KeyBindings()

        @keys.add(Keys.Tab)
        def _(event):
            focus_next(event)

        @keys.add(Keys.BackTab)
        def _(event):
            focus_previous(event)

        @keys.add(Keys.ControlC)
        @keys.add(Keys.ControlQ)
        def _(event):
            exit_app()

        return keys

    def _ready(self, app):
        key = "__is_ready"
        if not hasattr(self, key):
            set_title()
            self.status.notify("Ready!")
            setattr(self, key, True)

    def run(self):
        self.app.run()