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

Restore cursor after SIGINT during dialogue #4841

Merged
merged 4 commits into from
Jun 14, 2024
Merged

Conversation

xdoardo
Copy link
Contributor

@xdoardo xdoardo commented Jun 12, 2024

As per title. This PR adds a setup function to AsyncCliCommand with a default implementation that installs a signal handler that restores the cursor (see console-rs/dialoguer#77). Solves #4837

@xdoardo xdoardo requested a review from syrusakbary as a code owner June 12, 2024 16:49
@syrusakbary
Copy link
Member

Note: this PR is trying to fix #4837

Copy link
Member

@syrusakbary syrusakbary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find surprising that we were not using ctrlc before. Because I know for journaling we listen on Ctrl^C.

We need to make sure that handler for WASIX and this one are not colliding before merging the PR (please check with @john-sharratt )

@xdoardo
Copy link
Contributor Author

xdoardo commented Jun 12, 2024

(I force-pushed to remove a commit that was not related to this PR).

The signal handler is installed in those commands that implement the AsyncCliComand trait, and run is not one of them - this, of course, if you meant a conflict on the signal handling from the WASIX layer. I'll check with John.

@syrusakbary
Copy link
Member

Just more context: the current signal handler hops in when saving journaling upon doing ctrl-c

@xdoardo xdoardo requested a review from theduke June 13, 2024 14:21
@@ -70,12 +71,21 @@ pub(crate) trait AsyncCliCommand: Send + Sync {
type Output: Send + Sync;

async fn run_async(self) -> Result<Self::Output, anyhow::Error>;

fn setup(&self) -> Result<(), anyhow::Error> {
ctrlc::set_handler(move || {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need for the separate crtlc dependency, we can use tokio::signal::ctrl_c .

With the current structure it'll be easiest to just run it in a spawned task.

@@ -70,12 +71,21 @@ pub(crate) trait AsyncCliCommand: Send + Sync {
type Output: Send + Sync;

async fn run_async(self) -> Result<Self::Output, anyhow::Error>;

fn setup(&self) -> Result<(), anyhow::Error> {
ctrlc::set_handler(move || {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we should probably restrict this to TTYs.

stdin.is_terminal().

See https://doc.rust-lang.org/stable/std/io/trait.IsTerminal.html#tymethod.is_terminal

@theduke
Copy link
Contributor

theduke commented Jun 13, 2024

@syrusakbary this will not be invoked for the run command, so it won't interfere with the journaling.

@syrusakbary syrusakbary merged commit d70bd7b into main Jun 14, 2024
62 checks passed
@syrusakbary syrusakbary deleted the install-handler branch June 14, 2024 14:59
Copy link
Contributor

@theduke theduke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants