bczsalba / pytermgui

Python TUI framework with mouse support, modular widget system, customizable and rapid terminal markup language and more!
https://ptg.bczsalba.com
MIT License
2.21k stars 54 forks source link

[BUG] inline_styles has no effect when exporting to SVG? #67

Closed pawamoy closed 2 years ago

pawamoy commented 2 years ago

Describe the bug I'm adding an example using PyTermGUI to my Markdown Exec's gallery. Here's my code:

from io import StringIO
import pytermgui as ptg

code = """
while True:
    if condition:
        print("Hello")
    else:
        print("Goodbye")

    input()
"""

with ptg.Terminal(stream=StringIO(), size=(20, 20)).record() as recorder:
    recorder.write(ptg.tim.parse(ptg.highlight_python(code)))
    print(recorder.export_svg(inline_styles=True))

Whatever the value of inline_styles, I get a style tag in the final HTML. This is problematic because it affects other parts of the page.

pytermgui

Expected behavior No global style set in the page.

System information

PyTermGUI version 6.2.1

System details:
    Python version: 3.8.13
    $TERM:          xterm-256color
    $COLORTERM:     truecolor
    Color support:  ColorSystem.TRUE
    OS Platform:    Linux-5.17.9-arch1-1-x86_64-with-glibc2.35

Possible cause I might misunderstand the purpose of the mentioned style tag or the inline_styles option.

Possible solution Use more specific CSS selectors to affect only PyTermGUI's own SVG.

bczsalba commented 2 years ago

Yup, what that argument does is push all the per-text styling to inline. I will add some ptg tag to the text elements.

bczsalba commented 2 years ago

Actually, does it effect other parts of the website? I was under the impression that styles defined within an SVG file are scoped to it, but I might be completely misunderstanding the system.

pawamoy commented 2 years ago

Yes it does affect other parts of the page, at least another SVG aobve it in the page :slightly_smiling_face:

Without PyTermGUI's SVG style: pytermgui_rich2

With: pytermgui_rich1

bczsalba commented 2 years ago

Should be good now! By default SVG text items will use the class ptg, but that can be change with the prefix argument to the exporter.

pawamoy commented 2 years ago

Thanks a lot! Should I wait for a release or do you want me to try master branch?

bczsalba commented 2 years ago

The release should be out in a couple of hours, but I'm not expecting any major changes. A quick test would be much appreciated!