-
Notifications
You must be signed in to change notification settings - Fork 191
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
Broken coloring for boolean in command prompt #35
Comments
Thanks for the Issue! In which terminal are you experiencing this behavior so I may attempt to |
@gruns It's the default windows 10 command prompt. from icecream import ic
ic(True)
print('hello') |
I have the same issue on Windows where |
I had a moment to troubleshoot this and created a minimal working example with a simplified formatted from pygments import highlight
from pygments.formatters import Terminal256Formatter
from pygments.lexers import Python3Lexer as Py3Lexer
from pygments.style import Style
from pygments.token import (
Text, Name, Error, Other, String, Number, Keyword, Generic, Literal,
Comment, Operator, Whitespace, Punctuation)
# Solarized: https://ethanschoonover.com/solarized/
class MinSolarizedDark(Style):
GREEN = '#859900' # noqa
styles = {
Keyword: GREEN,
Keyword.Constant: GREEN,
Keyword.Declaration: GREEN,
Keyword.Reserved: GREEN,
Keyword.Type: GREEN,
}
lexer = Py3Lexer(ensurenl=False)
formatter = Terminal256Formatter(style=MinSolarizedDark)
import colorama
from colorama import Style as colorama_style
colorama.init()
code = {'this': None, 'that': True}
result = highlight(str(code), lexer, formatter)
print(result.encode())
print(result)
print('\n---\nstill white background' + colorama_style.RESET_ALL)
print('now cleared')
colorama.deinit()
print('\n---\n')
print(result) Output: Without the colorama.init()/colorama.deinit(), I don't have any issues with Windows command prompt or powershell try:
raise ImportError('HACK: Test if colorama were not installed')
import colorama
except ImportError:
colorama = None
@contextmanager
def supportTerminalColorsInWindows():
# Filter and replace ANSI escape sequences on Windows with equivalent Win32
# API calls. This code does nothing on non-Windows systems.
if colorama:
colorama.init()
yield
if colorama:
colorama.deinit() I'll add some notes to PR #40 later today/this weekend
Update 2: the quick fix of making Update 3: the above snippet should be useful to resume troubleshooting, but I wasn't able to resolve the issue in a meaningful way |
Same for me, after an "in" everything get a background colour. Anyways to fix that? |
Same problem is also mentioned in #52 (comment), clearly this is bothering a lot of people. This seems to essentially be a colorama bug. I don't have Windows to test on but tartley/colorama#200 and tartley/colorama#218 sound like likely candidates. icecream doesn't actually specify any background colors at all, and @KyleKing's example shows nicely that just asking for a green foreground causes the grey background. colorama is hardly maintained these days, see tartley/colorama#300 . Commits have slowed down and there are many open issues and PRs. The above issues are over 2 years old. icecream needs to not rely on colorama too much. #40 would be helpful so that users can simply uninstall colorama to disable it. You can disable color right now with #67 (comment) but as I said this needs to be easier and more obvious, something like |
is there any update on this issue? this is very bothering... or at least any way to disable background color and keep the foreground color? This is issue is happening to me after the word "in" in windows VSCode |
@rafaelruizv i dont have the time to tackle this right now, nor ready access to a windows machine to reproduce and debug in the mean time, you can disable coloring by setting the import sys
from icecream import ic
ic.configureOutput(outputFunction=lambda *a: print(*a, file=sys.stderr)) this bypasses icecream's coloring functionality |
Colorama does not support 256 colors so escape code like So one way to deal with this issue is to add this code colorama.ansi.AnsiBack.LIGHTBLACK_EX = 999 somewhere in your code. Since Windows 10 terminal supports native 256 ansi colors (with registry hack or using ctypes), a better solution is import icecream
icecream.ic.configureOutput(outputFunction=lambda s: print(icecream.colorize(s), file=sys.stderr)) |
As you see in the image, the background color is broken after
True
keyword appears.How do I get around this problem?
The text was updated successfully, but these errors were encountered: