Closed wvthoog closed 2 years ago
Hey,
thanks for trying my library. It is already possible but requires some extra work because simple-term-menu
does not know anything about columns:
#!/usr/bin/env python3
from simple_term_menu import TerminalMenu
def main():
headers = ("Channel Name", "Title")
value_dict = {
"Channel 1": "Title 1",
"Channel 2": "Title 2",
"Channel abc": "Title abc",
"Channel 1337": "Title ?",
"Channel 100000000000": "Title !!!!!!",
}
max_length_column1 = max(len(key) for key in value_dict.keys())
column_separator = " "
title = " " + f"{{:{max_length_column1}s}}".format(headers[0]) + column_separator + headers[1]
menu_entries = [
f"{{col1:{max_length_column1}s}}{{sep}}{{col2}}".format(col1=key, sep=column_separator, col2=value)
for key, value in value_dict.items()
]
terminal_menu = TerminalMenu(menu_entries, title=title)
terminal_menu.show()
if __name__ == "__main__":
main()
which creates the menu:
The menu title stays at top even if the menu needs to scroll.
But it could be a nice feature to support columns natively in simple-term-menu
.
Wow, that is exactly what i needed.
Thanks for clarifying
Hi,
first off, great library. Easy to install and use
Was wondering if this is possible. I have a dictionary of values (currently) in the order of 'Channel Name' and 'Title'. More could be added in the future. What i want to achieve is having two column headers on top with the previously mentioned values. Scrolling down would highlight both values and would act like the TerminalMenu 'default style' while keeping the headers 'visible'. The length of the list can go as high as 40 items (rows)
Is this a feature request or maybe already possible ?
Thanks, Wim