aegirhall / console-menu

A simple Python menu system for building terminal user interfaces.
MIT License
366 stars 58 forks source link

Colored menu items #33

Closed bramstoeller closed 2 years ago

bramstoeller commented 4 years ago

I'd like to create colored menu items. I tried using colorama (e.g. Fore.RED + "Menu Item" + Style.RESET_ALL, but this resulted in the menu border being messed up, probably because the color code characters are counted as normal characters but don't take up any screen space.

I saw some notes about color support in console_menu.py. Is someone working on this? Does anyone have some ideas about it? I'd be happy to implement this part, but it would be good to have some discussion about the API. How should a user define the color of a menu item? Obviously we could add a color argument to MenuItem, but how would we handle items in a SelectionMenu?

And then, colors are quite tricky, with all kinds of OS and stream dependent stuff. So I'd propose to use colorama for it. We could say that colored menu items are only supported if the colorama package is installed as well, without making it a hard requirement.

marianlukac commented 4 years ago

it would be needed to consider also the colors inside of text, bold etc. not only same color of a menu item

ahauser31 commented 4 years ago

I just needed a colored text without bolding, etc. and played around a bit with the ansicolor library... I got it to work as far as I need it by changing the row function in menu_component.py. But I have not tested extensively if there would be any issues in more complex menus / situations to what I use - I have a feeling that alignment (especially centered) may cause issues with my quick fix. And of course, it needs the additional dependency.

But if interested, I'd be happy to share what I did. I'm not exactly a git master, so not sure if I'll be able to manage a pull request but in any case could post the code here...

aegirhall commented 2 years ago

Colors are now supported as of v0.7.0. See example6.py for an example of using colors in menu item text.