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

Terminating TUI with ctrl+c on Windows causes terminal to act weird #8860

Open
1 task done
espenja opened this issue Jul 27, 2024 · 7 comments
Open
1 task done

Terminating TUI with ctrl+c on Windows causes terminal to act weird #8860

espenja opened this issue Jul 27, 2024 · 7 comments
Labels
kind: bug Something isn't working needs: triage New issues get this label. Remove it after triage owned-by: turborepo

Comments

@espenja
Copy link

espenja commented Jul 27, 2024

Verify canary release

  • I verified that the issue exists in the latest Turborepo canary release.

Link to code that reproduces this issue

https://github.com/espenja/turbo-mouse-scroll-tui

What package manager are you using / does the bug impact?

pnpm

What operating system are you using?

Windows

Which canary version will you have in your reproduction?

2.0.9

Describe the Bug

Running turbo watch dev on Windows and cancelling the process with ctrl+c does not gracefully shut down the process and causes the terminal to act in weird ways.

This happens when running turbo from global install (shown in video 1 in additional context).
Running turbo from pnpm does not seem to cause this "effect" (shown in video 2 in additional context).

What happens after ctrl+c after running global turbo watch dev

  • Residual fragments of tui's interface is left on the terminal
  • Scrolling with the mouse wheel acts like arrow up/down instead of scrolling the terminal window/buffer

Disclaimer: This is reported for 2.0.9 and not the canary release. Discussed this with @Zertsov on Discord and they said to report it anyway.

Tested with

  • Inside VSCode with pwsh with extensions enabled
  • Inside VSCode with pwsh with all extensions disabled
  • Outside of VSCode in Windows Terminal with pwsh
  • Outside of VSCode in GitBash MINGW64 with xterm

Expected Behavior

Expected behavior: Process exits to previous terminal state without fragments from TUI, and mouse wheel scrolls the terminal buffer/window
Actual behavior: Terminal has lots of fragments from TUI, and mouse wheel acts like arrow up and down and scrolls through terminal command history

To Reproduce

  • Be on Windows 11
  • Have turbo version 2.0.9 installed globally
  • clone reproduction repo: https://github.com/espenja/turbo-mouse-scroll-tui
  • pnpm install -g turbo
  • pnpm install
  • turbo watch dev
  • Cancel process with ctrl+c
  • Scroll with mouse in terminal
  • Observe mouse wheel acting like arrow up/down

Additional context

Screencap of what happens

Failure scenario: Screencap of running turbo as a global install and scrolling with mouse wheel after cancelling process with ctrl+c (clicking image will take you to a YouTube video showing what happens)

Running global turbo install with turbo watch dev

Working scenario: Screencap of running turbo from pnpm and scrolling with mouse wheel after cancelling process with ctrl+c (clicking image will take you to a YouTube video showing what happens)

Running global turbo install with turbo watch dev

Possibly related/similar bug reported in tmux repository

tmux/tmux#2148

@espenja espenja added kind: bug Something isn't working needs: triage New issues get this label. Remove it after triage owned-by: turborepo labels Jul 27, 2024
@espenja
Copy link
Author

espenja commented Jul 27, 2024

Additional information: After reporting issue #8861, I tested what I reported here in that reproduction branch too (which is a pure reproduction repo created with npx create-turbo@canary -e with-shell-command), and I am able to reproduce with 2.0.10-canary.0

@WillKirkmanM
Copy link
Contributor

Hey @espenja, it seems turborepo needs to flush the terminal to remove the fragments similar to how the clear command works. In the meantime there are two workarounds you can use:

Use CTRL+L / clear

This is to manually flush the terminal of the outputs.

Use Old Logging Style

Turborepo pushed an update which changed the default TUI from the old one to this new modal / tmux type editor. To go back to the old one, add this flag to your run command

--log-order=stream 

A full command would look like

bunx turbo dev --log-order=stream --filter web --env-mode loose

image

@espenja
Copy link
Author

espenja commented Jul 28, 2024

While ctrl+L clears the terminal, and running the old stream experience is an ok workaround, I think the issue still stands with tui. Look at this example:

2024-07-29.00-17-00.mp4

After having terminated the turbo process with ctrl+c the entire terminal is non-scrollable, even after clearing.
The mouse scroll wheel acts like arrow up/down, the scrollbar for the terminal itself is gone, even the terminal cursor indicator is gone. This doesn't go away until you either completely close the terminal or start another app (in the screen cap I show how I can reset the terminal to the original state by starting vim and closing it again)

My (completely uneducated) guess after having looked inside the code for TUI (I don't know Rust at all) would be that the ctrl+c handler in TUI somehow either crashes before it can run the cleanup function, or doesn't run it at all: https://github.com/vercel/turbo/blob/496def6068938f517b19d004032a4a6e02aa6f32/crates/turborepo-ui/src/tui/app.rs#L454

Within this cleanup function, it looks like all the things described in my issue would have been resolved:

  • Terminal is cleared
  • Mouse capture is disabled
  • Raw mode is disabled
  • Cursor is set to show

@lucas-labs
Copy link

In my case, after Ctrl+C, the terminal has no colors anymore.

image

@espenja
Copy link
Author

espenja commented Jul 29, 2024

I mentioned this in my original description as well, but another workaround is executing turbo from pnpm with pnpm exec turbo watch lint instead of global turbo turbo watch lint. Running with pnpm and pressing ctrl+c seems to exit the process just fine.

@WillKirkmanM
Copy link
Contributor

What version is pnpm's turbo?

@espenja
Copy link
Author

espenja commented Jul 30, 2024

It's the same version as global. I've tested all 2.x major versions, same thing happens with all of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working needs: triage New issues get this label. Remove it after triage owned-by: turborepo
Projects
None yet
Development

No branches or pull requests

3 participants