textual
textual copied to clipboard
Ability to stop and start/resume application/driver
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()
Is this different from what's described in #1093 ?
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
I think this is now resolved by #4064?