Skip to content

Enable 3.13's colorized output (bot half)#3198

Merged
ChrisLovering merged 2 commits into
python-discord:mainfrom
thurisatic:ansi-snekruns
Nov 14, 2024
Merged

Enable 3.13's colorized output (bot half)#3198
ChrisLovering merged 2 commits into
python-discord:mainfrom
thurisatic:ansi-snekruns

Conversation

@thurisatic
Copy link
Copy Markdown
Contributor

@thurisatic thurisatic commented Nov 14, 2024

One of the features new to Python 3.13 is the use of colored traceback output. These colors greatly aid in locating smaller bugs and are overall quite handy, but they are not always enabled, including for the bot's output message. This changes that.

Care was taken to achieve a significant degree of backwards compatibility. Long tracebacks, whose full forms are uploaded to pinnwand, go through a regular expression that removes ANSI escape codes. Pinnwand does not support ANSI, so if this is not done, the raw characters are included, easily making the traceback unintelligible. This will not delete escaped ANSI sequences, but it does provide a slight regression in that colored output that makes it to pinnwand is rendered monochrome (previously, the characters would be present, causing the legibility issue mentioned earlier - though whether this was a problem may be debated).

This PR is the bot side. There is a snekbox PR (python-discord/snekbox#225) that causes the colored output, which should probably be merged after this one.

This was not done alone. Credit is shared with
@ChrisLovering (for pointing to snekbox)
@shenanigansd and @parrrate (for help with docker)
@godlygeek (with the de-ANSIfication regex, much simpler than i thought it'd be)

a demo of this feature, with a code block by PR author and eval output featuring ANSI text and a colored traceback
paste mentioned in image is https://paste.pythondiscord.com/NEP7SBFPWJVETSCU5XJDLVG6Q4

Copy link
Copy Markdown
Contributor

@shenanigansd shenanigansd left a comment

Choose a reason for hiding this comment

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

oooh pretty

@ChrisLovering ChrisLovering merged commit 820c9c3 into python-discord:main Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants