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

REPL on Windows doesn't display console cursor after moving #20348

Closed
advanceddeveloper opened this issue Apr 27, 2018 · 29 comments
Closed

REPL on Windows doesn't display console cursor after moving #20348

advanceddeveloper opened this issue Apr 27, 2018 · 29 comments
Labels
confirmed-bug Issues with confirmed bugs. repl Issues and PRs related to the REPL subsystem. windows Issues and PRs related to the Windows platform. wontfix Issues that will not be fixed.

Comments

@advanceddeveloper
Copy link

  • Version: v10.0.0
  • Platform: Windows 10
  • Subsystem: repl?

Steps to reproduce the problem:

  1. Open command prompt or powershell
  2. Type node and then press enter
  3. Write some code
  4. Press left arrow on the keyboard
  5. The console cursor becomes invisible for a second

What is the expected behavior?

The cursor should be visible immediatelly after moving (to the left or to the right). For example, command prompt automatically displays the cursor after it has been moved. The cursor has blink rate, but after user moves it, it should be visible no matter if at the given moment the blink rate timeout suggest that it should be visible or invisible.

What went wrong?

After moving, the cursor becomes hidden. It makes navigating through the code very hard. Users need to wait one second after moving in order to find out where the cursor currently is. Using CTRL+ helps a bit skipping whole words, but it is still very hard to navigate if the code is large.

Is it a problem with Node.js itself?

I am pretty sure it is. The reason I think it is Node.js issue and not issue with command prompt is because other programs which provide REPL functionalities properly display the cursor after moving (reset the cursor blink rate to visible state). For example, Python 3.6 properly handles it.

Did this work before?

I think no.

@addaleax addaleax added repl Issues and PRs related to the REPL subsystem. windows Issues and PRs related to the Windows platform. labels Apr 27, 2018
@addaleax
Copy link
Member

@nodejs/platform-windows

@bzoz
Copy link
Contributor

bzoz commented Apr 27, 2018

Sorry, I can't reproduce this.

Does this also happen with other Node versions? Are you using some console emulators (like ConEmu)? Could you maybe provide a screenshot of the issue?

@advanceddeveloper
Copy link
Author

@bzoz

Does this also happen with other Node versions?

Reproduces with all versions from node 4 to node 10 (not tested below node 4).

Are you using some console emulators

No, just pure command prompt.

Could you maybe provide a screenshot of the issue?

Not sure how screenshot can help, so I'm providing screen recording. It is recorded on windows 8.1, which means that it also reproduces on windows 8.1

@tniessen
Copy link
Member

I can't reproduce this either. Does it happen every time you try it?

Until we are able to reproduce your problem, let's make sure that it is not caused by a third-party application. Could you post the output of listdlls -v PID for the PIDs of cmd.exe, conhost.exe and node.exe while node is running? (Preferably on a 64 bit Windows 10 system with a 64 bit node build, if possible.) You can find the PIDs using procexp, both tools are provided as part of the Sysinterals Suite.

@advanceddeveloper
Copy link
Author

@tniessen

Does it happen every time you try it?

Yes. Here are the outputs of listdlls -v PID: outputs.zip

@advanceddeveloper
Copy link
Author

Any updates on this? I mean, it is one week from posting and still nobody is able to reproduce? Weird...

@tniessen
Copy link
Member

tniessen commented May 3, 2018

@advanceddeveloper Sorry, I still was not able to reproduce the problem. The DLL list looks normal, I just had you check because we had issues with third-party applications injecting DLLs into node / the console in the past.

Is someone else from @nodejs/platform-windows able to reproduce?

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented May 3, 2018

It seems I can reproduce a tiny delay on Windows 7 x64 with cmd.exe:

Screenshot:

repl


@advanceddeveloper
Copy link
Author

advanceddeveloper commented May 3, 2018

The "tiny" delay that can be seen on the screenshot is, as I can tell exactly half-time of the blink rate, which means that the visibility state of the cursor in node.js repl is set to invisible immediatelly after moving, while in batch repl (cmd itself) or python repl cursor state is set to visible after moving. I think vsemozhetbyt's screenshot confirms the issue (I also checked on windows 7 32 and 64 bit, but on virtual machine, and able to reproduce).

