-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
Add colorama.just_fix_windows_console() #352
Conversation
This test never actually tested what it claimed to, and it's broken on Win10, so just remove it.
Never mind, fixed this and wrote a test. |
416b2e1
to
78bce18
Compare
This looks amazing, works for me, thank you @njsmith ! |
I'm unsure what's up with 0.4.6, but
Also, is there a better way to get cursor position than |
@LqdBcnAtWork Microsoft says it should work, and it seems to work for me: |
I have determined the issue I was having. The following code has shown the issue and is repeatable for me: from time import sleep
from colorama import Cursor
import colorama
colorama.just_fix_windows_console()
space = 10
print(1)
print("\n"*space,Cursor.UP(space),end="\r",sep="") #run with end="" and end="\r"
sleep(1) # take note of where the cursor is while 'sleeping'
pos = colorama.win32.GetConsoleScreenBufferInfo().dwCursorPosition
print(2)
print("pos:",pos.Y) By having |
Huh, weird. Sounds like this is a quirk on Microsoft's end, so not much we
can do about it, but useful to know.
…On Tue, Oct 18, 2022 at 4:01 AM LqdBcnAtWork ***@***.***> wrote:
I have determined the issue I was having. Cursor is not effected.
colorama.win32.GetConsoleScreenBufferInfo().dwCursorPosition however is.
The following code has shown the issue and is repeatable for me:
from time import sleepfrom colorama import Cursorimport colorama
colorama.just_fix_windows_console()
space = 10
print(1)print("\n"*space,Cursor.UP(space),end="\r",sep="") #run with end="" and end="\r"sleep(1) # take note of where the cursor is while 'sleeping'pos = colorama.win32.GetConsoleScreenBufferInfo().dwCursorPositionprint(2)print("pos:",pos.Y)
By having end="" the Y position is calculated while *not* respecting the
movement done by Cursor.UP, however having *something* print after the
reposition fixes the issue.
—
Reply to this email directly, view it on GitHub
<#352 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEU42HXGKR6GDN7LV75XNTWDZ7P3ANCNFSM6AAAAAARGUAJIY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Nathaniel J. Smith -- https://vorpus.org <http://vorpus.org>
|
I discovered another quirk with Anyway, in windows default command prompt, running So, in my case I have a function that'll print Fortunately Windows console, always causing issues because it's different. |
Thank you for sharing the info @LqdBcnAtWork, it's good to have it posted somewhere publicly. If I was better at curating our 'issues', I'd suggest it should go there. In fact, why don't I transfer it there... #357 I created both your reported quirks as issues. Thank you! I closed them, because I don't think we ought to be making any changes to Colorama in response (but am happy to hear disagreements), and then at least anyone who hits the same quirks can find them by searching our issues and possibly find workarounds, etc. |
We have a release candidate on PyPI containing this PR. Thank you for your contributions! https://pypi.org/project/colorama/0.4.6rc1/ If nobody spots any problems with it, I'll push the final 0.4.6 tomorrow. |
0.4.6 Current release * tartley/colorama#139 Add alternative to 'init()', called 'just_fix_windows_console'. This fixes many longstanding problems with 'init', such as working incorrectly on modern Windows terminals, and wonkiness when init gets called multiple times. The intention is that it just makes all Windows terminals treat ANSI the same way as other terminals do. Many thanks the njsmith for fixing our messes. * tartley/colorama#352 Support Windows 10's ANSI/VT console. This didn't exist when Colorama was created, and avoiding us causing havok there is long overdue. Thanks to segeviner for the initial approach, and to njsmith for getting it merged. * tartley/colorama#338 Internal overhaul of package metadata declaration, which abolishes our use of the now heavily discouraged setuptools (and hence setup.py, setup.cfg and MANIFEST.in), in favor of hatchling (and hence pyproject.toml), generously contributed by ofek (author of hatchling). This includes dropping support Python3.5 and 3.6, which are EOL, and were already dropped from setuptools, so this should not affect our users. * tartley/colorama#353 Attention to detail award to LqdBcnAtWork for a spelling fix in demo06
tqdm uses colorama to enable proper ANSI support on Windows. Traditionally, it's done this by calling `colorama.init`. But this API is pretty awkward: it tries to do too much (e.g. guessing whether you have ANSI support and if not then installing sys.stdout/stderr filters that remove all ANSI codes from output -- even if the system actually does support ANSI!), and it isn't idempotent, so if multiple libraries all call `colorama.init` then you can get brokenness (in particular, it can trigger the situation where colorama thinks ANSI is unavailable, when it actually is!). To solve this, colorama 0.4.6 added a new API, `colorama.just_fix_windows_console`: tartley/colorama#352 The advantage of this is that it does what it says: it just fixes the Windows console, without any strange side-effects, and it's safe to call multiple times.
As discussed in #139
Re: the bugs you collected:
just_fix_windows_console()
is a no-op if run repeatedly, or if run after someone else has calledinit
.just_fix_windows_console
only touches streams that are pointing to a Windows console. So I guess in theory it would still interfere with your random binary if you try dumping it on your terminal, but (a) no-one expects that to do anything useful, (b) it interprets the random binary the same way a Unix console would, and people seem to live with that. So I'm not worried about it.I've tested this manually (running
demos/demo01.py
) on Linux/Win7/Win10.The big remaining issue is that I'm not sure how to test this, because it touches global state, and
init
also touches global state, and I'm not sure how to make all the tests run in a single process.