Skip to content

Commit

Permalink
Added logic to add submenu header.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffrimko committed Feb 24, 2024
1 parent 535bae9 commit 0bb0de5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions _Build.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ def run_tests():

@menu
def package_menu():
Menu(install_package_locally, upload_to_pypi).main(header="Package")
Menu(install_package_locally, upload_to_pypi).main(header="Package", submenu=True)

@menu
def docs_menu():
Menu(readme_excerpt, all_docs, open_docs).main(header="Docs")
Menu(readme_excerpt, all_docs, open_docs).main(header="Docs", submenu=True)

@menu
def browse_menu():
def github(): auxly.open("https://github.com/jeffrimko/qprompt")
def pypi(): auxly.open("https://pypi.org/project/qprompt/")
def docs(): auxly.open("https://qprompt.readthedocs.io/")
def travis(): auxly.open("https://travis-ci.org/jeffrimko/Qprompt")
Menu(github, pypi, docs, travis).main(header="Browse")
Menu(github, pypi, docs, travis).main(header="Browse", submenu=True)

def install_package_locally():
with fsys.Cwd("lib", __file__):
Expand Down
6 changes: 3 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
# built documents.
#
# The short X.Y version.
version = u'0.16.3'
version = u'0.16.4-alpha.1'
# The full version, including alpha/beta/rc tags.
release = u'0.16.3'
release = u'0.16.4-alpha.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -121,7 +121,7 @@

# The name for this set of Sphinx documents.
# "<project> v<release> documentation" by default.
#html_title = u'Qprompt v0.16.3
#html_title = u'Qprompt v0.16.4-alpha.1

# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
Expand Down
21 changes: 15 additions & 6 deletions lib/qprompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def inner(*args, **kwargs):
##==============================================================#

#: Library version string.
__version__ = "0.16.3"
__version__ = "0.16.4-alpha.1"

#: A menu entry that can call a function when selected.
MenuEntry = namedtuple("MenuEntry", "name desc func args krgs")
Expand Down Expand Up @@ -172,11 +172,11 @@ def main(self, auto=None, loop=False, quit=("q", "Quit"), **kwargs):
- loop (bool) - If true, the menu will loop until quit.
- quit ((str,str)) - If provided, adds a quit option to the menu.
"""
submenu = kwargs.get('submenu', False)
def _main():
global _AUTO
if quit:
if self.entries[-1][:2] != quit:
self.add(*quit, func=lambda: quit[0])
if quit and self.entries[-1][:2] != quit:
self.add(*quit, func=lambda: quit[0])
if stdin_auto.auto:
_AUTO = True
result = None
Expand All @@ -190,15 +190,19 @@ def _main():
result = mresult
except EOFError:
pass
if submenu:
hrule()
return result
else:
note = "Menu does not loop, single entry."
try:
result = self.show(note=note, **kwargs)
if result in quit:
if submenu and result in quit:
return None
except EOFError:
pass
if submenu:
hrule()
return result
global _AUTO
if _AUTO:
Expand Down Expand Up @@ -346,6 +350,7 @@ def show_menu(entries, **kwargs):
- limit (int) - If set, limits the number of menu entries show at a time.
[default: None]
- fzf (bool) - If true, can enter FCHR at the menu prompt to search menu.
- submenu (bool) - If true, changes 'MENU' header to 'SUBMENU'.
"""
global _AUTO
hdr = kwargs.get('hdr', "")
Expand All @@ -355,12 +360,16 @@ def show_menu(entries, **kwargs):
compact = kwargs.get('compact', False)
returns = kwargs.get('returns', "name")
limit = kwargs.get('limit', None)
submenu = kwargs.get('submenu', False)
dft = kwargs.get('dft', None)
msg = []
if limit:
return show_limit(entries, **kwargs)
def show_banner():
banner = "-- MENU"
if submenu:
hrule()
banner = "-- "
banner += "MENU" if not submenu else "SUBMENU"
if hdr:
banner += ": " + hdr
banner += " --"
Expand Down
2 changes: 1 addition & 1 deletion lib/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name = "qprompt",
version = "0.16.3",
version = "0.16.4-alpha.1",
author = "Jeff Rimko",
author_email = "jeffrimko@gmail.com",
description = "Library for quick CLI user prompts, input, and menus.",
Expand Down

0 comments on commit 0bb0de5

Please sign in to comment.