Skip to content
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

Don't add ANSI colour codes to Sphinx -w warnings file #11617

Closed
hugovk opened this issue Aug 18, 2023 · 2 comments · Fixed by #11624
Closed

Don't add ANSI colour codes to Sphinx -w warnings file #11617

hugovk opened this issue Aug 18, 2023 · 2 comments · Fixed by #11624
Assignees

Comments

@hugovk
Copy link
Contributor

hugovk commented Aug 18, 2023

Describe the bug

If the terminal supports colour, Sphinx outputs in colour. This is good, it improves readability.

But if outputting to a file, it also adds ANSI colour codes, where is shouldn't.

How to Reproduce

index.rst with an error, in this case, a typo in the role:

:peep:`8`

And an empty conf.py will do.

  1. Build with warnings and output to a file: sphinx-build -b html . _build -n -w sphinx-warnings.txt

image

  1. View the file in an editor:

Actual result:

�[31m/private/tmp/bug-report/index.rst:1: ERROR: Unknown interpreted text role "peep".�[39;49;00m

Because Sphinx is correctly detecting my terminal can do colour, it's correctly adding ANSI colour codes to the terminal output.

But it's also incorrectly adding them to the text file.

Expected result:

Colour in the terminal but no ANSI colour codes in the text file:

/private/tmp/bug-report/index.rst:1: ERROR: Unknown interpreted text role "peep".

Environment Information

Platform:              darwin; (macOS-13.5-arm64-arm-64bit)
Python version:        3.11.4 (v3.11.4:d2340ef257, Jun  6 2023, 19:15:51) [Clang 13.0.0 (clang-1300.0.29.30)])
Python implementation: CPython
Sphinx version:        7.2.2
Docutils version:      0.20.1
Jinja2 version:        3.1.2
Pygments version:      2.16.1

Sphinx extensions

None.

Additional context

No response

@picnixz
Copy link
Member

picnixz commented Aug 18, 2023

Mmh sure. I think it's a reasonable feature. I'll work on it tomorrow (I don't think it'll need a lot of work since it's just stripping ANSI control sequences).

Btw, I think we could actually add some boolean to keep or not the ANSI CSs since people may want to pprint the file ising other tools perhaps?

@picnixz picnixz added the type:proposal a feature suggestion label Aug 18, 2023
@hugovk
Copy link
Contributor Author

hugovk commented Aug 19, 2023

Thank you!

Personally I wouldn't bother with a flag unless there's some stated need for it, but no strong opinion as long as the default is off :)

@picnixz picnixz self-assigned this Aug 19, 2023
@picnixz picnixz added api:cmdline and removed type:proposal a feature suggestion labels Aug 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants