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] `parser.py` outputs redundant sequences #39

Closed bczsalba closed 2 years ago

bczsalba commented 2 years ago

Describe the bug When parsing markup, the parser tries to optimize-out redundant sequences. This works when two PLAIN tokens share the exact same sequences, however when the sequence has a new element added it is detected as a wholly unique one, duplicating the sequence for no effect.

To Reproduce

>> import pytermgui as ptg
>> ptg.markup.parse("[bold 141]First [bold 141 italic]First but italic")
'\x1b[1m\x1b[38;5;141mFirst \x1b[1m\x1b[38;5;141m\x1b[3mFirst but italic\x1b[0m'

Expected behavior The output of the above call should be \x1b[1m\x1b[38;5;141mFirst \x1b[3mFirst but italic\x1b[0m.

System information

PyTermGUI v3.0.0+
Python: 3.9.10
Platform: macOS-12.2.1-arm64-arm-64bit
Git commit: ce27e3c

Possible cause The "optimizer" part of the parser checks for strict equality, not partial.

Possible solution Either fixing the possible cause, or leaving it be and running it through an optimize method. That could hinder speed, so the first option is preferred.