Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-112730: Use color to highlight error locations#112732

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ambv merged 10 commits intopython:mainfrompablogsal:gh-112730
Dec 6, 2023

Conversation

pablogsal
Copy link
Member

@pablogsalpablogsal commentedDec 4, 2023
edited by bedevere-appbot
Loading

hugovk, ikocs, and barneygale reacted with hooray emojixggrnx reacted with rocket emoji
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
@terryjreedy
Copy link
Member

On Windows in both CommandPrompt and PowerShell,1/0 becomes←[31m1←[0m←[1;31m/←[0m←[31m0←[0m in the traceback. They need to be switched to interpret the ANSI codes (possible, I believe) or treated as 'dumb', at least for this purpose.

pablogsal reacted with thumbs up emoji

@pablogsal
Copy link
MemberAuthor

pablogsal commentedDec 5, 2023
edited
Loading

On Windows in both CommandPrompt and PowerShell,1/0 becomes←[31m1←[0m←[1;31m/←[0m←[31m0←[0m in the traceback. They need to be switched to interpret the ANSI codes (possible, I believe) or treated as 'dumb', at least for this purpose.

Will investigate how to properly set this up for windows. I know the more modern Windows terminal (https://apps.microsoft.com/detail/9N0DX20HK701?hl=en-gb&gl=US) handles this correctly. We may need to deactivate this unless that new terminal is detected

@pablogsal
Copy link
MemberAuthor

pablogsal commentedDec 5, 2023
edited
Loading

I think for the start I will look atWT_SESSION as discussed here:microsoft/terminal#1040. More complicated solutions are possible (rich does thishere but I don't want to start using ctypes and complications when printing exceptions, so i want to keep this dumb as possible).

We can iterate afterwards if someone want to add support to detecting other (working) environments.

Or maybe we can expose some C calls to windows and check forENABLE_VIRTUAL_TERMINAL_PROCESSING....

@terryjreedy
Copy link
Member

According tohttps://en.wikipedia.org/wiki/Windows_Terminal, the first stable release of Windows Terminal was 18 days ago. It can run Command Prompt, Powershell, WSL Bash, and more. It is becoming default on Win 11 and can be installed on up-to-date Win 10. I will see if either an option 'cumulative update preview' or the next monthly update (in a week) installs it.

@aroberge
Copy link

Excellent idea. Based on my experience in trying to support this type of feature in various terminal themes for friendly-traceback, I think it would be helpful if the colors in

class _ANSIColors:    RED = '\x1b[31m'    BOLD_RED = '\x1b[1;31m'

could also be user-configurable via environment variables or some other method.

@pablogsal
Copy link
MemberAuthor

Excellent idea. Based on my experience in trying to support this type of feature in various terminal themes for friendly-traceback, I think it would be helpful if the colors in

class _ANSIColors:    RED = '\x1b[31m'    BOLD_RED = '\x1b[1;31m'

could also be user-configurable via environment variables or some other method.

Thanks a lot for the suggestion. I will consider it, but for the first version, I am going to center on getting the defaults right for most environments and then we can iterate to improve the situation in different systems.

@pablogsal
Copy link
MemberAuthor

@terryjreedy I have exposed a call toGetConsoleMode in thent module and I am using that to check if the given terminal supports colors. Can you try to give it a go. Here are my local results:

powershell

powershell

windows terminal

windows_terminal

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
@pablogsalpablogsalforce-pushed thegh-112730 branch 2 times, most recently from58ce57a to9ae4c77CompareDecember 5, 2023 12:47
@hugovk
Copy link
Member

Some Python programs usehttps://github.com/tartley/colorama for colour, and some others do the colour themselves but still depend on colorama just to call theircolorama.init() helper function to initialise Windows:

https://github.com/tartley/colorama#initialisation

You could check what that does, or their newercolorama.just_fix_windows_console():https://github.com/tartley/colorama/blob/136808718af8b9583cb2eed1756ed6972eda4975/colorama/initialise.py#L72

@pablogsal
Copy link
MemberAuthor

pablogsal commentedDec 5, 2023
edited
Loading

Some Python programs usehttps://github.com/tartley/colorama for colour, and some others do the colour themselves but still depend on colorama just to call theircolorama.init() helper function to initialise Windows:

That seems to wrap stderr and stdout to translate between ANSI and whatever windows uses. Given that this is critical code (we are printing errors) I don't want to mess with the standard streams not callcomplicated code.

Also, it is not clear to me what will happen if the interpreter does this wrapping and then something else does it on top (notice the only reason they claim is safe to call multiple times is because they record global state). As mentioned before, I want to leave this as dumb as possible and the current solution that detects if is possible to use ANSI sequences seems to work nicely to detect when is safe to do.

Edit:

Also seems that the future for Windows is the "Windows terminal" that supports this out of the box.

hugovk reacted with thumbs up emoji

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
@terryjreedy
Copy link
Member

With fresh update, after "Fix multiline output", tracebacks look normal (b/w, not ansi) in Python started in CommandPrompt and in Windows Console (when started from icon or Explorer).

pablogsal reacted with thumbs up emoji

@barneygale
Copy link
Contributor

Python-specific environment variables usually don't include underscores in their names (e.g. we havePYTHONWARNINGS, notPYTHON_WARNINGS). Should that apply here too, so the environment variable might bePYTHONCOLORS rather thanPYTHON_COLORS?

@ambv
Copy link
Contributor

ambv commentedDec 6, 2023

@barneygale, if you look at the current makeup of PYTHON env variables, you'll noticewe are currently changing this naming scheme. New variables have an underscore to improve readability. We leave old ones as is for backwards compatibility.

barneygale reacted with thumbs up emoji

@ambvambv merged commit16448ca intopython:mainDec 6, 2023
@barneygale
Copy link
Contributor

Ah ha! Thanks :)

@pablogsalpablogsal deleted the gh-112730 branchDecember 6, 2023 22:31
aisk pushed a commit to aisk/cpython that referenced this pull requestFeb 11, 2024
)Signed-off-by: Pablo Galindo <pablogsal@gmail.com>Co-authored-by: Łukasz Langa <lukasz@langa.pl>
@@ -1118,7 +1203,7 @@ def __eq__(self, other):
def __str__(self):
return self._str

def format_exception_only(self, *, show_group=False, _depth=0):
def format_exception_only(self, *, show_group=False, _depth=0, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is there any reason to use**kwargs instead of*, colorlize=False?

Glyphack pushed a commit to Glyphack/cpython that referenced this pull requestSep 2, 2024
)Signed-off-by: Pablo Galindo <pablogsal@gmail.com>Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@methanemethanemethane left review comments

@barneygalebarneygalebarneygale left review comments

@iritkatrieliritkatrieliritkatriel left review comments

@hugovkhugovkhugovk left review comments

@ambvambvAwaiting requested review from ambv

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

8 participants
@pablogsal@terryjreedy@aroberge@hugovk@barneygale@ambv@methane@iritkatriel

[8]ページ先頭

©2009-2025 Movatter.jp