textual icon indicating copy to clipboard operation
textual copied to clipboard

Ability to stop and start/resume application/driver

Open costrouc opened this issue 1 year ago • 3 comments

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:

  • suspends k9s
  • opens given editor (emacs, vim, vi, etc.) via exec
  • resume k9s for terminal keyboard events etc.

I have started to experiment with exposing this in textual but can't seem to "resume" textual after stopping the driver. I'm likely doing this the wrong way. It doesn't seem to respond to keyboard events after calling self._driver.start_application_mode().

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()

costrouc avatar Nov 09 '22 16:11 costrouc

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

alextremblay avatar Nov 10 '22 02:11 alextremblay

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

JoshKarpel avatar Nov 10 '22 03:11 JoshKarpel

I think this is now resolved by #4064?

TomJGooding avatar Jan 31 '24 14:01 TomJGooding

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

github-actions[bot] avatar Mar 19 '24 15:03 github-actions[bot]