我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用curses.flushinp()。
def launch_game(game_tuple): close_curses() print('RUNNING: ' + str(game_tuple)) system = game_tuple[0] game = game_tuple[1] full_path = os.path.join(path_to_games, system, game) args = config.get(SECTION, 'run_'+system).format(full_path) origWD = os.getcwd() os.chdir(os.path.dirname(CONFIG_FILE)) try: subprocess.call(args, shell=True) except KeyboardInterrupt: pass os.chdir(origWD) init_curses() curses.flushinp() search_window.draw() game_menu.draw()
def loop(self): await self.setup() while self._running: self._screen.timeout(1) pressed_key = self._screen.getch() if pressed_key == ord('q'): raise QuitException() self.update(pressed_key) self._screen.clear() drawees = sorted(self._sprites, key=lambda o: o.x) for d in drawees: d.draw() self._screen.refresh() curses.flushinp() await asyncio.sleep(1 / self._fps)
def __call__(self): self.run() curses.flushinp() return "\n".join(["".join(i) for i in self.text])
def close(self): self.text = self.text_orig curses.endwin() curses.flushinp() return False
def run(self): opt = 'x' while True: self.draw(opt) opt = self.screen.getch() # curses.flushinp() # flush input # arrow keys seem to send [27, 66], where the first is ESC # you really want the second number if opt == self.DOWN_KEY: curses.flash() # return elif opt == self.UP_KEY: curses.flash() # return elif opt == self.RIGHT_KEY: curses.flash() # return elif opt == self.LEFT_KEY: curses.flash() # return elif opt == self.SPACE_KEY: curses.flash() # elif opt == self.ESC_KEY or opt == ord('q'): elif opt == ord('q'): # curses.beep() # curses.flash() return # else: # curses.flash() # else: # self.screen.addstr(13, 30, 'key {}'.format(opt)) # time.sleep(1)
def alert(stdscr, args, oldwin): msg = args.msg if args.msg is not None else 'Time up!' if not args.silent: init_vol = get_curr_vol() change_vol(100) mplayer = proc.Popen('mplayer -loop 0 {0}'.format(args.song).split(), stdout=proc.DEVNULL, stderr=proc.DEVNULL) center(stdscr, msg, args.font, curses.color_pair(1), oldwin) curses.flushinp() stdscr.getkey() mplayer.kill() change_vol(init_vol) else: tkalert(msg)
def help(self): """Display help text popup window. """ help_txt = (" Save and exit : F2 or Ctrl-x\n" " (Enter if in single-line entry mode)\n" " Exit (no save) : F3, Ctrl-c or ESC\n" " Cursor movement : Arrow keys/Ctrl-f/b/n/p\n" " Beginning of line : Home/Ctrl-a\n" " End of line : End/Ctrl-e\n" " Page Up/Page Down : PgUp/PgDn\n" " Backspace/Delete : Backspace/Ctrl-h\n" " Delete current char : Del/Ctrl-d\n" " Insert line at cursor : Enter\n" " Paste block of text : Ctrl-v\n" " Delete to end of line : Ctrl-k\n" " Delete to BOL : Ctrl-u\n") help_txt_no = (" Save and exit : F2,F3,ESC,Ctrl-c or Ctrl-x\n" " Cursor movement : Arrow keys/j-k/Ctrl-n/p\n" " Page Up/Page Down : J/K/PgUp/PgDn/Ctrl-b/n\n") if self.edit is False: help_txt = help_txt_no txt = help_txt.splitlines() try: curses.curs_set(0) except _curses.error: pass lines = len(txt) + 2 cols = max([len(i) for i in txt]) + 2 # Only print help text if the window is big enough try: popup = curses.newwin(lines, cols, self.win_location_y, self.win_location_x) addstr(popup, 1, 0, "\n".join(txt)) popup.box() except _curses.error: pass else: while not popup.getch(): pass finally: # Turn back on the cursor if self.pw_mode is False and self.edit is True: curses.curs_set(1) # flushinp Needed to prevent spurious F1 characters being written # to line curses.flushinp() self.box_init()