1

Before you say anything, I know about right-clicking the cmd.exe window title and clicking "Properties" or "Defaults" and changing the color of the cursor. This is not what I mean for two reasons:

  1. It requires manual clicking instead of being a terminal command or escape sequence.
  2. Even if you do this, which I've tried, it doesn't hide the cursor even if the background is black and you set it to black, because it is "drawn" so that it's one pixel above the bottom line, meaning it draws a black line of pixels over whatever character happens to be at that position. (Also, it falls apart whenever the background changes, obviously.)

The same settings also allow you to change the "style" of the cursor, but none of those styles is called "none" or "empty". They are just slight variations of the blinking underscore. I am aware that you can set the blink rate globally in Windows, but that's also not relevant as it requires manual intervention and, again, doesn't hide the cursor anyway. I don't want to hide the cursor "in general" for app programs -- just for my own terminal scripts, "on demand".

I'm looking for a way to do this automatically and just for the terminal/"session" where the current script is run. (It's a PHP CLI one.)

I have tried numerous old ANSI escape sequences and whatnot; they are all seemingly ignored. My best guess at this point is that it's just not possible.

Please note that preventing the cursor from blinking, while slightly less annoying, would not solve this problem either since it would just be permanently covering the character in the first "column" on the current row.

It truly seems as if this just not is possible without downloading scary, sketchy, ancient MS-DOS executables which I don't exactly dream of trusting on my computer. I also don't want to use some third-party cmd.exe "replacer". These solutions are non-solutions to me because this is supposed to work on "vanilla" systems, whether they be Windows, Linux or Mac boxen.

I run a recent Windows 10 version but I don't have any "Windows Terminal" yet, so I can't tell if that allows this. Either way, PHP CLI on Windows appears to be closely tied to cmd.exe, so both PowerShell and Windows Terminal-related solutions aren't relevant for me at this time. Maybe in the future, when PHP on Windows starts using one of those or allows you to easily tell it to use them.

It would be quite swell to get rid of that obnoxious blinking cursor in good ol' cmd.exe.

1
  • 1
    Short answer: You can't.
    – DavidPostill
    Commented Oct 27, 2019 at 9:47

3 Answers 3

1

If you have windows 10, an ANSI escape sequence should work fine.

You can get the escape character with this:

for /F "delims=#" %a in ('prompt #$E# ^& for %a in ^(1^) do rem') do set esc=%a

Thus:

echo.%esc%[?25l

Would hide the cursor.

The letter l is the letter L, but not capitalized.

1

Here is a small C program to hide the cursor in a Windows console:

#include <Windows.h>

int main(void)
{
    HANDLE hStdOut = NULL;
    CONSOLE_CURSOR_INFO curInfo;

    hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleCursorInfo(hStdOut, &curInfo);
    curInfo.bVisible = FALSE;
    SetConsoleCursorInfo(hStdOut, &curInfo);

    return 0;
}

This code can be converted into other programming language where it has any Win32 wrapper, e.g. python, rust etc.

What this does:

This simple program retrieves the standard output handle in the current console. Then retrieves information about the size and visibility of the cursor for the specified console screen buffer and disables the cursor visibility by settings bVisible boolean value to false. Then set that configuration for the specified console screen buffer.

Used Win32 APIs:

0

A person called Aacini has published a program that hides the cursor, available from his article:
Advanced Batch features via auxiliary .exe programs.

The article contains all his programs in the file Auxiliary .exe programs.zip.

The program you want is CursorSize.exe described as:

Get or set cursor size.

CursorSize [size|/L]

The cursor size is a percentage (1..100) of the character cell that is filled by the cursor. Use 0 to hide the cursor; use /L to recover the last hidden cursor.

At end, the previous cursor size is returned in ERRORLEVEL.

I tested the program and it still works in CMD on Windows 10.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .