8000 Discussion PR - AppMenu + python3 by koreno · Pull Request #3 · elifiner/termenu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Discussion PR - AppMenu + python3 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits 8000
Select commit Hold shift + click to select a range
82a2671
added AppMenu and colors
May 18, 2014
c521af3
updates
Oct 28, 2014
995e8f9
move to package
Oct 29, 2014
3d54773
updates for AppMenu
Oct 29, 2014
f93903f
python3 compatibility fixes
koreno Sep 6, 2015
23c3652
Merge branch 'master' of https://github.com/gooli/termenu into gooli-…
koreno Sep 6, 2015
4ad9c2c
more python3 adjustments
koreno Oct 4, 2015
1b3f80c
return None if menu is empty
koreno Oct 5, 2015
c07c47d
x
koreno Oct 11, 2015
832eee8
prevent non-selectable items from being selected when active
koreno Oct 20, 2015
2010bcf
bug fix on option selectability/markability
koreno Oct 20, 2015
e8d4894
submenus - support for dict-based Options
koreno Oct 20, 2015
4211624
filter - add tip on reseting when no items match
koreno Oct 20, 2015
8def49a
added support for F1 (Help)
koreno Oct 24, 2015
ae7a2f0
bug fix on showing usage help
koreno Oct 24, 2015
24069ae
bug fix in slicing colorized string
koreno Nov 6, 2015
067054c
default to 'fullscreen', and clear the screen
koreno Nov 8, 2015
79f3dea
auto-select the single action if get_selection_actions returns a non-…
koreno Mar 15, 2016
c817032
support on_XXX key hooks
koreno Apr 5, 2016
344de26
back on 'None' only, not any non-zero selection result
koreno May 13, 2016
3add7fc
support for wrapping titles (longer than term-width); bug fix in Colo…
koreno May 13, 2016
0a5c14f
bug fix on 344de26, for empty multiselect selection
koreno May 13, 2016
b1c5f10
added support for ctrl+left/right
koreno May 16, 2016
5f247d4
move the test module out of the top-level folder, so it doesn't inter…
koreno Oct 8, 2016
dd508d5
uncolorize text before measuring string length
koreno Oct 14, 2016
773bb53
no need to clear_menu when in fullscreen mode
koreno Oct 14, 2016
15242b4
support updating data before clearing the screen, to prevent flickering
koreno Oct 14, 2016
905e5cb
uncolorize before testing text against filters
koreno Oct 14, 2016
f1ea020
workaround a bug with OSx that causes the menu to explode
koreno Oct 14, 2016
920a6b3
abort write retries after 5 attempts
koreno Oct 27, 2016
01a2c95
bug fix in access to .height attr, support for SelectSignal
koreno Oct 27, 2016
5584844
bug fix on printing long headers
koreno Oct 27, 2016
55aef30
keyboard - catch ctrl-a,b,d,e...
koreno Nov 1, 2016
9e1c7cc
uncolorize text before tokenzining into Colorized
koreno Nov 4, 2016
814e08d
bug fix in overflowing menus
koreno Nov 7, 2016
ed5d00f
check terminal size for max height
koreno Dec 27, 2016
fd10305
bug fix on preserving selection
koreno Mar 23, 2017
5f226b5
esc: clear selection before exiting
koreno Apr 9, 2017
fa29bed
allow keyboard to be imported even if no stdin (pytest)
koreno Apr 9, 2017
3c7c81a
show cursor when waiting for keys
koreno Apr 9, 2017
eed4864
keyboard: allow releasing stdin
koreno Jun 19, 2017
fc87850
hopefully fix mac issue
koreno Dec 15, 2017
a700b79
keyboard: support for custom ansi escape mapping file
koreno Jan 28, 2018
8f3e334
app: support for inverting filter
koreno Apr 14, 2018
f820e61
keyboard: added mapping to ctrl/shift/fn
koreno Apr 14, 2018
a935382
app: support for 4 filter modes
koreno Apr 19, 2018
4ee78f3
app: support alternative filter text
koreno Jul 16, 2018
85bafd4
app: show the scroll markers on the left, and bolder
koreno Jul 26, 2018
a813871
finally fix height math for app menu; also...
koreno Aug 30, 2018
ac27a55
app: disable resize signal handler when not in menu
koreno Sep 1, 2018
6b974e2
app: announce it when the config file is created
koreno Sep 2, 2018
af778c0
app: change default chars to not depend on unicode glyphs
koreno Sep 2, 2018
fac216a
app: fixes to app_chars config intro
koreno Sep 3, 2018
f30d0c1
app: don't show intro if not a TTY
koreno Sep 5, 2018
8775529
app: don't neglect to close the config file after writing it
koreno Sep 5, 2018
5819209
app: skip app_chars config file if PermissionError
koreno Sep 6, 2018
bf8dfa5
bug fix on pushing title into the stack
koreno Sep 29, 2018
68531cf
app: support a 'showing' hook
koreno Oct 28, 2018
ae92aca
fix: make termenu installable with --editable (WEKAPP-81981)
doron-cohen Dec 2, 2018
b6938a9
Merge pull request #2 from koreno/fix-package-editable-install
koreno Dec 23, 2018
54357ba
handle terminal size change in main-thread only
koreno Jan 6, 2019
873396a
app: don't fail on read-only fs when writing config file
koreno Apr 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.swp
*.pyc
*.egg-info
MANIFEST
dist/
1 change: 0 additions & 1 deletion __init__.py

This file was deleted.

Empty file added examples/__init__.py
Empty file.
83 changes: 83 additions & 0 deletions examples/app1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import time
from termenu.app import AppMenu
from functools import reduce
try:
input = raw_input
except NameError:
pass


class TopMenu(AppMenu):
title = staticmethod(lambda: "YELLOW<<%s>>" % time.ctime())
timeout = 15
submenus = ["Empty", "Letters", "Numbers", "Submenu", "Foo", "Bar"]

class Empty(AppMenu):
title = "CYAN(BLUE)<<Empty>>"
option_name = "BLUE<<Empty>>"
items = []
def action(self, letters):
input("Selected: %s" % "".join(letters))

class Letters(AppMenu):
title = "CYAN(BLUE)<<Letters>>"
option_name = "BLUE<<Letters>>"
multiselect = True
items = [chr(i) for i in range(65, 91)]
def action(self, letters):
input("Selected: %s" % "".join(letters))

class Numbers(AppMenu):
multiselect = True
@property
def items(self):
return list(range(int(time.time()*2) % 10, 50))
def get_selection_actions(self, selection):
yield "MinMax"
yield "Add"
if min(selection) > 0:
yield "Multiply"
yield "Quit"
def get_selection_title(self, selection):
return ", ".join(map(str, sorted(selection)))
def MinMax(self, numbers):
"Min/Max"
input("Min: %s, Max: %s" % (min(numbers), max(numbers)))
self.retry()
def Add(self, numbers):
input("Sum: %s" % sum(numbers))
self.back()
def Multiply(self, numbers):
input("Mult: %s" % reduce((lambda a, b: a*b), numbers))
def Quit(self, numbers):
input("%s" % numbers)
self.quit()


class Submenu(AppMenu):
submenus = ["Letter", "Number"]

class Letter(AppMenu):
@property
def items(self):
return [chr(i) for i in range(65, 91)][int(time.time()*2) % 10:][:10]
def action(self, letter):
input("Selected: %s" % letter)
self.back()

class Number(AppMenu):
items = list(range(50))
def action(self, number):
input("Sum: %s" % number)

def Foo(self):
input("Foo?")

def Bar(object):
input("Bar! ")

Bar.get_option_name = lambda: "Dynamic option name: (%s)" % (int(time.time()) % 20)


if __name__ == "__main__":
TopMenu()
29 changes: 29 additions & 0 deletions examples/app2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import time
from termenu.app import AppMenu

def leave():
print("Leave...")
AppMenu.quit()

def go():
def back():
print("Going back.")
AppMenu.back()

def there():
ret = AppMenu.show("Where's there?",
"Spain France Albania".split() + [("Quit", AppMenu.quit)],
multiselect=True, back_on_abort=True)
print(ret)
return ret

return AppMenu.show("Go Where?", [
("YELLOW<<Back>>", back),
("GREEN<<There>>", there)
])

if __name__ == "__main__":
AppMenu.show("Make your MAGENTA<<decision>>", [
("RED<<Leave>>", leave),
("BLUE<<Go>>", go)
])
3 changes: 1 addition & 2 deletions examples/filemenu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import sys
sys.path.insert(0, "..")
import termenu

"""
Expand Down Expand Up @@ -62,7 +61,7 @@ def main():
os.chdir(selected[0])
else:
for file in selected:
print >>redirectedStdout, os.path.abspath(file)
print(os.path.abspath(file), file=redirectedStdout)
return
else:
return
Expand Down
2 changes: 1 addition & 1 deletion examples/loading_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _print_menu(self):
return super(TitleCounterPlugin, self)._print_menu()

def data(size):
for i in xrange(size):
for i in range(size):
yield i
time.sleep(0.05)

Expand Down
10 changes: 6 additions & 4 deletions examples/paged_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ def __init__(self, iter):
self._list = []

def __getitem__(self, index):
if isinstance(index, slice):
return self.__slice__(index.start, index.stop, index.step)
try:
while index >= len(self._list):
self._list.append(self._iter.next())
self._list.append(next(self._iter))
except StopIteration:
pass
return self._list[index]

def __slice__(self, i, j):
def __slice__(self, i, j, k=None):
self[j]
return self._list[i:j]
return self._list[i:j:k]

def show_long_menu(optionsIter, pagesize=30):
Next = object()
Expand All @@ -48,4 +50,4 @@ def show_long_menu(optionsIter, pagesize=30):
return result

if __name__ == "__main__":
show_long_menu(xrange(500))
show_long_menu(range(500))
115 changes: 0 additions & 115 deletions keyboard.py

This file was deleted.

8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with termenu. If not, see <http://www.gnu.org/licenses/>.

from distutils.core import setup
from version import version
from setuptools import setup
from os import path

DESCRIPTION = """
Termenu is a command line utility and Python library for displaying console
Expand All @@ -29,6 +29,8 @@
allow a modicum of interactivity in regular command line utilities.
"""

version = open(path.join(path.dirname(path.abspath(__file__)), 'version'), 'r').read().strip()

setup(
name='termenu',
version=version,
Expand All @@ -40,7 +42,6 @@
url='https://github.com/gooli/termenu',
package_dir={'termenu':'.'},
packages=['termenu'],
scripts=['termenu'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
Expand All @@ -52,4 +53,3 @@
'Topic :: Terminals'
]
)

2 changes: 1 addition & 1 deletion termenu → termenu-cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import re
import sys
import termenu
Expand Down
1 change: 1 addition & 0 deletions termenu/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .termenu import *
Loading
0