def wrapper_fork(call_function, reset=True): pid = os.fork() if pid: # Parent os.waitpid(pid, 0) if reset: external_reset() else: locale.setlocale(locale.LC_ALL, '') _SCREEN = curses.initscr() try: curses.start_color() except: pass _SCREEN.keypad(1) curses.noecho() curses.cbreak() curses.def_prog_mode() curses.reset_prog_mode() return_code = call_function(_SCREEN) _SCREEN.keypad(0) curses.echo() curses.nocbreak() curses.endwin() sys.exit(0)
def wrapper_fork(call_function, reset=True): pid = os.fork() if pid: # Parent os.waitpid(pid, 0) if reset: external_reset() else: locale.setlocale(locale.LC_ALL, '') _SCREEN = curses.initscr() try: curses.start_color() except Exception: pass _SCREEN.keypad(1) curses.noecho() curses.cbreak() curses.def_prog_mode() curses.reset_prog_mode() call_function(_SCREEN) _SCREEN.keypad(0) curses.echo() curses.nocbreak() curses.endwin() sys.exit(0)
def sigtstp(self, signum, frame): curses.def_prog_mode() curses.endwin() signal.signal(signal.SIGTSTP, signal.SIG_DFL) os.kill(os.getpid(), signal.SIGTSTP) signal.signal(signal.SIGTSTP, self.sigtstp) self.stdscr.refresh()
def main(): scr = None try: scr = curses.initscr() mgr = Manager(scr) if curses.has_colors() and curses.can_change_color(): curses.start_color() pair_number = curses.pair_number( curses.color_pair(curses.COLOR_BLUE)) curses.init_pair(pair_number, curses.COLOR_WHITE, curses.COLOR_BLUE) curses.color_content(curses.COLOR_RED) scr.bkgdset(curses.COLOR_BLUE) curses.def_prog_mode() curses.noecho() curses.cbreak() curses.curs_set(0) scr.keypad(1) mgr.run() clean(scr=scr) except KeyboardInterrupt: clean(scr=scr) except: clean(scr=scr)
def processmenu(menu, parent=None): optioncount = len(menu['options']) exitmenu = False while not exitmenu: #Loop until the user exits the menu getin = runmenu(menu, parent) if getin == optioncount: exitmenu = True elif menu['options'][getin]['type'] == "COMMAND": curses.def_prog_mode() # save curent curses environment os.system('reset') screen.clear() #clears previous screen os.system(menu['options'][getin]['command']) # run the command screen.clear( ) #clears previous screen on key press and updates display based on pos curses.reset_prog_mode() # reset to 'current' curses environment curses.curs_set(1) # reset doesn't do this right curses.curs_set(0) elif menu['options'][getin]['type'] == "MENU": screen.clear( ) #clears previous screen on key press and updates display based on pos processmenu(menu['options'][getin], menu) # display the submenu screen.clear( ) #clears previous screen on key press and updates display based on pos elif menu['options'][getin]['type'] == EXITMENU: exitmenu = True
def main(scr): h, w = scr.getmaxyx() hghts = [h // 3 + (1 if 3 - h % 3 <= i else 0) for i in range(3)] pr = 0 wins = [] for i in hghts: wins.append(newwin(i, w, pr, 0)) pr += i for i in range(3): wins[i].box(0, 0) panels = [new_panel(i) for i in wins] update_panels() doupdate() x = 0 while x != ord('q'): x = scr.getch() wn = wins[0] wn.addstr(1, 1, "%x" % x) wn.addstr(2, 1, repr([ i for i in dir(wn) if not i.startswith('__')])[:w-3]) def_prog_mode() endwin() print(dir(wn)) reset_prog_mode() wins[0].refresh()
def set_up(self): """ This class overrides this method """ self.menu.pause() curses.def_prog_mode() self.menu.clear_screen()
def processmenu(menu, parent=None): optioncount = len(menu['options']) exitmenu = False pm = PropertyManager("Domains/domains.properties") jbossHome = pm.getValue("jboss.home") controller = pm.getValue("controller") user = pm.getValue("user") password = pm.getValue("password") while not exitmenu: #Loop until the user exits the menu getin = runmenu(menu, parent) if getin == optioncount: exitmenu = True elif menu['options'][getin]['type'] == COMMAND: curses.def_prog_mode() # save curent curses environment os.system('reset') screen.clear() #clears previous screen command = menu['options'][getin]['command'] # run the command command.execute(jbossHome,controller,user,password) screen.clear() #clears previous screen on key press and updates display based on pos curses.reset_prog_mode() # reset to 'current' curses environment curses.curs_set(1) # reset doesn't do this right curses.curs_set(0) elif menu['options'][getin]['type'] == MENU: screen.clear() #clears previous screen on key press and updates display based on pos processmenu(menu['options'][getin], menu) # display the submenu screen.clear() #clears previous screen on key press and updates display based on pos elif menu['options'][getin]['type'] == EXITMENU: exitmenu = True
def processmenu(menu, parent=None): optioncount = len(menu['options']) exitmenu = False while not exitmenu: #Loop until the user exits the menu getin = runmenu(menu, parent) if getin == optioncount: exitmenu = True elif menu['options'][getin]['type'] == COMMAND: curses.def_prog_mode() # save curent curses environment os.system('reset') if menu['options'][getin]['title'] == 'Pianobar': os.system('amixer cset numid=3 1') # Sets audio output on the pi to 3.5mm headphone jack screen.clear() #clears previous screen os.system(menu['options'][getin]['command']) # run the command screen.clear() #clears previous screen on key press and updates display based on pos curses.reset_prog_mode() # reset to 'current' curses environment curses.curs_set(1) # reset doesn't do this right curses.curs_set(0) os.system('amixer cset numid=3 2') # Sets audio output on the pi back to HDMI elif menu['options'][getin]['type'] == MENU: screen.clear() #clears previous screen on key press and updates display based on pos processmenu(menu['options'][getin], menu) # display the submenu screen.clear() #clears previous screen on key press and updates display based on pos elif menu['options'][getin]['type'] == EXITMENU: exitmenu = True
def renderMenu(menu, parent=None): global myMenu options = len(menu['options']) exitMenu = False if parent == None: menu = myMenu while not exitMenu: currentPosition = listOptionsInMenu(menu, parent) if currentPosition == options: exitMenu = True elif menu['options'][currentPosition]['type'].upper() == "MENU": screen.clear() menu = myMenu renderMenu(menu['options'][currentPosition], menu) screen.clear() elif menu['options'][currentPosition]['type'].upper() == "COMMAND": screen.clear() curses.def_prog_mode() os.system('reset') os.system(menu['options'][currentPosition]['command']) if menu['options'][currentPosition]['wait'] == True: print('The job is finished, press Enter to continue...') input() screen.clear() curses.reset_prog_mode() curses.curs_set(1) curses.curs_set(0)
def _get_screen(self): screen = curses.initscr() curses.noecho() try: # Try to hide the cursor curses.curs_set(0) except Exception: pass if curses.has_colors(): curses.start_color() curses.use_default_colors() # Initialize the colors curses.init_pair(1, curses.COLOR_WHITE, -1) curses.init_pair(2, curses.COLOR_GREEN, -1) curses.init_pair(3, curses.COLOR_BLUE, -1) curses.init_pair(4, curses.COLOR_RED, -1) screen.keypad(1) screen.nodelay(1) curses.def_prog_mode() return screen
def edit_xml(self): par = self.content._content[self.par_index] byte_index = par.byte_index curses.def_prog_mode() # save current tty modes curses.endwin() os.system(options.editor % (byte_index, self.filename)) self.screen = curses.initscr()
def edit(self, win): curses.def_prog_mode() curses.endwin() run_editor(self.files) self.blocks = get_all_blocks(self.files) curses.reset_prog_mode() self.redraw(win)
def main(): """ Entry point for example 12 """ screen = curses.initscr() # Start curses mode screen.addstr("Hello World !!!\n") # Print Hello World screen.refresh() # Print it on to the real screen # Wait for user input to see printed message (added during porting) screen.getch() curses.def_prog_mode() # Save the tty mode curses.endwin() # End curses mode temporarily os.system("/bin/sh") # Do whatever you like in cooked mode curses.reset_prog_mode( ) # Return to the previous tty mode stored by def_prog_mode() screen.refresh() # Do refresh() to restore the screen contents screen.addstr("Another String\n" ) # Back to curses use the full capabilities of curses screen.refresh() # Wait for user input to see printed message (added during porting) screen.getch() curses.endwin() # End curses mode sys.exit(0)
def main(): global stdscr try: global filelist # get the file list before initCurses, because opening a pipe # after curses is initialized causes Cygwin to hang filelist = getFileList() initCurses() redraw() y,x = curses.getsyx() stdscr.move(0,1) while 1: c = stdscr.getch() logging.debug(c) if c == ord('q'): break # Exit the while() elif c == curses.KEY_UP: logging.debug("KEYUP!") move(-1) elif c == curses.KEY_DOWN : logging.debug("KEYDOWN") move(1) elif c == ord(' '): logging.debug("SPACE") toggleChecked(currentLine) move(1) elif c == ord('a'): y,x = curses.getsyx() checkall() redraw() stdscr.move(y,x) elif c == ord('u'): y,x = curses.getsyx() checkall(False) redraw() stdscr.move(y,x) elif c == curses.KEY_RIGHT: logging.debug("KEY_RIGHT") move(getMaxLines()) elif c == curses.KEY_LEFT: logging.debug("KEY_LEFT") move(-getMaxLines()) elif c == curses.KEY_ENTER or c == 10: logging.debug("KEY_ENTER") curses.def_prog_mode() curses.endwin() os.system('clear && svn diff "' + filelist[currentLine]["file"] + '" --diff-cmd=colordiff | less -r') stdscr.refresh() elif 0 <= c <= 256 and chr(c).isdigit(): destination = 10 if chr(c) != 0: destination = int(chr(c)) - 1 gotoPage(destination) except Exception as err: logging.error(err) cleanupCurses() print(' '.join(f["file"] for f in filelist if f["checked"]))
def restore_teminal(self): curses.def_prog_mode() curses.endwin() try: yield finally: curses.reset_prog_mode() self.mainframe.refresh()
def set_up(self): """ This class overrides this method """ self.menu.pause() curses.def_prog_mode() clear_terminal() self.menu.clear_screen()
def set_up(self): """ """ self.menu.pause() curses.def_prog_mode() clear_terminal() self.menu.clear_screen()
def edit_all(self, win): curses.def_prog_mode() curses.endwin() run_editor(self.files) self.blockno = 0 self.blocks = get_all_blocks(self.files) curses.reset_prog_mode() self.redraw(win)
def edit_xml(self): par = self.content._content[self.par_index] byte_index = par.byte_index curses.def_prog_mode() # save current tty modes curses.endwin() os.system(options.general['editor'].format(byte_offset=byte_index, filename=self.filename)) self.screen = curses.initscr()
def edit(self, text): "Create a temporary editing window on the screen. Except that if DISPLAY is set, it will probably pop open a separate window." curses.raw() curses.def_prog_mode() curses.endwin() editedText = self.ui.edit(text, self.ui.username()) curses.cbreak() self.stdscr.refresh() self.stdscr.keypad(1) # allow arrow-keys to continue to function return editedText
def edit(self, win): curses.def_prog_mode() curses.endwin() block = self.blocks[self.blockno] run_editor([block.filename]) self.blocks = get_all_blocks(self.files) if self.blockno >= len(self.blocks): self.blockno = 0 curses.reset_prog_mode() self.redraw(win)
def commitMessageWindow(self): "Create a temporary commit message editing window on the screen." curses.raw() curses.def_prog_mode() curses.endwin() self.commentText = self.ui.edit(self.commentText, self.ui.username()) curses.cbreak() self.stdscr.refresh() self.stdscr.keypad(1) # allow arrow-keys to continue to function
def wrapped(scr): curses.use_default_colors() curses.mousemask(curses.ALL_MOUSE_EVENTS) curses.mouseinterval(0) curses.curs_set(2) # solid block cursor scr.idlok(True) curses.def_prog_mode() i = HexInterface(scr) i.set_file(hf) i.main_loop()
def CallSubShell(subshell): """Call this function if you need to execute an external command in a subshell (os.system). All the usual warnings apply -- the command line will be expanded by the shell, so make sure it is safe before passing it to this function.""" curses.def_prog_mode() #curses.endwin() # Probably causes a memory leak. rtn = os.system("%s" % (subshell)) curses.reset_prog_mode() if rtn is not 0: return False else: return True curses.reset_prog_mode()
def init(): screen = curses.initscr() curses.start_color() curses.cbreak() curses.meta(1) curses.noecho() curses.nonl() curses.def_prog_mode() curses.endwin() curses.def_shell_mode() curses.reset_prog_mode() return Screen(screen)
def init(): screen=curses.initscr() curses.start_color() curses.cbreak() curses.meta(1) curses.noecho() curses.nonl() curses.def_prog_mode() curses.endwin() curses.def_shell_mode() curses.reset_prog_mode() return Screen(screen)
def edit_xml(self): par = self.content._content[self.par_index] byte_index = par.byte_index curses.def_prog_mode() # save current tty modes curses.endwin() os.system( options.general['editor'].format( byte_offset=byte_index, filename=self.filename ) ) self.screen = curses.initscr()
def grep(option, target): if not target: doc = document.Document() mode = GrepMode() doc.setmode(mode) else: doc = target.document doc.delete(0, doc.endpos()) mode = doc.mode doc.set_title('<grep>') mode.grepoption = option.clone() mode.encoding = mode.grepoption.encoding mode.newlilne = mode.grepoption.newline dir = os.path.abspath(os.path.expanduser(option.directory)) if not os.path.isdir(dir): s = 'Cannot find directory `{}`.'.format(dir) doc.append(s) else: try: # Restore to cooked mode to accept ^C. curses.def_prog_mode() curses.endwin() try: print('Hit ^C to cancel grep.') nfiles, nhits = _search(dir, option, doc) finally: curses.reset_prog_mode() kaa.app.mainframe.refresh() except KeyboardInterrupt: kaa.app.messagebar.set_message('Grep canceled') return if not nfiles: s = 'Cannot find file `{}`.'.format(option.filenames) doc.append(s) elif not nhits: s = 'Cannot find `{}`.'.format(option.text) doc.append(s) else: s = 'Found {} times in {} files'.format(nhits, nfiles) kaa.app.messagebar.set_message(s) if not target: kaa.app.show_doc(doc) else: target.activate()
def commitmessagewindow(self, commenttext): "Create a temporary commit message editing window on the screen." curses.raw() curses.def_prog_mode() curses.endwin() commenttext = self.ui.edit(commenttext, self.ui.username(), name=os.path.join(self.ui.repo.controldir(), 'COMMIT_EDITMSG')) curses.cbreak() self.stdscr.refresh() self.stdscr.keypad(1) # allow arrow-keys to continue to function return commenttext
def markLine(self): curses.def_prog_mode() # save curent curses environment os.system('reset') linenum = self.topLineNum + self.highlightLineNum pair = self.outputLines[linenum].split(",") search_line_num = pair[1][pair[1].rfind(" ") + 1:] subprocess.call(shlex.split('vim +' + search_line_num + " ../txt/" + pair[0])) self.screen.clear() curses.reset_prog_mode() # reset to 'current' curses environment curses.curs_set(1) # reset doesn't do this right curses.curs_set(0)
def replyEmailApp(MainSession, emlData, currentSelect, stdscr): curses.def_prog_mode(); stdscr.clear(); stdscr.refresh() curses.reset_shell_mode(); print PROC_ORIGINAL msgCodec = Proc(MainSession.IMAP.fetchMsg(\ emlData[3][currentSelect])[1][0][1]) # Fetch original Msg toSendMsg = constructReply(MainSession, msgCodec) # Gather reply MIME if toSendMsg == None: # User cancelled sending curses.reset_prog_mode(); stdscr.clear(); stdscr.refresh() return emlData try: MainSession.SMTP.session.sendmail(toSendMsg["From"], ParseAddr(toSendMsg["To"])[1], toSendMsg.as_string()) except Exception as err: print SEND_ERR % err; raw_input() else: # If sending is successful, then ask whether save to draft.
def main(stdscr): curses.start_color() curses.use_default_colors() curses.def_prog_mode() for i in range(1, curses.COLORS): curses.init_pair(i, 0, i) try: for i in range(0, curses.COLORS + 20): stdscr.addstr(i, 0, '%2s: XXXX ' % i, curses.color_pair(i)) except curses.ERR: # End of screen reached pass stdscr.getch()
def processmenu(menu, parent=None): optioncount = len(menu['options']) exitmenu = False while not exitmenu: #Loop until the user exits the menu getin = runmenu(menu, parent) if getin == optioncount: exitmenu = True elif menu['options'][getin]['type'] == COMMAND: # Prepare for command os.system("sudo pkill -f python\ viinputdaemon") # Stop daemon curses.def_prog_mode() # Save menu status os.system('reset') screen.clear() # Run input daemon with new parameters if 'newsbeuter' in menu['options'][getin]['command']: subprocess.Popen([ "nohup", "sudo", "python", "viinputdaemon.py", "newsbeuter", "&" ]) elif 'man ' in menu['options'][getin]['command']: subprocess.Popen([ "nohup", "sudo", "python", "viinputdaemon.py", "man", "&" ]) else: subprocess.Popen([ "nohup", "sudo", "python", "viinputdaemon.py", menu['options'][getin]['command'], "&" ]) # Run Program os.system(menu['options'][getin]['command']) # Reset Daemon os.system("sudo pkill -f python\ viinputdaemon") subprocess.Popen( ["nohup", "sudo", "python", "viinputdaemon.py", "viui", "&"]) os.system('clear') # Cleanup screen.clear() curses.reset_prog_mode() curses.curs_set(1) curses.curs_set(0) elif menu['options'][getin]['type'] == MENU: screen.clear() processmenu(menu['options'][getin], menu) # display the submenu screen.clear() elif menu['options'][getin]['type'] == EXITMENU: exitmenu = True
def callback(w, s): s = s.strip() if s: # todo: move these lines to kaa.cui.* curses.def_prog_mode() curses.endwin() try: ret = self._exec_cmd(s) finally: curses.reset_prog_mode() wnd.mainframe.refresh() from kaa.ui.makeoutput import makeoutputmode makeoutputmode.show(ret)
def __init__(self, slideshow: bool=True, timeout: int=1): self.scr = curses.initscr() curses.start_color() self.scr.keypad(1) self.scr.nodelay(1) # For non blocking getch. self.timeout = timeout self.scr.timeout(self.timeout * 1000) # Set getch timeout (ms). curses.noecho() self.colors = {} self._old_pairs = {} curses.def_prog_mode() self.buffer = {} self.buffer_size = 1000 self.slideshow = slideshow
def _get_screen(self): screen = curses.initscr() curses.start_color() curses.use_default_colors() curses.noecho() curses.cbreak() curses.init_pair(1, curses.COLOR_RED, -1) curses.init_pair(2, curses.COLOR_MAGENTA, -1) curses.init_pair(3, curses.COLOR_YELLOW, -1) curses.init_pair(4, curses.COLOR_BLUE, -1) curses.init_pair(5, curses.COLOR_CYAN, -1) curses.init_pair(6, curses.COLOR_GREEN, -1) curses.init_pair(7, curses.COLOR_WHITE, curses.COLOR_BLACK) COLOR_RED = curses.color_pair(1) COLOR_MAGENTA = curses.color_pair(2) COLOR_YELLOW = curses.color_pair(3) COLOR_BLUE = curses.color_pair(4) COLOR_CYAN = curses.color_pair(5) COLOR_GREEN = curses.color_pair(6) COLOR_BLACK = curses.color_pair(7) self._COLOR_MAP = { "critical": COLOR_RED, "major": COLOR_MAGENTA, "minor": COLOR_YELLOW, "warning": COLOR_BLUE, "indeterminate": COLOR_CYAN, "cleared": COLOR_GREEN, "normal": COLOR_GREEN, "informational": COLOR_GREEN, "ok": COLOR_GREEN, "debug": COLOR_BLACK, "auth": COLOR_BLACK, "unknown": COLOR_BLACK } try: curses.curs_set(0) except Exception: pass screen.keypad(1) screen.nodelay(1) curses.def_prog_mode() return screen
def markLine(self): curses.def_prog_mode() # save curent curses environment os.system('reset') linenum = self.topLineNum + self.highlightLineNum pair = self.outputLines[linenum].split(",") search_line_num = pair[1][pair[1].rfind(" ") + 1:] subprocess.call( shlex.split('vim +' + search_line_num + " ../txt/" + pair[0])) self.screen.clear() curses.reset_prog_mode() # reset to 'current' curses environment curses.curs_set(1) # reset doesn't do this right curses.curs_set(0)
def processmenu(menu, parent=None): optioncount = len(menu['options']) exitmenu = False while not exitmenu: #Loop until the user exits the menu getin = runmenu(menu, parent) if getin == optioncount: exitmenu = True elif menu['options'][getin]['type'] == COMMAND: curses.def_prog_mode() # save curent curses environment os.system('reset') if menu['options'][getin]['title'] == 'Authenticate using local credentials file': getcreds() #os.system(menu['options'][getin]['command']) # run a bash command if necessary if menu['options'][getin]['title'] == 'Enter credentials manually': input_user_creds() if menu['options'][getin]['title'] == 'List Servers': try: auth_check() except: not_authed() serverlist() if menu['options'][getin]['title'] == 'List My Images': getimagelist() if menu['options'][getin]['title'] == 'List Base Images': getimagelist(base=True) if menu['options'][getin]['title'] == 'Show Credentials': show_credentials() if menu['options'][getin]['title'] == 'List Load Balancers': getLBlist() if menu['options'][getin]['title'] == 'List Flavors': flavorlist() if menu['options'][getin]['title'] == 'List Cloud Files': getCNlist() if menu['options'][getin]['title'] == 'List DNS Records': getDNSlist() if menu['options'][getin]['title'] == 'List Databases': getDBlist() # reset to 'current' curses environment curses.reset_prog_mode() # reset doesn't do this right curses.curs_set(1) curses.curs_set(0) elif menu['options'][getin]['type'] == MENU: #clears previous screen on key press and updates display based on pos screen.clear() processmenu(menu['options'][getin], menu) # display the submenu #clears previous screen on key press and updates display based on pos screen.clear() elif menu['options'][getin]['type'] == EXITMENU: exitmenu = True
def vimPrepareScreen(): global STDSCR if STDSCR == None: STDSCR = curses.initscr() if curses.has_colors(): curses.start_color() curses.def_prog_mode() curses.mousemask(curses.ALL_MOUSE_EVENTS) STDSCR.redrawwin() STDSCR.refresh() vim.command("redraw!") curses.noecho() # don't echo keypresses curses.cbreak() # no need to press Return after each char STDSCR.keypad(1) # translate multibyte keypresses return STDSCR
def suspended(self): """ A context manager that pauses all commands for the duration of the execution of the `with` block and allows other applications to take over the screen. """ curses.def_prog_mode() self.screen.clear_and_refresh() self.running.clear() try: yield finally: self.running.set() curses.reset_prog_mode() self.screen.clear_and_refresh()
def __init__(self): curses.setupterm() self.scr = curses.initscr() curses.savetty() #curses.def_shell_mode() curses.curs_set(0) #curses.start_color() curses.noecho() curses.cbreak() self.scr.scrollok(False) curses.def_prog_mode() self.scr.refresh() self.curses_module = curses self.last_time = time.monotonic() self.status_updates = True
def __init__(self): curses.setupterm() self.scr = curses.initscr() curses.savetty() # curses.def_shell_mode() curses.curs_set(0) # curses.start_color() curses.noecho() curses.cbreak() self.scr.scrollok(False) curses.def_prog_mode() self.scr.refresh() self.curses_module = curses self.last_time = time.monotonic() self.status_updates = True
def callback(w, s): s = s.strip() if s: kaa.app.config.hist('makecommand').add(s) # todo: move these lines to kaa.cui.* curses.def_prog_mode() curses.endwin() try: ret = self._exec_cmd(s) finally: curses.reset_prog_mode() wnd.mainframe.refresh() from kaa.ui.makeoutput import makeoutputmode makeoutputmode.show(s, ret)
def _get_screen(self): screen = curses.initscr() curses.noecho() try: curses.curs_set(0) except Exception: pass screen.keypad(1) screen.nodelay(1) curses.def_prog_mode() return screen
def commitMessageWindow(self): "Create a temporary commit message editing window on the screen." if self.commentText == "": self.commentText = textwrap.dedent(""" HG: Enter/resume commit message. Lines beginning with 'HG:' are removed. HG: You can save this message, and edit it again later before committing. HG: After exiting the editor, you will return to the crecord patch view. HG: -- HG: user: %s""" % self.ui.username()) curses.raw() curses.def_prog_mode() curses.endwin() self.commentText = self.ui.edit(self.commentText, self.ui.username()) curses.cbreak() self.stdscr.refresh() self.stdscr.keypad(1) # allow arrow-keys to continue to function
def run_menu(parent='.'): pos = 0 #pos is the zero-based index of the hightlighted menu option. Every time runmenu is called, position returns to 0, when runmenu ends the position is returned and tells the program what opt$ x = None #control for while loop, let's you scroll through options until return key is pressed then returns pos to program options = [ i for i in os.listdir(parent) if not i.startswith('.') and not i == "menu.py" ] while True: curses.curs_set(0) # Make cursor invisible screen.border(0) screen.addstr(1, 2, "Project Euler %s" % '' if parent == '.' else parent, curses.A_STANDOUT) i = 0 for i, entry in enumerate(options): if pos == i: textstyle = curses.color_pair(1) # highlight else: textstyle = curses.A_NORMAL screen.addstr(4 + i, 4, "%d - %s" % (i + 1, entry), textstyle) #screen.addstr(4 + i, 4, "%d - Exit" % i + 1, textstyle) x = screen.getch() # get user input if x == ord('j') or x == 258: pos += 1 elif x == ord('k') or x == 259: pos -= 1 elif x == ord('q') or x == ord('h'): break elif x == ord('\n') or x == ord('l'): if parent == '.': screen.clear() run_menu(options[pos]) screen.clear() else: curses.def_prog_mode() os.system('reset') os.system('cd %s && time python3 %s; cd ..' % (parent, options[pos])) os.system('read -n1') screen.clear() curses.reset_prog_mode() curses.curs_set(0) # Make cursor invisible again pos %= len(options)
def processmenu(menu, parent=None): optioncount = len(menu['options']) exitmenu = False while not exitmenu: #Loop until the user exits the menu getin = runmenu(menu, parent) if getin == optioncount: exitmenu = True elif menu['options'][getin]['type'] == COMMAND: # Prepare for command os.system("sudo pkill -f python\ viinputdaemon"); # Stop daemon curses.def_prog_mode() # Save menu status os.system('reset') screen.clear() # Run input daemon with new parameters if 'newsbeuter' in menu['options'][getin]['command']: subprocess.Popen(["nohup","sudo","python","viinputdaemon.py","newsbeuter","&"]) elif 'man ' in menu['options'][getin]['command']: subprocess.Popen(["nohup","sudo","python","viinputdaemon.py","man","&"]) else: subprocess.Popen(["nohup","sudo","python","viinputdaemon.py",menu['options'][getin]['command'],"&"]) # Run Program os.system(menu['options'][getin]['command']) # Reset Daemon os.system("sudo pkill -f python\ viinputdaemon"); subprocess.Popen(["nohup","sudo","python","viinputdaemon.py","viui","&"]) os.system('clear') # Cleanup screen.clear() curses.reset_prog_mode() curses.curs_set(1) curses.curs_set(0) elif menu['options'][getin]['type'] == MENU: screen.clear() processmenu(menu['options'][getin], menu) # display the submenu screen.clear() elif menu['options'][getin]['type'] == EXITMENU: exitmenu = True
def viewEmail(MainSession, emlData, msgNOs, currentSelect, stdscr): # Set up curses. curses.def_prog_mode();curses.curs_set(0);stdscr.clear();stdscr.refresh() maxY, maxX = stdscr.getmaxyx(); stdscr.box() stdscr.addstr(0,max(0,(maxX-len(JIMMY_MAIL))/2),JIMMY_MAIL) stdscr.addstr(min(2,maxY-1),max(0,(maxX-len(PLEASE_WAIT))/2), PLEASE_WAIT); stdscr.refresh(); txtMsg = processCodec(Proc(MainSession.IMAP.fetchMsg(\ emlData[3][currentSelect])[1][0][1])) + EOM # Retrieve message. (flag,event,currentTop)=(True, None, 0) while flag: maxY, maxX = stdscr.getmaxyx() maxLen = getMaxLen(txtMsg.split("\n"), maxX) createMailGraphics(MainSession, emlData, txtMsg, stdscr, currentSelect, currentTop) event = stdscr.getch() # Get Keyboard Inputs if event in EML_LST_GEN: (flag,currentTop)=respondMsgPg(flag,event,currentTop,maxY,maxLen) elif event in EML_LST_EDT: (emlData, msgNOs) = modifyEml(MainSession, emlData, msgNOs, currentSelect, event, stdscr) if event == ord("D"): flag = False # Quit Email Viewing
def processmenu(menu, parent=None): optioncount = len(menu['options']) exitmenu = False while not exitmenu: #Loop until the user exits the menu getin = runmenu(menu, parent) if getin == optioncount: exitmenu = True elif menu['options'][getin]['type'] == COMMAND: curses.def_prog_mode() # save curent curses environment os.system('reset') screen.clear() #clears previous screen os.system(menu['options'][getin]['command']) # run the command screen.clear() #clears previous screen on key press and updates display based on pos curses.reset_prog_mode() # reset to 'current' curses environment curses.curs_set(1) # reset doesn't do this right curses.curs_set(0) elif menu['options'][getin]['type'] == MENU: screen.clear() #clears previous screen on key press and updates display based on pos processmenu(menu['options'][getin], menu) # display the submenu screen.clear() #clears previous screen on key press and updates display based on pos elif menu['options'][getin]['type'] == EXITMENU: exitmenu = True
def otherkey(self, c): if c in (ord('f'), curses.KEY_ENTER, 10): root.setpassive() self.render() elif c == ord('h'): root.setpassive() self.printhelp() elif c in (ord('d'), ord('D')): # if self.winmanager.issplit == True: # self.winmanager.unsetsplit() # else: # self.winmanager.setsplit() if self.winmanager.issplit == False: self.winmanager.setsplit() if root.isactive: self.doublewin.drawDoubleWin() # self.winmanager.setsplit = True root.setpassive() elif c == ord('s'): curses.def_prog_mode() curses.reset_shell_mode() self.shell()
def update(self, clear=True): curses.def_prog_mode() curses.reset_shell_mode() sys.stdout.write('\033[2J') sys.stdout.write('\033[H') def bool_map(v): return "On" if v else "Off" sys.stdout.write( "[a]ntialiasing: {} [d]ither: {} [f]it horizontal: {}\n".format( bool_map(self.antialiasing), bool_map(self.dither), bool_map(self.fit))) for i in range( self.start_display_at, self.start_display_at + min(len(self.values) - self.start_display_at, self.height - 2)): sys.stdout.write(self.values[i]) sys.stdout.write("\n") curses.reset_prog_mode()
def setup_console(): # Curses wipes scrollback on exit and that's lame. I'm probably already wiping scrollback on start... # but that's not entirely my fault tcattr = termios.tcgetattr(sys.stdout.fileno()) stdscr = curses.initscr() curses.def_shell_mode() # Can I do this before init? (LOL NO CURSES MAD) curses.start_color() # Turning on color mode SETS the text color to some weird grey. Why? WHO KNOWS. curses.use_default_colors() if curses.COLORS != 256: raise RuntimeError('256-color mode not detected') # WHY DO I HAVE TO MAKE THE COLORS for i in range(curses.COLORS): curses.init_pair(i + 1, i, -1) # Color pair for color number x is 256*x # They can be redefined. # Do i just need to init all of them curses.init_pair(100, 100, 0) curses.noecho() curses.curs_set(0) curses.cbreak() # TBH idk if this is helpful. I WON'T receive ^C stdscr.keypad(True) curses.def_prog_mode() # I MEAN I GUESS # Moved to game logic because UGH, maybe I'll just use the wrapper # Wrapper sucks because endwin() resets terminal content # Atexit is after stacktrace printing # Making my OWN wrapper >:C # atexit.register(teardown_console, stdscr) return stdscr, tcattr
def processmenu(self, menu, parent=None): optioncount = len(menu['options']) exitmenu = False while not exitmenu: selected = self.runmenu(menu, parent) if selected == optioncount: exitmenu = True elif menu['options'][selected]['type'] == "menu": self.stdscr.clear() self.processmenu(menu['options'][selected], menu) self.stdscr.clear() elif menu['options'][selected]['type'] == "command": curses.def_prog_mode() os.system('reset') username = raw_input('Username: '******'ssh ' + username + '@' + menu['options'][selected]['ip_addr']) self.stdscr.clear() curses.reset_prog_mode() curses.curs_set(1) curses.curs_set(0) elif menu['options'][selected]['type'] == "prompt": curses.def_prog_mode() os.system('reset') ip_address = raw_input('IP / Hostname: ') os.system('clear') username = raw_input('Username: '******'ssh ' + username + '@' + ip_address) self.stdscr.clear() curses.reset_prog_mode() curses.curs_set(1) curses.curs_set(0)