Skip to content

Commit

Permalink
[api] addMenuItems with string menu defs
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Jan 26, 2023
1 parent 8a07b79 commit 4846a53
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions visidata/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ def addMenuItem(vd, *args):
vd.addMenu(m)


@VisiData.api
def addMenuItems(vd, *itemgroups):
'''Add any number of commands to menu, separated by lines, with individual menupaths separated by '>' character. Example:
vd.addMenuItems("""
Help > About > credits > show-credits
Help > About > environment > show-env
""")
'''
for itemgroup in itemgroups:
for itemline in itemgroup.splitlines():
if not itemline: continue
menupath = [x.strip() for x in itemline.split('>')]
vd.addMenuItem(*menupath)


@VisiData.api
def addMenu(vd, *args):
'''Incorporate submenus and commands into hierarchical menu. Wrap all in Menu() objects. Example:
Expand Down

0 comments on commit 4846a53

Please sign in to comment.