colorama icon indicating copy to clipboard operation
colorama copied to clipboard

Need cursor hide and show support

Open pjfarleyiii opened this issue 3 years ago • 7 comments

Project bullet on PyPi provides very simple python menu capabilities, but it needs support to hide ("\033[?25l") and show("\033[?25h") the cursor on Windows platforms.

Can colorama be updated to support these two sequences?

Peter

pjfarleyiii avatar Sep 20 '20 18:09 pjfarleyiii

This should be possible to do using SetConsoleCursorInfo on Windows. I'm not sure when I'll have time to implement it, though. Pull requests are always welcome.

wiggin15 avatar Sep 21 '20 06:09 wiggin15

I did clone the repo and make some changes using Pycharm. It works under the new Windows Terminal application but not under the old original cmd.exe window. I wrote a new demo09.py test to show that it works, but under regular cmd.exe it just outputs the escape codes to hide and show the cursor, it does not implement them it seems.

I am not familiar with sending back my changes up to your github account, I have never done that before. Would you please point me to any tutorials there may be so I could share what I have done so far?

I have contributed to other open source projects in the past, but back then we just sent the maintainers "diff -u" patch files that showed our changes. Using git to share changes is a new world for me.

Peter

pjfarleyiii avatar Sep 23 '20 23:09 pjfarleyiii

After I wrote the my previous comment I did some further testing and found that the ANSI_CSI_RE was not matching the cursor-hide or cursor-show escape sequences. I now have an RE that matches them (as well as all the current ones it already catches) and found that the code I added is not, on fact, working. The new Windows Terminal V1.0 console apparently directly implements the cursor hide and show function (which the older console does not), so that is how I was led to believe my code was working in Windows Terminal.

Now I need advice on how to correctly code the winterm.py code that calls the DLL functions GetConsoleCursorInfo and SetConsoleCursorInfo. GetConsoleCursorInfo returns a POINTER to a CONSOLE_CURSOR_INFO structure with two fields, a dword and a bool. How do I de-reference the returned pointer to change the "bool" to false for the hide function and to true for the show function?

Similarly, the SetConsoleCursorInfo requires as input a handle and a POINTER to a CONSOLE_CURSOR_INFO structure. After getting back a pointer from GetConsoleCursorInfo , can I just pass that same python variable to the SetConsoleCursorInfo function as-is?

Appreciate any advice you can offer here.

Peter

pjfarleyiii avatar Sep 24 '20 15:09 pjfarleyiii

I have since found examples in python out on the web for using the *CursorInfo functions, but either my coding in win32.py isn't executing them correctly or auto-reset is accidentally turning it off. Haven't figured out which yet. Will post again when I do.

I have a separate demo script that calls the *CursorInfo functions directly after a normal (not wrapped) sys.stdout.write(), and it works as it should, hiding and showing the cursor correctly. Just can't get the win32py function to do the same thing yet.

pjfarleyiii avatar Sep 26 '20 02:09 pjfarleyiii

Hi @pjfarleyiii if you need some starting point for the "how do I contribute". Maybe the following reading could help to find it.

https://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project https://github.com/firstcontributions/first-contributions

After you have forked this repository, created a branch to provide a solution for this issue and have pushed you current work into your repostiory. You might add here a link to your working branch. Then others might have a look on what you have done so far and provide suggestions/pull requests to solve the open points.

SubOptimal avatar Dec 07 '20 15:12 SubOptimal

Have you seen https://stackoverflow.com/a/10455937 , and its corresponding packaged https://github.com/GijsTimmers/cursor ? I've tried this approach in my own code and it seems to work fine.

itsayellow avatar Jan 24 '21 21:01 itsayellow

Thank you itsayellow, I had not seen that and it is right on point. I've been busy with other aspects of my project and may be returning to my colorama issues soon.

pjfarleyiii avatar Mar 13 '21 18:03 pjfarleyiii