Textualize / textual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.
https://textual.textualize.io/
MIT License
25.65k stars 787 forks source link

Ability to stop and start/resume application/driver #1148

Closed costrouc closed 8 months ago

costrouc commented 2 years ago

To be added by @willmcgugan

I'm looking at creating an application similar to k9s which has the feature where within the curses application you can edit text via whatever your $EDITOR environment variable is set to. It does the following:

If possible it would be nice to have a way to easily suspend/resume the given textual application.

import tempfile
import subprocess

from rich.markdown import Markdown

from textual.app import App, ComposeResult
from textual import events
from textual.containers import Container
from textual.widgets import Footer, Header, Static

class GithubApp(App):
    """A working 'desktop' github interface for managing issues/discussions."""

    BINDINGS = [
        ("q", "quit", "Quit"),
        ("e", "edit", "Edit"),
    ]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def compose(self) -> ComposeResult:
        """Compose our UI."""
        yield Header()
        yield Container(
            Static(id="text", markup=True),
            Static(id="render", markup=True),
        )
        yield Footer()

    async def action_edit(self) -> None:
        self._driver.stop_application_mode()
        with tempfile.NamedTemporaryFile() as tempf:
            subprocess.run(f"$EDITOR {tempf.name}", shell=True)
            with open(tempf.name) as f:
                contents = f.read()
                self.query_one("#text", Static).update(contents)
                self.query_one("#render", Static).update(Markdown(contents))
        self._driver.start_application_mode()

if __name__ == "__main__":
    GithubApp().run()
alextremblay commented 2 years ago

Is this different from what's described in #1093 ?

JoshKarpel commented 2 years ago

It doesn't seem to respond to keyboard events after calling self._driver.start_application_mode().

I should have checked the issues - I just posted a PR related to this! https://github.com/Textualize/textual/pull/1150

TomJGooding commented 9 months ago

I think this is now resolved by #4064?

github-actions[bot] commented 8 months ago

Don't forget to star the repository!

Follow @textualizeio for Textual updates.