我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用curses.ERR。
def get_key(self, block=True, timeout=None): if timeout: check = select.select([sys.stdin], [], [], timeout)[0] if len(check) == 0: return None ret = self.stdscrs[-1].getkey() elif block: ret = self.stdscrs[-1].getkey() else: self.stdscrs[-1].nodelay(1) try: ret = self.stdscrs[-1].getkey() if ret == curses.ERR: ret = None except: ret = None finally: self.stdscrs[-1].nodelay(0) if len(ret) == 1: if ord(ret) < 0x20: ret = "^{}".format(chr(ord(ret) + ord('@'))) elif ord(ret) == 0x7f: ret = "^?" return ret
def main(stdscr): curses.start_color() curses.use_default_colors() for i in range(0, curses.COLORS): curses.init_pair(i + 1, i, -1) try: for i in range(0, 255): stdscr.addstr(str(i), curses.color_pair(i)) stdscr.addstr(" ") except curses.ERR: # End of screen reached pass stdscr.getch()
def _run(self, callback): self._create_desktop() if not callback(self): return self._redraw() self._desktop.window.nodelay(True) while True: c = self._desktop.window.getch() if c == curses.ERR: if not callback(self): return time.sleep(1) elif c == ord('q'): break elif c == curses.KEY_RESIZE: self._updated = True if self._updated: self._redraw() self._updated = False