def initInteractive(setup): logging.info("Initializing Nexus migration tool.") os.environ.setdefault('ESCDELAY', '25') try: stdscr = unicurses.initscr() unicurses.noecho() unicurses.cbreak() try: unicurses.start_color() except: pass scr = Screen(stdscr, setup.args) saf = Safety(scr) win = Main(scr) scr.render() while True: win.show() if not scr.modified() or saf.show(): break except: logging.exception("Error running Nexus migration tool:") raise finally: logging.info("Terminating Nexus migration tool.") logging.shutdown() if 'stdscr' in locals(): unicurses.echo() unicurses.nocbreak() unicurses.endwin()
def main(): try: stdscr = unicurses.initscr() unicurses.cbreak() # unicurses.noecho() unicurses.start_color() stdscr.keypad(1) # Determine if we need color if args.nocolor: unicurses.init_pair(1, unicurses.COLOR_WHITE, unicurses.COLOR_BLACK) unicurses.init_pair(2, unicurses.COLOR_WHITE, unicurses.COLOR_BLACK) else: unicurses.init_pair(1, unicurses.COLOR_BLUE, unicurses.COLOR_BLACK) unicurses.init_pair(2, unicurses.COLOR_RED, unicurses.COLOR_BLACK) unicurses.init_pair(3, unicurses.COLOR_GREEN, unicurses.COLOR_BLACK) # Game loop after this point gameLoop(stdscr) except KeyboardInterrupt: pass # TODO: Use global variables to fix this #saveGame( playerName ) finally: stdscr.erase() stdscr.refresh() stdscr.keypad(0) unicurses.echo() unicurses.nocbreak() unicurses.endwin()
def _dbg_instr(self): # messy input string (intended for debugging) curses.echo() self.stdscr.nodelay(0) curses.halfdelay(100) str = self.stdscr.getstr() curses.noecho() return str
def stop(): global screen curses.nocbreak() screen.timeout(-1) curses.curs_set(1) screen.keypad(0) curses.nl() screen.scrollok(True) curses.echo() curses.endwin()
def terminateCursesTerminal(stdscr): """Terminate the curses terminal.""" unicurses.nocbreak() unicurses.keypad(stdscr, False) unicurses.curs_set(True) unicurses.timeout(True) unicurses.echo() unicurses.endwin()
def _stop(self): """ Restore the screen. """ curses.echo() self._curs_set(1) try: curses.endwin() except _curses.error: pass # don't block original error with curses error if self._old_signal_keys: self.tty_signal_keys(*self._old_signal_keys) super(Screen, self)._stop()
def newgame(): global name curses.erase() curses.mvaddstr(1, 1, "UUSI PELI") curses.mvaddstr(3, 1, "Kirjoita nimesi:") curses.echo() curses.move(4, 1) name = curses.getstr().decode(encoding="utf-8") curses.noecho() curses.mvaddstr(12, 1, name) curses.mvaddstr(10, 1, "Onko tiedot oikein? (K/E)") while 1: key = curses.getch() if (check_key(key, "k") or key == 27): break elif (key == ord('e') or key == ord('E')): newgame()
def echo(self, yes: bool = True): """If False, then all keypresses by the user are not drawn on the screen.""" if yes: unicurses.echo() else: unicurses.noecho()
kw['ssl_version'] = ssl.PROTOCOL_TLSv1 return func(*args, **kw) return bar ssl.wrap_socket = sslwrap(ssl.wrap_socket) # Start the tool by initializing unicurses and creating a new Screen object. # Before doing so, set the ESCDELAY environment variable to 25, in an attempt to # mitigate the delay following the pressing of the escape key during line # editing. if __name__ == '__main__': os.environ.setdefault('ESCDELAY', '25') fixssl() try: stdscr = unicurses.initscr() unicurses.noecho() unicurses.cbreak() try: unicurses.start_color() except: pass scr = Screen(stdscr) saf = Safety(scr) win = Main(scr) scr.render() while True: win.show() if not scr.modified() or saf.show(): break finally: if 'stdscr' in locals(): unicurses.echo() unicurses.nocbreak() unicurses.endwin()
if key == unicurses.KEY_DOWN: new_head[0] += 1 if key == unicurses.KEY_UP: new_head[0] -= 1 if key == unicurses.KEY_LEFT: new_head[1] -= 1 if key == unicurses.KEY_RIGHT: new_head[1] += 1 snake.insert(0, new_head) if snake[0] == food: food = None while food is None: nf = [ random.randint(1, sh-1), random.randint(1, sw-1) ] food = nf if nf not in snake else None w.addch(food[0], food[1], unicurses.ACS_PI) else: tail = snake.pop() w.addch(int(tail[0]), int(tail[1]), ' ') w.addch(int(snake[0][0]),int( snake[0][1]), unicurses.ACS_CKBOARD) unicurses.nocbreak() stdscr.keypad(False) unicurses.echo() unicurses.endwin()
def main_loop(manga_list): global compc, compv for m in manga_list: req = _parsers.ParseRequest(m) sout, title, path = get_listing(req._name) if _g.conf._usecache and _g.conf._found_in_cache: sout = subdir_recurse(sout, path) else: sout = sout.splitlines() sout = rem_subdir_recurse(sout, path) compv, compc, allf, compfile = walk_thru_listing(req, title, sout) if req._vols and req._vols[-1] == req.ALL: del req._vols[-1] if req._chps and req._chps[-1] == req.ALL: del req._chps[-1] missv = str([v for v in req._vols if v not in compv]).strip('[]') missc = str([c for c in req._chps if c not in compc]).strip('[]') if missv: _out._("couldn't find vol(s): " + missv) if missc: _out._("couldn't find chp(s): " + missc) if any((compfile, compc, compv)): # XXX sigh... # need to append MLOC when we get a cache match. ppfx = ''.join(['https://', loc['DOMAIN']]) if _g.conf._found_in_cache: ppfx = ''.join([ppfx, loc['MLOC']]) try: stdscr = unicurses.initscr() _g.conf._stdscr = stdscr unicurses.noecho() if compfile: _out._('downloading complete archive... ', end='') _g.conf._stdscr.erase() _g.conf._stdscr.addstr(0, 0, compfile.name) _g.conf._stdscr.refresh() _curl.curl_to_file('/'.join([ppfx, _util.create_nwo_basename( compfile.basename), urllib .parse .quote(compfile.name)]), compfile.name, 'HTTP') elif compv or compc: _out._('downloading volume/chapters... ', end='') for f,v,c in allf: #_g.log.info('DL ' + f) _g.conf._stdscr.erase() _g.conf._stdscr.addstr(0, 0, 'title - {}' .format(title)) _g.conf._stdscr.addstr(1, 0, 'current - {}' .format(f.name)) _g.conf._stdscr.refresh() _curl.curl_to_file('/'.join([ppfx, _util .create_nwo_basename( f.basename), urllib .parse .quote(f.name)]), f.name, 'HTTP') except: raise finally: unicurses.nocbreak() _g.conf._stdscr.keypad(False) unicurses.echo() unicurses.endwin() print('done', file=sys.stderr) else: _out._('could not find any requested volume/chapters.') return 1 return 0