simple-term-menu icon indicating copy to clipboard operation
simple-term-menu copied to clipboard

Colored entries

Open luka-zet opened this issue 4 years ago • 6 comments

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/) Screenshot 2020-11-27 at 19 37 01

Is there any chance to use color in menu entries (i want to use multiple colors in one entry)?

luka-zet avatar Nov 27 '20 18:11 luka-zet

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.

IngoMeyer441 avatar Nov 29 '20 09:11 IngoMeyer441

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.

Brod8362 avatar Jul 27 '22 20:07 Brod8362

Why isn't there an option to pass styling arguments for the entries themselves? @IngoMeyer441

VaderFuntime avatar Mar 24 '23 15:03 VaderFuntime

@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.

IngoMeyer441 avatar Mar 27 '23 08:03 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.

It just seemed odd that one could pass styling arguments for every element except for the basic entries. (As well as the title)

VaderFuntime avatar Mar 28 '23 08:03 VaderFuntime

Ok, that's true. I will try to add some more styling attributes when I find some time.

IngoMeyer441 avatar Mar 28 '23 08:03 IngoMeyer441