Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
costrouc opened this issue Nov 9, 2022 · 4 comments
Closed

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

costrouc opened this issue Nov 9, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@costrouc
Copy link

costrouc commented Nov 9, 2022

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()
@alextremblay
Copy link

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

@JoshKarpel
Copy link
Contributor

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! #1150

@TomJGooding
Copy link
Contributor

I think this is now resolved by #4064?

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
6 participants