ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
26.82k stars 1.84k forks source link

ANSI Color Code bug in Windows #2302

Open Rickaym opened 3 years ago

Rickaym commented 3 years ago

Description of bug / unexpected behavior

ANSI Control code formatting for tracebacks and logs in manim seems to be corrupted when opened with command prompt or Powershell (manim version 0.11.0 and 0.12.0)

Expected behavior

Well the traceback should be formatted properly.

How to reproduce the issue

Any manim scene file works.

from manim import *

class SomeRandomText(Scene):
    def construct(self):
        text = MathTex(r"\mathbb{R}", fill_color="#FFFFFF").scale(4)
        self.play(Create(text))

manim -pql source.py -a

Additional media files

Images/GIFs ![bug report](https://media.discordapp.net/attachments/669259565941915723/910098278648016906/unknown.png?width=852&height=677)

Logs

Terminal output Something like: ``` Manim Community ←[32mv0.←[0m←[32m12.0←[0m ←[2;36m[11/17/21 10:17:40]←[0m←[2;36m ←[0m←[32mINFO ←[0m Animation ←[32m0←[0m : Using cached data ←[1m(←[0mhash : 1837579955_3925222406_1685565738←[1m)←[0m ←[2mcairo_renderer.py←[0m←[2m:←[0m←[2m74←[0m [Create(MarkupText('1. A program to compile, (compilation of DVDs back in the days) an idea to\ndeduce a collection from a given pile and make it into a collection.')), Create(MarkupText('2. Your mother\n*. Okay'))] ←[2;36m[11/17/21 10:17:41]←[0m←[2;36m ←[0m←[32mINFO ←[0m Animation ←[32m1←[0m : Using cached data ←[1m(←[0mhash : 2346314500_1430383836_2029021001←[1m)←[0m ←[2mcairo_renderer.py←[0m←[2m:←[0m←[2m74←[0m ←[2;36m ←[0m←[2;36m ←[0m←[32mINFO ←[0m Combining to Movie file. ←[2mscene_file_writer.py←[0m←[2m:←[0m←[2m604←[0m ←[2;36m ←[0m←[2;36m ←[0m←[32mINFO ←[0m ←[2mscene_file_writer.py←[0m←[2m:←[0m←[2m718←[0m ←[1;33mFile←[0m ready at ←[32m'D:\Programming\Python\Lectures\Compilers\media\videos\ep1\480p15\Episode1.mp4'←[0m ←[2;36m ←[0m←[2;36m ←[0m←[32mINFO ←[0m ←[1;33mRendered←[0m Episode1 ←[2mscene.py←[0m←[2m:←[0m←[2m234←[0m ←[1;33mPlayed←[0m ←[32m2←[0m ←[1;33manimations←[0m ←[2;36m ←[0m←[2;36m ←[0m←[32mINFO ←[0m Previewed ←[1;33mFile←[0m at: ←[32m'D:\Programming\Python\Lectures\Compilers\media\videos\ep1\480p15\Episode1.mp4'←[0m ←[2mfile_ops.py←[0m←[2m:←[0m←[2m202←[0m ```

System specifications

System Details - OS: Windows 10 Home Single Language Version: 20H2 - RAM: 8 GB - Python version (`python/py/python3 --version`): Python 3.9.6 - Installed modules (provide output from `pip list`): ``` Package Version ------------------- --------- certifi 2021.10.8 charset-normalizer 2.0.7 click 8.0.3 click-default-group 1.2.2 cloup 0.7.1 colorama 0.4.4 colour 0.1.5 commonmark 0.9.1 decorator 5.1.0 glcontext 2.3.4 idna 3.3 isosurfaces 0.1.0 manim 0.12.0 ManimPango 0.3.1 mapbox-earcut 0.12.11 moderngl 5.6.4 moderngl-window 2.4.0 multipledispatch 0.6.0 networkx 2.6.3 numpy 1.21.4 Pillow 8.4.0 pip 21.1.3 pycairo 1.20.1 pydub 0.25.1 pyglet 1.5.21 Pygments 2.10.0 pyrr 0.10.3 requests 2.26.0 rich 10.13.0 scipy 1.7.2 screeninfo 0.6.7 setuptools 56.0.0 six 1.16.0 skia-pathops 0.7.1 tqdm 4.62.3 urllib3 1.26.7 watchdog 2.1.6 ```
LaTeX details + LaTeX distribution (e.g. TeX Live 2020): + Installed LaTeX packages:
FFMPEG Output of `ffmpeg -version`: ```ffmpeg version 4.4.1-essentials_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers built with gcc 11.2.0 (Rev1, Built by MSYS2 project) configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband libavutil 56. 70.100 / 56. 70.100 libavcodec 58.134.100 / 58.134.100 libavformat 58. 76.100 / 58. 76.100 libavdevice 58. 13.100 / 58. 13.100 libavfilter 7.110.100 / 7.110.100 libswscale 5. 9.100 / 5. 9.100 libswresample 3. 9.100 / 3. 9.100 libpostproc 55. 9.100 / 55. 9.100 ```

Additional comments

In my estimation, this issue is caused by the ANSI Terminal Control support which was added to the Windows 10 console host in build 16257 (and later) being disabled by default.

By using os.system(""), the ANSI support gets enabled as per here. img

As you can see, the Manim Community ←[32mv0.←[0m←[32m12.0←[0m gets printed with invalid formatting, and right after I executed the echo the formatting returns to normal.

from manim import *
from os import system

print("ENABLING ANSI")
system("")

class SomeRandomText(Scene):
    def construct(self):
        text = MathTex(r"\mathbb{R}", fill_color="#FFFFFF").scale(4)
        self.play(Create(text))

This may be useful: https://superuser.com/questions/413073/windows-console-with-ansi-colors-handling

ad-chaos commented 2 years ago

Is this fixed for you now on manim v0.15.0

Rickaym commented 2 years ago

Unfortunately, not.

d:\Programming\Python\Lectures\Compilers>deps\Scripts\manim.exe --version
Manim Community ←[32mv0.←[0m←[32m15.0←[0m

d:\Programming\Python\Lectures\Compilers>deps\Scripts\manim.exe tests.py
Manim Community ←[32mv0.←[0m←[32m15.0←[0m

←[2;36m[03/06/22 20:01:58]←[0m←[2;36m ←[0m←[32mINFO    ←[0m Animation ←[32m0←[0m : Using cached data ←[1m(←[0mhash :  ←[2mcairo_renderer.py←[0m←[2m:←[0m←[2m75←[0m
                             3163782288_3464486584_223132457←[1m)←[0m                      

Aborted!

d:\Programming\Python\Lectures\Compilers>
ad-chaos commented 2 years ago

That's unfortunate :( Do you have a fix in mind?

behackl commented 2 years ago

Maybe an upgrade of rich would help; we should check whether they have any corresponding issues / PRs in their library repo.

ad-chaos commented 2 years ago

Hey @Rickaym can you please file an issue regarding this on rich's repository here?