Also, notice that the blink rate may vary (on my pc it is 1 second), so the "tiny" delay becomes "not so tiny" delay.

@bzoz
Copy link
Contributor

bzoz commented May 8, 2018

I don't know if we can do anything about it. I've took a quick look into Python code to see if there is anything related that could be used to improve Node, but could not find anything.

@advanceddeveloper can you try adjusting cursor blink rate in the Keyboard properties in the Control Panel? Other than that I don't think we can do anything in Node to fix this.

@advanceddeveloper
Copy link
Author

Can you try adjusting cursor blink rate in the Keyboard properties in the Control Panel?

I really like my 1sec blink rate and don't want to change it.

I've took a quick look into Python code to see if there is anything related that could be used to improve Node, but could not find anything.

Since all programs that use REPL (not only python) which I tested so far properly handle cursor movement, I guess that these programs don't do anything special, but probably Node.js does something (I suppose unintentionally) that hides the cursor after moving. As I know, command prompt and powershell by default show the cursor, so if the cursor after moving is hidden, it probably means that the application itself (here node.js) hides the cursor.

I don't know if we can do anything about it.

I'm sorry, but I can't believe that this is impossible to fix. Either Node.js or some of it's libraries affect cursor behavior. As I said, all other programs properly handle it (even programs written in C and compiled with gcc (which also means that no extra code is needed to properly handle cursor movement)), so even if some library which is used by node.js creates this weird behavior, I am sure Node.js can override it and implement correct behavior. I mean, currently it is very hard (read: impossible) to navigate in the REPL.

@seishun
Copy link
Contributor

seishun commented May 8, 2018

I can reproduce this issue on Windows 7 but not Windows 10.

@bzoz
Copy link
Contributor

bzoz commented May 8, 2018

Did more investigation: Python just uses fgets. We are running the console in raw mode and move the cursor ourselves. Thanks to this we support some fancy commands, persistent history, tab auto competition, etc.

The readline module is moving the cursor by itself when arrow keys are used. I can only guess that moving the cursor restarts blinking animation loop and thus we have a cursor that disappears.

@seishun seishun added the confirmed-bug Issues with confirmed bugs. label May 8, 2018
@ghost
Copy link

ghost commented Jul 15, 2018

Able to reproduce with reported v10.0.0 and latest v10.6.0 using Windows 8.1 x64.

@IonutArhire
Copy link

I have the exact same problem. Node v8.11.1. I tried both command promt and powershell. I'm using Windows 7.

@Hakerh400
Copy link
Contributor

Calling SetConsoleCursorInfo with CONSOLE_CURSOR_INFO::bVisible set to TRUE after moving the cursor would probably solve this problem.

@bzoz
Copy link
Contributor

bzoz commented Sep 12, 2018

@Hakerh400: tried that (added a call to uv_tty_set_cursor_visibility in uv_tty_move_caret) - does not help.

I don't know if we can do anything else besides suggesting using ConEmu in which the cursor is visible when moving.

@noahbrenner
Copy link

I have the same issue, which has been present with every version of Node I've used. I'm running Windows 7 32-bit. My current version of Node is 10.6.0. I get the disappearing cursor no matter whether I start Node through cmd, PowerShell, Git Bash, or the node.exe executable directly.

@vtjnash
Copy link
Contributor

vtjnash commented Jan 2, 2019

We've seen the same problem in Julia, and a quick google search reveals others with the problem too. From some more googling, I think MS may have fixed this bug in microsoft/terminal#269

@noahbrenner
Copy link

Thanks for doing that digging @vtjnash! I'm not entirely sure that console bug is the same as this one though, at least from the initial report in that issue you linked to:

Type into windows cmd. Cursor disappears and does not reappear.

In the Node REPL, the cursor does consistently reappear. The issue is that its blink cycle restarts in the hidden state whenever the cursor is moved, so it remains hidden until the cursor stops moving and half the blink rate's time elapses.

(Powershell apears unaffected though)

As I mentioned in an earlier comment, I get exactly the same issue whether I start the Node REPL from cmd, PowerShell, or Git Bash.

Is the problem you've been running into with Julia closer to this behavior?


