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

Clear console before running command in exec -w #10983

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

gridbugs
Copy link
Collaborator

@gridbugs gridbugs commented Oct 1, 2024

This fixes an issue where the build progress stays on the console after the build completes, and the first line of the output of the command being exec'd is printed on teh same line as the build progress.

A side effect of this change is that some of the "Build Successful" messages in tests get truncated.

Fixes #10922

@gridbugs gridbugs requested a review from emillon October 1, 2024 08:53
@@ -10,16 +10,16 @@ between each change to its code.
> EOF

$ dune exec --watch ./foo.exe &
Success, waiting for filesystem changes...
changes...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does it remove the entire sentence, minus the last word, here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No idea! It only happens in cram tests - not when running dune from a terminal. I've tried various Console functions to see if I could fix the test behaviour while also maintaining the behaviour when you run the command interactively but nothing works. Maybe something to do with how cram tests capture the output of commands? @rgrinberg any ideas?

Copy link
Member

Choose a reason for hiding this comment

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

No idea, sorry. But shouldn't you restore the terminal after the process finishes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's non-trivial to restore the terminal after the process finishes because dune doesn't wait for the process to finish and continues to run in watch mode, printing to the terminal itself while the new process runs in the background. This means that running programs that change terminal settings (such as programs with tuis) from exec watch mode will have a bad ux, especially because after every change dune will kill the process and launch a new process, possibly leaving the terminal in a bad state. It's definitely something we could improve in the future but not necessary to solve this issue.

@rgrinberg rgrinberg force-pushed the fix-10922 branch 2 times, most recently from 5a89166 to 763a085 Compare October 18, 2024 16:30
bin/exec.ml Outdated
|> Fiber.map
~f:
(Result.map ~f:(fun prog ->
Console.reset ();
Copy link
Collaborator

@Alizter Alizter Oct 25, 2024

Choose a reason for hiding this comment

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

Rather than doing this directly, let's be consistent with dune build watch mode.

Suggested change
Console.reset ();
Scheduler.maybe_clear_screen ~details_hum:[] config;

You will need to thread config from run_eagar_watch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for this suggestions. This somehow fixed the issues in tests where the success messages was being truncated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh I see, because maybe_clear_screen has different behaviour when running inside the dune repo than when running in the wild.

@Alizter
Copy link
Collaborator

Alizter commented Oct 25, 2024

Are we aware that all the exec-watch tests are disabled? i.e. (enable_if false).

@gridbugs
Copy link
Collaborator Author

Are we aware that all the exec-watch tests are disabled? i.e. (enable_if false).

Yep, there's a big comment here explaining why (they're flakey).

This fixes an issue where the build progress stays on the console after
the build completes, and the first line of the output of the command
being exec'd is printed on teh same line as the build progress.

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
@gridbugs gridbugs merged commit 05124de into ocaml:main Oct 31, 2024
26 of 27 checks passed
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.

Missing newline in "dune exec -w"
4 participants