Python curses.wrapper() Examples
The following are 30
code examples of curses.wrapper().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
curses
, or try the search function
.
Example #1
Source File: menu.py From ssha with MIT License | 8 votes |
def choose_instance(instances, search, show_menu=True): labels = [ec2.label(inst) for inst in instances] columns_width = _find_each_column_width(labels) items = [] for i, inst in enumerate(instances): formatted_labels = [label.ljust(columns_width[j]) for j, label in enumerate(labels[i])] items.append(Item(label=' '.join(formatted_labels), value=inst)) if search: search = search.lower() items = [item for item in items if search in item.label.lower()] if len(items) == 1: return items[0].value if not items: return None if not show_menu: if search: # If there is a search string, use word boundaries # to increase the changes of it being a good choice. pattern = r'\b{}\b'.format(re.escape(search)) items.sort( key=lambda item: bool(re.search(pattern, item.label, re.IGNORECASE)), reverse=True, ) return items[0].value return curses.wrapper(_display, items)
Example #2
Source File: __init__.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def initscr(): import _curses, curses # we call setupterm() here because it raises an error # instead of calling exit() in error cases. setupterm(term=_os.environ.get("TERM", "unknown"), fd=_sys.__stdout__.fileno()) stdscr = _curses.initscr() for key, value in _curses.__dict__.items(): if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'): setattr(curses, key, value) return stdscr # This is a similar wrapper for start_color(), which adds the COLORS and # COLOR_PAIRS variables which are only available after start_color() is # called.
Example #3
Source File: npyssafewrapper.py From apple_bleee with GNU General Public License v3.0 | 6 votes |
def wrapper_basic(call_function): #set the locale properly locale.setlocale(locale.LC_ALL, '') return curses.wrapper(call_function) #def wrapper(call_function): # locale.setlocale(locale.LC_ALL, '') # screen = curses.initscr() # curses.noecho() # curses.cbreak() # # return_code = call_function(screen) # # curses.nocbreak() # curses.echo() # curses.endwin()
Example #4
Source File: ci_program.py From ci_edit with Apache License 2.0 | 6 votes |
def run_ci(): locale.setlocale(locale.LC_ALL, '') try: # Reduce the delay waiting for escape sequences. os.environ.setdefault('ESCDELAY', '1') curses.wrapper(wrapped_ci) finally: app.log.flush() app.log.writeToFile('~/.ci_edit/recentLog') # Disable Bracketed Paste Mode. sys.stdout.write('\033[?2004l') # Disable mouse tracking in xterm. sys.stdout.write('\033[?1002;l') sys.stdout.flush() if userConsoleMessage: fullPath = app.buffer_file.expandFullPath( '~/.ci_edit/userConsoleMessage') with io.open(fullPath, 'w+') as f: f.write(userConsoleMessage) sys.stdout.write(userConsoleMessage + '\n') sys.stdout.flush()
Example #5
Source File: __init__.py From oss-ftp with MIT License | 6 votes |
def initscr(): import _curses, curses # we call setupterm() here because it raises an error # instead of calling exit() in error cases. setupterm(term=_os.environ.get("TERM", "unknown"), fd=_sys.__stdout__.fileno()) stdscr = _curses.initscr() for key, value in _curses.__dict__.items(): if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'): setattr(curses, key, value) return stdscr # This is a similar wrapper for start_color(), which adds the COLORS and # COLOR_PAIRS variables which are only available after start_color() is # called.
Example #6
Source File: wrapper.py From BinderFilter with MIT License | 6 votes |
def wrapper(func, *args, **kwds): """Wrapper function that initializes curses and calls another function, restoring normal keyboard/screen behavior on error. The callable object 'func' is then passed the main window 'stdscr' as its first argument, followed by any other arguments passed to wrapper(). """ try: # Initialize curses stdscr = curses.initscr() # Turn off echoing of keys, and enter cbreak mode, # where no buffering is performed on keyboard input curses.noecho() curses.cbreak() # In keypad mode, escape sequences for special keys # (like the cursor keys) will be interpreted and # a special value like curses.KEY_LEFT will be returned stdscr.keypad(1) # Start color, too. Harmless if the terminal doesn't have # color; user can test with has_color() later on. The try/catch # works around a minor bit of over-conscientiousness in the curses # module -- the error return from C start_color() is ignorable. try: curses.start_color() except: pass return func(stdscr, *args, **kwds) finally: # Set everything back to normal if 'stdscr' in locals(): stdscr.keypad(0) curses.echo() curses.nocbreak() curses.endwin()
Example #7
Source File: lcd.py From bitnodes-hardware with MIT License | 6 votes |
def main(argv): if len(argv) > 1: if argv[1] == 'slave': display = Display() curses.wrapper(display.show) return 1 command = [ sys.executable, os.path.realpath(__file__), 'slave', ] while True: return_code = subprocess.call(command) if return_code != 1: break return 0
Example #8
Source File: client_shell.py From PenguinDome with Apache License 2.0 | 6 votes |
def main(): args = parse_args() log.info('Requesting remote shell from {}', args.hostname) with PenguinDomeServerPeer( 'server', local_port=get_setting('local_port'), logger=log, client_hostname=args.hostname) as remote, \ TerminalPeer() as terminal: host = args.hostname script = '#!/bin/bash\npython client/endpoints/shell.py {}\n'.format( remote.pipe_id) patch_hosts('client/commands/shell-{}'.format(remote.pipe_id), patch_content=script.encode('utf8'), hosts=host) broker = InteractionBroker(terminal, remote, poll_interval=0.2) print('Waiting for client to connect (once connected, use "~." to ' 'disconnect)...') remote.poll() curses.wrapper(interact, broker)
Example #9
Source File: npyssafewrapper.py From EDCOP with Apache License 2.0 | 6 votes |
def wrapper_basic(call_function): #set the locale properly locale.setlocale(locale.LC_ALL, '') return curses.wrapper(call_function) #def wrapper(call_function): # locale.setlocale(locale.LC_ALL, '') # screen = curses.initscr() # curses.noecho() # curses.cbreak() # # return_code = call_function(screen) # # curses.nocbreak() # curses.echo() # curses.endwin()
Example #10
Source File: event_listening.py From stem with GNU Lesser General Public License v3.0 | 6 votes |
def main(): with Controller.from_port(port = 9051) as controller: controller.authenticate() try: # This makes curses initialize and call draw_bandwidth_graph() with a # reference to the screen, followed by additional arguments (in this # case just the controller). curses.wrapper(draw_bandwidth_graph, controller) except KeyboardInterrupt: pass # the user hit ctrl+c
Example #11
Source File: npyssafewrapper.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def wrapper_basic(call_function): #set the locale properly locale.setlocale(locale.LC_ALL, '') return curses.wrapper(call_function) #def wrapper(call_function): # locale.setlocale(locale.LC_ALL, '') # screen = curses.initscr() # curses.noecho() # curses.cbreak() # # return_code = call_function(screen) # # curses.nocbreak() # curses.echo() # curses.endwin()
Example #12
Source File: __init__.py From py_cui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def start(self): """Function that starts the CUI """ self._logger.debug('Starting {} CUI'.format(self._title)) curses.wrapper(self._draw)
Example #13
Source File: wrapper.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def wrapper(func, *args, **kwds): """Wrapper function that initializes curses and calls another function, restoring normal keyboard/screen behavior on error. The callable object 'func' is then passed the main window 'stdscr' as its first argument, followed by any other arguments passed to wrapper(). """ try: # Initialize curses stdscr = curses.initscr() # Turn off echoing of keys, and enter cbreak mode, # where no buffering is performed on keyboard input curses.noecho() curses.cbreak() # In keypad mode, escape sequences for special keys # (like the cursor keys) will be interpreted and # a special value like curses.KEY_LEFT will be returned stdscr.keypad(1) # Start color, too. Harmless if the terminal doesn't have # color; user can test with has_color() later on. The try/catch # works around a minor bit of over-conscientiousness in the curses # module -- the error return from C start_color() is ignorable. try: curses.start_color() except: pass return func(stdscr, *args, **kwds) finally: # Set everything back to normal if 'stdscr' in locals(): stdscr.keypad(0) curses.echo() curses.nocbreak() curses.endwin()
Example #14
Source File: terminal_10.py From Modern-Python-Standard-Library-Cookbook with MIT License | 5 votes |
def show(cls, message, content=None): return curses.wrapper(cls(message, content)._show)
Example #15
Source File: terminal_09.py From Modern-Python-Standard-Library-Cookbook with MIT License | 5 votes |
def show(cls, message, cancel=False, width=40): """Show a message with an Ok/Cancel dialog. Provide ``cancel=True`` argument to show a cancel button too. Returns the user selected choice: - 0 = Ok - 1 = Cancel """ dialog = MessageBox(message, width, cancel) return curses.wrapper(dialog._show)
Example #16
Source File: __init__.py From pick with MIT License | 5 votes |
def start(self): return curses.wrapper(self._start)
Example #17
Source File: npyssafewrapper.py From TelegramTUI with MIT License | 5 votes |
def wrapper(call_function, fork=None, reset=True): global _NEVER_RUN_INITSCR if fork: wrapper_fork(call_function, reset=reset) elif fork == False: wrapper_no_fork(call_function) else: if _NEVER_RUN_INITSCR: wrapper_no_fork(call_function) else: wrapper_fork(call_function, reset=reset)
Example #18
Source File: npyssafewrapper.py From TelegramTUI with MIT License | 5 votes |
def wrapper_basic(call_function): #set the locale properly locale.setlocale(locale.LC_ALL, '') return curses.wrapper(call_function) #def wrapper(call_function): # locale.setlocale(locale.LC_ALL, '') # screen = curses.initscr() # curses.noecho() # curses.cbreak() # # return_code = call_function(screen) # # curses.nocbreak() # curses.echo() # curses.endwin()
Example #19
Source File: drawille.py From vim-minimap with MIT License | 5 votes |
def animate(canvas, fn, delay=1./24, *args, **kwargs): """Animation automatition function :param canvas: :class:`Canvas` object :param fn: Callable. Frame coord generator :param delay: Float. Delay between frames. :param *args, **kwargs: optional fn parameters """ import curses # python2 unicode curses fix if not IS_PY3: import locale locale.setlocale(locale.LC_ALL, "") def animation(stdscr): for frame in fn(*args, **kwargs): for x,y in frame: canvas.set(x,y) f = canvas.frame() stdscr.addstr(0, 0, '{0}\n'.format(f)) stdscr.refresh() if delay: sleep(delay) canvas.clear() curses.wrapper(animation)
Example #20
Source File: ui.py From suplemon with MIT License | 5 votes |
def run(self, func): """Run the application main function via the curses wrapper for safety.""" curses.wrapper(func)
Example #21
Source File: python_pick.py From NSC_BUILDER with MIT License | 5 votes |
def start(self): return curses.wrapper(self._start)
Example #22
Source File: worldmap.py From EasY_HaCk with Apache License 2.0 | 5 votes |
def launch_map(api): app = MapApp(api) return curses.wrapper(app.run)
Example #23
Source File: screen.py From aws-elastic-beanstalk-cli with Apache License 2.0 | 5 votes |
def wrapper(cls, func, height=200, catch_interrupt=False, arguments=None, unicode_aware=None): """ Construct a new Screen for any platform. This will initialize the Screen, call the specified function and then tidy up the system as required when the function exits. :param func: The function to call once the Screen has been created. :param height: The buffer height for this Screen (if using scrolling). :param catch_interrupt: Whether to catch and prevent keyboard interrupts. Defaults to False to maintain backwards compatibility. :param arguments: Optional arguments list to pass to func (after the Screen object). :param unicode_aware: Whether the application can use unicode or not. If None, try to detect from the environment if UTF-8 is enabled. """ screen = Screen.open(height, catch_interrupt=catch_interrupt, unicode_aware=unicode_aware) restore = True try: try: if arguments: return func(screen, *arguments) else: return func(screen) except ResizeScreenError: restore = False raise finally: screen.close(restore)
Example #24
Source File: wrapper.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def wrapper(func, *args, **kwds): """Wrapper function that initializes curses and calls another function, restoring normal keyboard/screen behavior on error. The callable object 'func' is then passed the main window 'stdscr' as its first argument, followed by any other arguments passed to wrapper(). """ try: # Initialize curses stdscr = curses.initscr() # Turn off echoing of keys, and enter cbreak mode, # where no buffering is performed on keyboard input curses.noecho() curses.cbreak() # In keypad mode, escape sequences for special keys # (like the cursor keys) will be interpreted and # a special value like curses.KEY_LEFT will be returned stdscr.keypad(1) # Start color, too. Harmless if the terminal doesn't have # color; user can test with has_color() later on. The try/catch # works around a minor bit of over-conscientiousness in the curses # module -- the error return from C start_color() is ignorable. try: curses.start_color() except: pass return func(stdscr, *args, **kwds) finally: # Set everything back to normal if 'stdscr' in locals(): stdscr.keypad(0) curses.echo() curses.nocbreak() curses.endwin()
Example #25
Source File: tui.py From wifiphisher with GNU General Public License v3.0 | 5 votes |
def gather_info(self, template_argument, template_manager): """ Select a template based on whether the template argument is set or not. If the template argument is not set, it will interfactively ask user for a template :param self: A TuiTemplateSelection object :type self: TuiTemplateSelection :param template_argument: The template argument which might have been entered by the user :type template_argument: str :param template_manager: A TemplateManager object :type template_manager: TemplateManager :return A PhishingTemplate object :rtype: PhishingTemplagte :raises InvalidTemplate in case the template argument entered by the user is not available. """ # get all available templates templates = template_manager.get_templates() # get all the templates names for display template_names = list(templates.keys()) # get all the section contents self.get_sections(template_names, templates) # check if the template argument is set and is correct if template_argument and template_argument in templates: # return the template name return templates[template_argument] elif template_argument and template_argument not in templates: # in case of an invalid template raise phishingpage.InvalidTemplate else: # prompt interactive phishing scenarios to let user select one template = curses.wrapper(self.display_info, templates, template_names) return template
Example #26
Source File: game.py From ascii_racer with MIT License | 5 votes |
def run(): curses.wrapper(main)
Example #27
Source File: __main__.py From curseradio with MIT License | 5 votes |
def main(): curses.wrapper(OPMLBrowser)
Example #28
Source File: termdown.py From termdown with GNU General Public License v3.0 | 5 votes |
def graceful_ctrlc(func): """ Makes the decorated function exit with code 1 on CTRL+C. """ @wraps(func) def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except KeyboardInterrupt: exit(1) return wrapper
Example #29
Source File: picker.py From Spelt with MIT License | 5 votes |
def __init__( self, options, title='Select', arrow="-->", footer="Space = toggle, Enter = accept, q = cancel", more="...", border="||--++++", c_selected="[X]", c_empty="[ ]" ): self.title = title self.arrow = arrow self.footer = footer self.more = more self.border = border self.c_selected = c_selected self.c_empty = c_empty self.all_options = [] for option in options: self.all_options.append({ "label": option, "selected": False }) self.length = len(self.all_options) self.curses_start() curses.wrapper(self.curses_loop) self.curses_stop()
Example #30
Source File: npyssafewrapper.py From EDCOP with Apache License 2.0 | 5 votes |
def wrapper(call_function, fork=None, reset=True): global _NEVER_RUN_INITSCR if fork: wrapper_fork(call_function, reset=reset) elif fork == False: wrapper_no_fork(call_function) else: if _NEVER_RUN_INITSCR: wrapper_no_fork(call_function) else: wrapper_fork(call_function, reset=reset)