I'm not familiar with the implementation of the REPL, so I could be way of track, but these might be some helpful bits of info:

  • The issue is caused specifically by the cursor moving, not by key presses. For example, if the cursor is at the end of a line and I press or hold the right arrow key, the cursor continues to blink and does not disappear, because it has nowhere to move to.
  • I don't have this disappearing cursor issue from a plain console prompt in cmd, PowerShell, or Git Bash, it's only in the Node REPL.
  • I also don't have the issue in other languages' REPLs, such as Python's.
  • I do see the issue in variations of the Node REPL, such as ts-node.

From my (admittedly uninformed) observations: The only places I see the disappearing cursor problem is when running Node. I don't see it in any other console-related interface, which seems to suggest that the issue stems from something in Node's codebase or dependencies.

If your research turned up any examples that match this specific behavior more closely, it might be helpful if you would share them here to help in tracking down a solution.

@vtjnash
Copy link
Contributor

vtjnash commented Jan 2, 2019

I've seen that depending on various options (such as turning on the legacy rendering and the capabilities of the program driving the console) the effect can vary from almost instant (visible only as screen tearing) to full loss of cursor for many seconds after all input stops. That all seems to be the fault of conhost though, since I don't see any option for a program to command the cursor to blink/stop. If you follow the link above, you can see some example screen caps of the different ways people have seen that problem manifest for various applications and settings.

@bzoz
Copy link
Contributor

bzoz commented Jan 2, 2019

microsoft/terminal#269 is an issue with Win10, this is a issue withe the Win7 console (the old, legacy one).

From what I found out:

  • only the legacy console is affected
  • the cursor disappears when it is moved
  • changing blink rate does not affect this, nor does disabling it altogether
  • other REPLs are not affected, since they use "line mode"
  • Node uses "raw mode" to support autocompletition and history
  • Node works fine in ConEmu

@vtjnash
Copy link
Contributor

vtjnash commented Jan 2, 2019

For me (on Windows 10), the modern console can show undesirable cursor flickering, but the bad delays only happen with the legacy console enabled. But I see those same effects regardless of whether I'm running just cmd.exe or libuv. Additionally, I observe that changing the blink rate does affect this for me, as does disabling it altogether, if I'm using line mode (including through libuv), but does not significantly affect this delay when in "raw mode".

The original report was for Windows 10, so maybe there's multiple bugs here? I have a Win7 VM, but haven't booted it in years.

@bzoz
Copy link
Contributor

bzoz commented Jan 3, 2019

Multiple bugs, or maybe using legacy console in Win10?

@ihnorton
Copy link

This looks related to libuv/libuv#852 and libuv/libuv#866

@bzoz
Copy link
Contributor

bzoz commented Aug 22, 2019

No, those are not related, the issue is the console window itself. On older Windows, moving the cursor from the code restarts the blinking cycle to "not shown". There is nothing we can do about it, except to suggest using console emulator like ConEmu.

Python and other apps do not show this issue, because they are using consoles built-in "get line" functionality. Node uses its own custom method, which allows us to have history and autocompletion.

Besides switching REPL to use line mode (which I don't think will happen) I can't see anything that we can do about this issue.

@seishun
Copy link
Contributor

seishun commented Aug 22, 2019

This is an issue only on older Windows, so I suggest just closing. Windows 7 support ends in January and almost no one uses Windows 8.1.

@seishun
Copy link
Contributor

seishun commented Aug 22, 2019

They will have to upgrade within the next 5 months, and I guarantee their next OS won't be Windows 8.1.

@bzoz already explained that other REPLs don't have this problem because they are more primitive.

@bzoz
Copy link
Contributor

bzoz commented Aug 22, 2019

Most other languages do not offer as feature-rich REPL as Node does.

I don't think there is anything sensible we can do here. Upgrading Windows or installing ConEmu is a valid solution. We could make a line-mode REPL but I don't think it is worth the effort.

I'm going to close this issue.

@bzoz bzoz closed this as completed Aug 22, 2019
@bzoz bzoz added the wontfix Issues that will not be fixed. label Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. repl Issues and PRs related to the REPL subsystem. windows Issues and PRs related to the Windows platform. wontfix Issues that will not be fixed.
Projects
None yet
Development

No branches or pull requests