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

Add support for suspend and resume. #3727

Closed
willmcgugan opened this issue Nov 22, 2023 · 4 comments · Fixed by #4064
Closed

Add support for suspend and resume. #3727

willmcgugan opened this issue Nov 22, 2023 · 4 comments · Fixed by #4064
Assignees
Labels
enhancement New feature or request Task

Comments

@willmcgugan
Copy link
Collaborator

willmcgugan commented Nov 22, 2023

Textual swallows ctrl+Z which would normally allow the user to suspend the app. We should restore this behaviour.

There many be another issue for this somewhere, and some initial work.

This may require a little work on the driver code. Bear in mind there are several concrete implementations and we want to avoid breaking them. Suggest talking this through with @willmcgugan once you have a plan for this.

2d

@davep
Copy link
Contributor

davep commented Nov 22, 2023

Previous issue is #1582 and related PR is #1655 which, at the time, was working but stalled when it came to testing via the pilot.

@davep davep self-assigned this Jan 22, 2024
@davep davep added enhancement New feature or request Task labels Jan 22, 2024
@davep davep linked a pull request Jan 24, 2024 that will close this issue
@davep
Copy link
Contributor

davep commented Jan 24, 2024

While the bulk of this is now in place, I have run into one problem when it comes to SIGTSTP background of the app. With this PR in place, if you Ctrl+Z the app then fg it from the resulting shell it works fine. On the other hand if you first bg (which doesn't make sense for a full-screen application, of course, but it's something the user could attempt) and then fg you get the following:

╭─────────────────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────────────────╮
│ /Users/davep/develop/python/textual/src/textual/app.py:3375 in action_suspend_process                                                   │
│                                                                                                                                         │
│   3372 │   │   """                                                                                                                      │
│   3373 │   │   if not WINDOWS:                                                                                                          │
│   3374 │   │   │   try:                                                                                                                 │
│ ❱ 3375 │   │   │   │   with self.suspend():                                                                                             │
│   3376 │   │   │   │   │   os.kill(os.getpid(), signal.SIGTSTP)                                                                         │
│   3377 │   │   │   except SuspendNotSupported:                                                                                          │
│   3378 │   │   │   │   pass                                                                                                             │
│                                                                                                                                         │
│ ╭────────────────────────── locals ───────────────────────────╮                                                                         │
│ │ self = SplashApp(title='SplashApp', classes={'-dark-mode'}) │                                                                         │
│ ╰─────────────────────────────────────────────────────────────╯                                                                         │
│                                                                                                                                         │
│ /Users/davep/.pyenv/versions/3.11.6/lib/python3.11/contextlib.py:144 in __exit__                                                        │
│                                                                                                                                         │
│   141 │   def __exit__(self, typ, value, traceback):                                                                                    │
│   142 │   │   if typ is None:                                                                                                           │
│   143 │   │   │   try:                                                                                                                  │
│ ❱ 144 │   │   │   │   next(self.gen)                                                                                                    │
│   145 │   │   │   except StopIteration:                                                                                                 │
│   146 │   │   │   │   return False                                                                                                      │
│   147 │   │   │   else:                                                                                                                 │
│                                                                                                                                         │
│ ╭──────────────────────────────── locals ─────────────────────────────────╮                                                             │
│ │      self = <contextlib._GeneratorContextManager object at 0x106af29d0> │                                                             │
│ │ traceback = None                                                        │                                                             │
│ │       typ = None                                                        │                                                             │
│ │     value = None                                                        │                                                             │
│ ╰─────────────────────────────────────────────────────────────────────────╯                                                             │
│                                                                                                                                         │
│ /Users/davep/develop/python/textual/src/textual/app.py:3358 in suspend                                                                  │
│                                                                                                                                         │
│   3355 │   │   │   self._driver.close()                                                                                                 │
│   3356 │   │   │   with redirect_stdout(sys.__stdout__), redirect_stderr(sys.__stderr__):                                               │
│   3357 │   │   │   │   yield                                                                                                            │
│ ❱ 3358 │   │   │   self._driver.start_application_mode()                                                                                │
│   3359 │   │   │   self.app_resume_signal.publish()                                                                                     │
│   3360 │   │   else:                                                                                                                    │
│   3361 │   │   │   raise SuspendNotSupported(                                                                                           │
│                                                                                                                                         │
│ ╭────────────────────────── locals ───────────────────────────╮                                                                         │
│ │ self = SplashApp(title='SplashApp', classes={'-dark-mode'}) │                                                                         │
│ ╰─────────────────────────────────────────────────────────────╯                                                                         │
│                                                                                                                                         │
│ /Users/davep/develop/python/textual/src/textual/drivers/linux_driver.py:167 in start_application_mode                                   │
│                                                                                                                                         │
│   164 │   │   │   # defaults to ASCII EOT = Ctrl-D = 4.)                                                                                │
│   165 │   │   │   newattr[tty.CC][termios.VMIN] = 1                                                                                     │
│   166 │   │   │                                                                                                                         │
│ ❱ 167 │   │   │   termios.tcsetattr(self.fileno, termios.TCSANOW, newattr)                                                              │
│   168 │   │                                                                                                                             │
│   169 │   │   self.write("\x1b[?25l")  # Hide cursor                                                                                    │
│   170 │   │   self.write("\033[?1003h\n")                                                                                               │
│                                                                                                                                         │
│ ╭─────────────────────────────────────────────────────────── locals ───────────────────────────────────────────────────────────╮        │
│ │               loop = <_UnixSelectorEventLoop running=True closed=False debug=False>                                          │        │
│ │            newattr = [                                                                                                       │        │
│ │                      │   26626,                                                                                              │        │
│ │                      │   3,                                                                                                  │        │
│ │                      │   19200,                                                                                              │        │
│ │                      │   67,                                                                                                 │        │
│ │                      │   9600,                                                                                               │        │
│ │                      │   9600,                                                                                               │        │
│ │                      │   [                                                                                                   │        │
│ │                      │   │   b'\x04',                                                                                        │        │
│ │                      │   │   b'\xff',                                                                                        │        │
│ │                      │   │   b'\xff',                                                                                        │        │
│ │                      │   │   b'\x7f',                                                                                        │        │
│ │                      │   │   b'\x17',                                                                                        │        │
│ │                      │   │   b'\x15',                                                                                        │        │
│ │                      │   │   b'\x12',                                                                                        │        │
│ │                      │   │   b'\xff',                                                                                        │        │
│ │                      │   │   b'\x03',                                                                                        │        │
│ │                      │   │   b'\xff',                                                                                        │        │
│ │                      │   │   ... +10                                                                                         │        │
│ │                      │   ]                                                                                                   │        │
│ │                      ]                                                                                                       │        │
│ │ on_terminal_resize = <function LinuxDriver.start_application_mode.<locals>.on_terminal_resize at 0x106a5fc40>                │        │
│ │               self = <LinuxDriver SplashApp(title='SplashApp', classes={'-dark-mode'})>                                      │        │
│ │    send_size_event = <function LinuxDriver.start_application_mode.<locals>.send_size_event at 0x106a5c220>                   │        │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯        │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
error: (4, 'Interrupted system call')

Attempting something similar with vim (for example), works just fine; the process stays in a stopped state and resumes without a problem. I'll use a bit more time to dig into how the Linux driver works and/or the method used to SIGTSTP the application as I sense the issue will be around there.

It's also worth noting that this mostly works fine with Midnight Commander (as another example app to test), although I have managed to get it into a state where it's failing to properly process non-alphanumeric keys or mouse input.

@davep
Copy link
Contributor

davep commented Jan 29, 2024

+1d

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 Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants