-
Notifications
You must be signed in to change notification settings - Fork 815
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
Application suspension #4064
Merged
Merged
Application suspension #4064
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pulling out the very core of Textualize#1541 to start to build it up again and experiment and test (getting into the forge so I can then pull it down onto Windows and test there).
This reverts commit db31c61. Didn't address the issue I was trying to understand.
While things are generally working fine on macOS (and possibly GNU/Linux, that's still to be tested), there is the "can't input anything, have to kill the terminal" issue on Windows. This worked in the PR a year ago, and this bit of code seems to be the difference so let's test that out.
Adding Josh Karpel as a co-author here; not because of the docstring, but the core idea started with Textualize#1541 and this is a reimplementation of that code in the current version of Textual. Co-authored-by: Josh Karpel <[email protected]>
This will be used by subclasses to say if the environment they pertain to permits a suspension of the application.
And by extension macOS and BSD, etc (the Linux driver is really a Un*x driver).
And, if it doesn't, raise an exception.
Borrowing heavily from Josh's testing. Co-authored-by: Josh Karpel <[email protected]>
While this is intended to be "experimental" at the moment, it needs to be in the API docs so that it can be linked to from the docs for the signals.
This adds a signal that is published before the suspension finally happens, and another once the application is back and running again.
darrenburns
reviewed
Jan 30, 2024
darrenburns
reviewed
Jan 30, 2024
Co-authored-by: Darren Burns <[email protected]>
While at the moment these are the thinnest of shims around stop/start, the idea here is that we're going to add an API that *promises* to handle suspend and resume of the application mode in the driver; unlike stop/start which just promise that it'll stop and start and there's no promise that a start can happen after a stop.
I realised that Driver.close exists so it makes sense to call that in the base class rather than special-case that down in the LinuxDriver.
willmcgugan
requested changes
Jan 31, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Just some suggestions, mostly doc related.
Co-authored-by: Will McGugan <[email protected]>
Co-authored-by: Will McGugan <[email protected]>
Co-authored-by: Will McGugan <[email protected]>
Co-authored-by: Will McGugan <[email protected]>
Co-authored-by: Will McGugan <[email protected]>
This was referenced Jan 31, 2024
@willmcgugan Changes made and doc-tweaks merged. |
willmcgugan
approved these changes
Jan 31, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
This was referenced Jan 31, 2024
This was referenced Aug 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
This PR adds two related features to Textual applications:
App.suspend
context manager that allows the dev to temporarily stop application mode to run some other code; a classic example would be shelling out to an external editor.App.action_suspend_process
) that, where appropriate (currently GNU/Linux and macOS, perhaps other Unix and Unix-like environments), suspends the application as the foreground task.App.suspend
Here's a simple example of using the
App.suspend
context manager:Screen.Recording.2024-01-30.at.13.24.40.mov
Suspend as foreground task
This PR also adds support for suspending the application as the foreground task. This is done by providing
App.action_suspend_process
as an action that can be bound to a key combination, the conventional choice being Ctrl+Z. This feature is only available on Unix and Unix-like operating systems (currently tested on GNU/Linux and macOS). On Windows it is a no-op. No matter the host operating system it is also a no-op when running under Textual Web.Screen.Recording.2024-01-30.at.13.30.05.mov
Suspend and resume signals
Because the developer may with to perform some actions as a suspend happens, or when a resume happens, this PR also makes use of the new
Signal
facility. The developer can subscribe toApp.app_suspend_signal
andApp.app_resume_signal
to be notified when a suspend or a resume happens.Using this, an example app with code like this in it (to log when a suspend and a resume happens):
will log the suspends and the resumes:
Screen.Recording.2024-01-30.at.14.18.38.mov
App.suspend and SuspendNotSupported
If
App.suspend
is called in an environment that isn't supported aSuspendNotSupported
exception will be raised. Using code like this:in the test application above, and then run under Textual Web, will show the above notification:
Screen.Recording.2024-01-30.at.14.24.32.mov