Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a Separator System #72

Closed
wants to merge 8 commits into from

Conversation

AnthonyMakesStuff
Copy link

This allows the select and select_multiple to have separators in the middle if they are prefixed with :SEPARATOR:.
It could also be used to put a description for another option.

names = [
    "Frodo Baggins",
    "Samwise Gamgee",
    "Legolas",
    "Aragorn",
    ":SEPARATOR:" + ("=" * 32),
    "[red]Sauron[/red]",
]
# Choose one item from a list
name = select(names, cursor="馃ⅶ", cursor_style="cyan")

This example with add a separator above the last option.

Updated the _format_option_select and _render_option_select_multiple to support separators
Added a seperator system to select and select_multiple
@AnthonyMakesStuff
Copy link
Author

I have been using this in my own project, and I wanted to provide it in case anyone else would find it useful

Added a pause function
Added pause function
Removed pause function (didn't mean to add it to begin with)
Added comma to be the same as the original file
Removed pause function (didn't mean to add it to begin with)
@AnthonyMakesStuff
Copy link
Author

I'm sure it's obvious, but in case anyone can't tell, I'm very new to using git

@petereon
Copy link
Owner

Please don't worry, I am very glad you chose to contribute to my project! Glancing over the code, I have gathered a few remarks, but I haven't found time to write them down just yet as I am somewhat pressed for time. I believe, I should be able to get to it tomorrow.

@petereon
Copy link
Owner

petereon commented Sep 15, 2023

@AnthonyMakesStuff, sorry for delay, life got in the way of review.

Anyway, I've got to take a proper look today. I like this new feature, I can definitely imagine a use-case for having a way to provide sub-groups of options. This feature was already available in cutie from which I have inherited most of the code (this started as a fork and then diverged too far). I've removed it deliberately, as the implementation struck me as very unnatural.

That said, I'd envision different sort of implementation. This one relies heavily on specific formatting of strings, which provides some room for user error and is more difficult in terms of automated preparation of the data for displaying. Python has a rich set of data-structures available out of the box and this seems like an good application for the dictionary (Dict[str, List[str]]).

As an example with 'Historical' and 'Fictional' being the sections:

people = {
  'Historical': [
    'Napoleon',
    'Julius Caesar',
    'Marie Curie',
  ],
  'Fictional': [
    'Mark Watney',
    'Harry Potter',
  ]
}

select_multiple(options=people)

This would be a bit more of a hassle to implement but it would be cleaner in terms of usage and data preparation for displaying.

If you would like to have a go at it, please do let me know. Otherwise I will implement it myself in near future. Either way, thank you very much for the contribution and inspiration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants