aegirhall / console-menu

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

Items longer than the default screen width don't wrap #29

Closed gene1wood closed 2 years ago

gene1wood commented 5 years ago

If an item is of a length greater than the screen width (default of 80 characters it doesn't wrap it merely sticks out the side of the box

Steps to reproduce

Install v0.5.1 with pip install console-menu Create code like

from consolemenu import SelectionMenu

a_list = [
    "This is an option that isn't just a string under 80 characters heck it's actually quite a bit longer",
    "blue", 
    "green"]

selection = SelectionMenu.get_selection(
    a_list)

Expected results

A menu like

  ┌─────────────────────────────────────────────────────────────────────────┐
  │                                                                         │
  │  Select an option                                                       │
  │                                                                         │
  │                                                                         │
  │    1 - This is an option that isn't just a string under 80 characters   │
           heck it's actually quite a bit longer                            │
  │    2 - blue                                                             │
  │    3 - green                                                            │
  │    4 - Exit                                                             │
  │                                                                         │
  │                                                                         │
  └─────────────────────────────────────────────────────────────────────────┘
  >> 

Actual results

  ┌─────────────────────────────────────────────────────────────────────────┐
  │                                                                         │
  │  Select an option                                                       │
  │                                                                         │
  │                                                                         │
  │    1 - This is an option that isn't just a string under 80 characters heck it's actually quite a bit longer  │
  │    2 - blue                                                             │
  │    3 - green                                                            │
  │    4 - Exit                                                             │
  │                                                                         │
  │                                                                         │
  └─────────────────────────────────────────────────────────────────────────┘
  >> 
MoralCode commented 3 years ago

Would it be preferable to wrap, or to have the width of the default screen increase? seems to me like it may be good to have an option since ive used this library in a project as a quick-and-dirty way to display a selectable table of items by having each item be a string with tabs in it to move them into columns. This is a case where having things auto-wrap wouldn't be as great, but i also see the value in it.

on first look, it seems like these lines are where the logic would need to check for line width and split it into two lines, but maybe theres some more complexity needed to make sure the second line doesnt show up as a separate selectable menu item:

https://github.com/aegirhall/console-menu/blob/9378508bb04d2214a8f65157c2a5aa6847784a5e/consolemenu/menu_formatter.py#L274-L276

MoralCode commented 3 years ago

Screenshot_20211106_203857

seems like simply inserting newlines every 80 chars isnt quite enough.

MoralCode commented 3 years ago

Screenshot_20211106_204803

simply truncating it is another possible option. visually cleaner but also far less usable

MoralCode commented 3 years ago

Screenshot_20211106_210156

well it works.

edit: see linked PR for a list of issues that should be resolved before fixing

gene1wood commented 2 years ago

@MoralCode Nice fix! Thanks for it!