toejough / pimento

simple CLI menu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

colors?

dcsan opened this issue · comments

commented

are there any options for coloring or other presentation options for the menu :)

not at the moment, but I could be convinced to add some. What would you like to see? If I add color options, I'll want to add both a programmatic API for it and some way to trigger/configure colors on the CLI.

commented

just a way to make the options a bit more attractive... wrapping in a color tag or something?

are you imagining an across-the-board menu(..., foreground='blue', background='white') option?

that would be pretty simple to add.

If you're looking for more customization, like individual color config for indices/items/prompts/user-input/messages, that would take more thought/planning.

fwiw, it's already possible to do quite a bit just by formatting input to menu:

image

^ that was accomplished with:

import pimento
import blessed


terminal = blessed.Terminal()


choices = {
    'red': terminal.red('red'),
    'orange': terminal.color(172)('orange'),
    'yellow': terminal.yellow('yellow'),
    'green': terminal.green('green'),
    'blue': terminal.blue('blue'),
    'purple': terminal.color(129)('purple'),
}


pre_prompt = (
    terminal.red('c') +
    terminal.color(172)('o') +
    terminal.yellow('l') +
    terminal.green('o') +
    terminal.blue('r') +
    terminal.color(129)('s')
)


chosen_value = pimento.menu(choices.values(), fuzzy=True, pre_prompt=pre_prompt)


for color, string in choices.items():
    if string == chosen_value:
        print("You chose {}!".format(color))
        break

This relies on a bunch of things:

  • fuzzy matching to match just the printable characters instead of having to match the literal color code characters
  • blessed to do the coloring of the strings
  • using the API, not the CLI
  • using a dictionary to store/retrieve the actual string you want (because menu returns the formatted string)

It also doesn't work with tab-completion very well.

This might be enough for you, but if it's not, that will be insightful/helpful in refining what it is you are looking for, too :-)

commented

really just wanted to make the pickable items stand out from the surrounding menu text.
the above would do the trick I think!