simple-term-menu
simple-term-menu copied to clipboard
Colored entries
I'm new in python so do not beat me ;)
While creating the list, I inserted the color codes to strings to make the menu entries look more readable, but unfortunately, the list is broken. I used espace codes (from https://ozzmaker.com/add-colour-to-text-in-python/)

Is there any chance to use color in menu entries (i want to use multiple colors in one entry)?
Thanks for giving simple-term-menu a try! :+1: Currently, the text width calculation in simple-term-menu counts escape codes as normal text. This is the reason for the broken list which you attached. I could fix the text width calculation, but then there are still other issues left: search highlighting would break your color codes and the truncation of menu entries (which is done if the terminal is too small for the menu) could lead to truncated escape codes. I think the latter could also be fixed, but currently I have no good idea how to support escape codes in a general way for the search highlighting. For this to work, simple-term-menu probably must analyze which escape codes are activated on every letter position and restore these codes after a search highlight but this is quite complicated and error-prone.
This is a kind of hacky idea, but might be worth considering, at least in the meantime.
If the terminal can display without truncating:
- Count width not including escape codes, and disable the menu "highlight" (only use the arrow on the left)
If the terminal cannot display without truncating:
- Strip all escape codes entirely, and display the text without them
- Alternate idea: scan backwards and attempt to find the last escape code, showing only the first and last ones in the string.
For search highlighting, strip all escape codes.
For what it's worth, I haven't at all looked at the implementation, it's just an idea that came to mind.
Why isn't there an option to pass styling arguments for the entries themselves? @IngoMeyer441
@VaderFuntime Do you think of assigning a style to one menu item? Escape codes could style every individual character, so they would be very flexible. However, they are terminal dependent, which is bad if a script is used by different users.
@VaderFuntime Do you think of assigning a style to one menu item? Escape codes could style every individual character, so they would be very flexible. However, they are terminal dependent, which is bad if a script is used by different users.
It just seemed odd that one could pass styling arguments for every element except for the basic entries. (As well as the title)
Ok, that's true. I will try to add some more styling attributes when I find some time.