rmyorston / busybox-w32

WIN32 native port of BusyBox.
https://frippery.org/busybox
Other
674 stars 124 forks source link

Ctrl+C in a process which emits color control codes causes misaligned text prompt #372

Closed doctorpangloss closed 10 months ago

doctorpangloss commented 10 months ago

You'll have to watch this to the bitter end (about 21s) hJOCV8iZUT

Reproduction:

  1. Start a process which emits multiple lines with mixed color codes, like gradle.
  2. Interrupt the process using Ctrl+C
  3. Observe the prompt is now glitched, where it will appear misaligned.
  4. Observe the misalignment persists throughout the session

In this gif, the exact reproduction is:

  1. gradle init and follow the prompts.
  2. Start some process like gradle test or gradle javaToolchains which is slow.
  3. During the 1s it is actually running, try to interrupt it with Ctrl+C.

Reproduces on latest unicode and non-unicode prerelease builds. This is using Windows Terminal with sh -ilX.

rmyorston commented 10 months ago

Unable to reproduce. When I execute gradle run and hit Ctrl+C I get the prompt

Terminate batch job (Y/N)?

Whichever I choose the shell prompt returns and everything is normal.

doctorpangloss commented 10 months ago

I spam Ctrl+C while it's running. Shortly after it starts and has printed some output, but before it has exited normally. This is with the gradle executable installed by choco install -y gradle. You ought not to see a batch job notification.

doctorpangloss commented 10 months ago

this is one of those, a QA tester walks into a bar, walks backwards into a bar, walks through the door with her eyes closed... sort of bugs.

rmyorston commented 10 months ago

I still can't reproduce the issue. However, I suspect it's nothing to do with colour control codes, as my attempts to replicate the issue with them have met with similar ill success.

Moreover, looking at the output it seems the problem is not restricted to the prompt, as the output from ls is similarly affected. It appears only line feeds are being processed on output.

My suspicion is that Gradle is setting DISABLE_NEWLINE_AUTO_RETURN.

Try the latest prerelease, which unsets it.

doctorpangloss commented 10 months ago

LlHpERzDWH

image

Still occurs. The best reproduction is:

  1. cd newdirectory
  2. gradle init.
  3. Hit Ctrl+C while the "EXECUTING" text appears.
  4. gradle init again.
  5. Observe the cursor goes down a row, and does not return to the beginning of the column.
  6. Ctrl-C after you are asked to enter a selection.
  7. Observe the prompt is not returned to the first column.
  8. Observe pressing Ctrl+C causes busybox to start writing the prompt below the current cursor position and not return to the first column.
rmyorston commented 10 months ago

OK, I've reproduced the problem. In the Gradle bin directory there's a Windows batch file and a Unix shell script to start the program. I was using the batch file while it appears Scoop set up the shell script. The problem occurs when Gradle on Windows is started with the Unix shell script. Whatever.

My suspicion that the issue was related to the terminal mode was correct, it was the fix that was faulty. Try the latest prerelease.

doctorpangloss commented 10 months ago

resolved

the newline weirdness appeared in a lot of places when interrupting processes, so this is a huge boon for me, thanks so much for the diligence on the issue