pmbarrett314 / curses-menu

A simple console menu system in python using the curses library
MIT License
471 stars 55 forks source link

Right justify index numbers #62

Open dirkd70 opened 9 months ago

dirkd70 commented 9 months ago

When you add more than 10 items to a menu, the menu text indents. This cause an alignment issue when the menu is a large generated list (using tab formatting etc)

 Alignment test                            

   Idx Ident   Type    Score   Description 
   1 - AA12001 car     50%                 
   2 - AA12002 truck   50%                 
   3 - AA12003 car     25%                 
   4 - AA12004 truck   100%                
   5 - AA12005 truck   100%                
   6 - AA12006 truck   100%                
   7 - AA12007 truck   50%                 
   8 - AA12008 truck   25%                 
   9 - AA12009 car     50%                 
   10 - AA12010        car     75%         
   11 - AA12011        car     25%         
   12 - AA12012        truck   75%     

Can you right justify the index numbers, so we don't get this alignment issue

Here's sample code that will generate the list (I did simple generated output, but mine has many columns and indent if further broken after 100 rows)

iter=1
def a_function():
    print("this function will display details on the item")
menu = CursesMenu("Alignment test", "  Idx\tIdent\tType\tScore\tDescription", )
while iter <= 110:
    function_item = FunctionItem("AA12%03d\t%s\t%s" % (iter, random.choice(['car', 'truck']), random.choice(['25%', '50%', '75%', '100%'])), a_function, iter)
    menu.append_item(function_item)
    iter += 1
menu.show()