我们从Python开源项目中,提取了以下37个代码示例,用于说明如何使用curses.use_default_colors()。
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 colorize(self): curses.use_default_colors() curses.init_pair(1, 7, -1) curses.init_pair(2, -1, 7) curses.init_pair(3, -1, 0) curses.init_pair(4, 2, -1) curses.init_pair(5, 3, -1) curses.init_pair(6, 3, -1) curses.init_pair(7, 6, -1) curses.init_pair(8, 5, -1) self.color_palette = {} self.color_palette["Player"] = 0 self.color_palette["NPC"] = 1 self.color_palette["dark_wall"] = 2 self.color_palette["dark_floor"] = 3 self.color_palette["goblinoid"] = 4 self.color_palette["troll"] = 5 self.color_palette['canine'] = 6 self.color_palette['elf'] = 7 self.color_palette['dwarf'] = 8
def __init__(self): self._colors = { 'white': curses.color_pair(self.PAIRS['white']), 'black': curses.color_pair(self.PAIRS['white']) | curses.A_REVERSE, 'red': curses.color_pair(self.PAIRS['red']), 'blue': curses.color_pair(self.PAIRS['blue']), 'green': curses.color_pair(self.PAIRS['green']), 'green_reverse': (curses.color_pair(self.PAIRS['green']) | curses.A_REVERSE), 'cyan': curses.color_pair(self.PAIRS['cyan']), 'cyan_reverse': (curses.color_pair(self.PAIRS['cyan']) | curses.A_REVERSE), 'yellow': curses.color_pair(self.PAIRS['yellow']), 'yellow_reverse': (curses.color_pair(self.PAIRS['yellow']) | curses.A_REVERSE), 'magenta': curses.color_pair(self.PAIRS['magenta']), 'magenta_reverse': (curses.color_pair(self.PAIRS['magenta']) | curses.A_REVERSE), } curses.start_color() curses.use_default_colors() for definition, (color, background) in self.DEFINITION.items(): curses.init_pair(definition, color, background)
def __enter__(self): # Default delay when pressing ESC is too long, at 1000ms os.environ["ESCDELAY"] = "25" self.pairs = Pairs() # Make curses use unicode locale.setlocale(locale.LC_ALL, "") self.screen = curses.initscr() curses.noecho() # Using raw instead of cbreak() gives us access to CTRL+C and others curses.raw() self.screen.keypad(True) if not self.blocking_events: self.screen.timeout(33) curses.start_color() curses.use_default_colors() self.hide_cursor() return self
def conf_scr(): '''Configure the screen and colors/etc''' curses.curs_set(0) curses.start_color() curses.use_default_colors() text, banner, banner_text, background = get_theme_colors() curses.init_pair(2, text, background) curses.init_pair(3, banner_text, banner) curses.halfdelay(10)
def init_colors(self): curses.start_color() curses.use_default_colors() colors = [ curses.COLOR_BLUE, curses.COLOR_CYAN, curses.COLOR_GREEN, curses.COLOR_MAGENTA, curses.COLOR_RED, curses.COLOR_WHITE, curses.COLOR_YELLOW ] curses.init_pair(0, curses.COLOR_WHITE, curses.COLOR_BLACK) for i, c in enumerate(colors): curses.init_pair(i + 1, c, curses.COLOR_BLACK)
def main(stdscr): curses.use_default_colors() game_field = GameField(win=32) state_actions = {} # Init, Game, Win, Gameover, Exit def init(): game_field.reset() return 'Game' state_actions['Init'] = init def not_game(state): game_field.draw(stdscr) action = get_user_action(stdscr) responses = defaultdict(lambda: state) responses['Restart'], responses['Exit'] = 'Init', 'Exit' return responses[action] state_actions['Win'] = lambda: not_game('Win') state_actions['Gameover'] = lambda: not_game('Gameover') def game(): game_field.draw(stdscr) action = get_user_action(stdscr) if action == 'Restart': return 'Init' if action == 'Exit': return 'Exit' if game_field.move(action): # move successful if game_field.is_win(): return 'Win' if game_field.is_gameover(): return 'Gameover' return 'Game' state_actions['Game'] = game state = 'Init' while state != 'Exit': state = state_actions[state]()
def config_curses(self): # use the default colors of the terminal curses.use_default_colors ( ) # hide the cursor curses.curs_set (0) # add some color for multi_select # @todo make colors configurable curses.init_pair (1, curses.COLOR_GREEN, curses.COLOR_WHITE)
def __init__(self, ts, injector, tests, do_tick, disassembler=disas_capstone): self.ts = ts; self.injector = injector self.T = tests self.gui_thread = None self.do_tick = do_tick self.ticks = 0 self.last_ins_count = 0 self.delta_log = deque(maxlen=self.RATE_Q) self.time_log = deque(maxlen=self.RATE_Q) self.disas = disassembler self.stdscr = curses.initscr() curses.start_color() # doesn't work # self.orig_colors = [curses.color_content(x) for x in xrange(256)] curses.use_default_colors() curses.noecho() curses.cbreak() curses.curs_set(0) self.stdscr.nodelay(1) self.sx = 0 self.sy = 0 self.init_colors() self.stdscr.bkgd(curses.color_pair(self.WHITE)) self.last_time = time.time()
def start(self, no_delay): self.window = curses.initscr() curses.start_color() curses.use_default_colors() curses.noecho() curses.cbreak() curses.curs_set(0) self.window.nodelay(no_delay) self.init_colors() self.window.bkgd(curses.color_pair(self.WHITE)) locale.setlocale(locale.LC_ALL, '') # set your locale self.code = locale.getpreferredencoding()
def __init__(self): """ Initialize a new TUI window in terminal. """ locale.setlocale(locale.LC_ALL, '') self._stdscr = curses.initscr() curses.start_color() curses.noecho() curses.cbreak() curses.curs_set(0) # Set colors curses.use_default_colors() for i, color in enumerate(self.colorpairs): curses.init_pair(i + 1, *color)
def run(self): ''' Runs all the windows added to the application, and returns a `Result` object. ''' result = Result() try: self.scr = curses.initscr() self.MAX_HEIGHT, self.MAX_WIDTH = self.scr.getmaxyx() curses.noecho() curses.cbreak() curses.start_color() curses.use_default_colors() self.window = self.scr.subwin(0, 0) self.window.keypad(1) self.window.nodelay(1) self._run_windows() self.threads += [gevent.spawn(self._input_loop)] gevent.joinall(self.threads) for thread in self.threads: if thread.exception: result._extract_thread_exception(thread) except KeyboardInterrupt: result._extract_exception() except Exception: result._extract_exception() finally: if self.scr is not None: self.scr.keypad(0) curses.echo() curses.nocbreak() curses.endwin() return result
def __init__(self): self.screen = curses.initscr() self.screen.timeout(100) # the screen refresh every 100ms # charactor break buffer curses.cbreak() self.screen.keypad(1) self.netease = NetEase() curses.start_color() if Config().get_item('curses_transparency'): curses.use_default_colors() curses.init_pair(1, curses.COLOR_GREEN, -1) curses.init_pair(2, curses.COLOR_CYAN, -1) curses.init_pair(3, curses.COLOR_RED, -1) curses.init_pair(4, curses.COLOR_YELLOW, -1) else: curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK) # term resize handling size = terminalsize.get_terminal_size() self.x = max(size[0], 10) self.y = max(size[1], 25) self.startcol = int(float(self.x) / 5) self.indented_startcol = max(self.startcol - 3, 0) self.update_space() self.lyric = '' self.now_lyric = '' self.tlyric = '' self.storage = Storage() self.config = Config() self.newversion = False
def create_screen(fn): """ Initializes curses and passes a Screen to the main loop function `fn`. Based on curses.wrapper. """ try: # Make escape key more responsive os.environ['ESCDELAY'] = '25' stdscr = curses.initscr() curses.noecho() curses.cbreak() stdscr.keypad(1) stdscr.nodelay(1) curses.curs_set(0) curses.mousemask(curses.BUTTON1_CLICKED) if curses.has_colors(): curses.start_color() curses.use_default_colors() screen = Screen(stdscr) fn(screen) finally: # Set everything back to normal if 'stdscr' in locals(): curses.use_default_colors() curses.curs_set(1) stdscr.keypad(0) curses.echo() curses.nocbreak() curses.endwin()
def init_colors(): """ Init the colors for the screen """ curses.use_default_colors() # Colors we use for messages, etc curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK) curses.init_pair(5, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(7, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_WHITE) colors['white'] = curses.color_pair(1) colors['green'] = curses.color_pair(2) colors['cyan'] = curses.color_pair(3) colors['yellow'] = curses.color_pair(4) colors['green-black'] = curses.color_pair(5) colors['black-white'] = curses.color_pair(6) colors['red'] = curses.color_pair(7) colors['white-white'] = curses.color_pair(8) # Allocate colour ranges here for the ma display. maprange = 10 for i in range(curses.COLORS - maprange): curses.init_pair(i + maprange, 0, i)
def main(stdscr): def init(): # ?????? game_field.reset() return 'Game' def not_game(state): # ?? GameOver ??? # ?????????Restart??Exit game_field.draw(stdscr) action = get_user_action(stdscr) responses = defaultdict(lambda: state) responses['Restart'], responses['Exit'] = 'Init', 'Exit' return responses[action] def game(): game_field.draw(stdscr) action = get_user_action(stdscr) if action == 'Restart': return 'Init' if action == 'Exit': return 'Exit' if game_field.move(action): if game_field.is_win(): return 'Win' if game_field.is_gameover(): return 'Gameover' return 'Game' state_actions = { 'Init': init, 'Win': lambda: not_game('Win'), 'Gameover': lambda: not_game('Gameover'), 'Game': game } curses.use_default_colors() game_field = GameField(win=32) state = 'Init' while state != 'Exit': state = state_actions[state]()
def screen_curses_init(): # # number of milliseconds to wait after reading an escape character, to # distinguish between an individual escape character entered on the # keyboard from escape sequences sent by cursor and function keys (see # curses(3X). os.putenv("ESCDELAY", "0") # was 25 # global STDSCR STDSCR = curses.initscr() curses.noecho() curses.cbreak() # if not curses.has_colors(): raise Exception("Need colour support to run.") curses.raw() # curses.start_color() # # This is what allows us to use -1 for default when we initialise # the pairs curses.use_default_colors() # curses.init_pair(PROFILE_GREY , curses.COLOR_WHITE , -1) curses.init_pair(PROFILE_WHITE , curses.COLOR_WHITE , -1) curses.init_pair(PROFILE_RED , curses.COLOR_RED , -1) curses.init_pair(PROFILE_VERMILION , curses.COLOR_RED , -1) curses.init_pair(PROFILE_ORANGE , curses.COLOR_RED , -1) curses.init_pair(PROFILE_AMBER , curses.COLOR_YELLOW , -1) curses.init_pair(PROFILE_YELLOW , curses.COLOR_YELLOW , -1) curses.init_pair(PROFILE_CHARTREUSE , curses.COLOR_GREEN , -1) curses.init_pair(PROFILE_GREEN , curses.COLOR_GREEN , -1) curses.init_pair(PROFILE_TEAL , curses.COLOR_CYAN , -1) curses.init_pair(PROFILE_BLUE , curses.COLOR_BLUE , -1) curses.init_pair(PROFILE_VIOLET , curses.COLOR_MAGENTA , -1) curses.init_pair(PROFILE_PURPLE , curses.COLOR_MAGENTA , -1) curses.init_pair(PROFILE_MAGENTA , curses.COLOR_MAGENTA , -1) curses.init_pair(PROFILE_BLACK_INFO , curses.COLOR_BLACK , curses.COLOR_WHITE) curses.init_pair(PROFILE_ALARM, curses.COLOR_RED , curses.COLOR_WHITE)
def start_screen(self): self.screen = curses.initscr() curses.noecho() curses.cbreak() curses.curs_set(0) self.screen.keypad(True) curses.start_color() curses.use_default_colors() curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE) curses.init_pair(2, curses.COLOR_GREEN, -1) curses.init_pair(3, curses.COLOR_CYAN, -1) curses.init_pair(4, curses.COLOR_YELLOW, -1) return None
def config_curses(self): # use the default colors of the terminal curses.use_default_colors() # hide the cursor curses.curs_set(0)
def defineColors(): curses.start_color() curses.use_default_colors() curses.init_pair(color.BLACK, curses.COLOR_BLACK, -1) curses.init_pair(color.GREY, 250, -1) curses.init_pair(color.RED, curses.COLOR_RED, -1) curses.init_pair(color.YELLOW, 143, -1) curses.init_pair(color.BLUE, curses.COLOR_BLUE, -1) # highlight text curses.init_pair(color.RED_H, curses.COLOR_RED, curses.COLOR_WHITE) curses.init_pair(color.YELLOW_H, curses.COLOR_YELLOW, curses.COLOR_WHITE)
def start(screen): curses.noecho() curses.cbreak() screen.keypad(True) curses.start_color() curses.use_default_colors() curses.curs_set(0) if curses.can_change_color(): curses.init_color(COLOR_DARKBLACK, 0, 0, 0) curses.init_color(COLOR_SUPERWHITE, 1000, 1000, 1000) curses.init_pair(PAIR_ACTIVE_TAB, COLOR_SUPERWHITE, COLOR_DARKBLACK) curses.init_pair(PAIR_TABBAR_BG, COLOR_DARKBLACK, COLOR_SUPERWHITE) else: curses.init_pair(PAIR_ACTIVE_TAB, curses.COLOR_WHITE, curses.COLOR_BLACK) curses.init_pair(PAIR_TABBAR_BG, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(PAIR_INACTIVE_TAB, curses.COLOR_WHITE, curses.COLOR_BLACK) curses.init_pair(PAIR_ACTIVE_ACCOUNT_SEL, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(PAIR_INACTIVE_ACCOUNT_SEL, curses.COLOR_WHITE, -1) curses.init_pair(PAIR_POSITIVE_VALUE, curses.COLOR_GREEN, -1) curses.init_pair(PAIR_NEGATIVE_VALUE, curses.COLOR_RED, -1) websockets_path = "ws://localhost:8888" async with api.WebSocket(websockets_path) as ws: app = Application(screen, ws) await app.start()
def _start(self): """ Initialize the screen and input mode. """ self.s = curses.initscr() self.has_color = curses.has_colors() if self.has_color: curses.start_color() if curses.COLORS < 8: # not colourful enough self.has_color = False if self.has_color: try: curses.use_default_colors() self.has_default_colors=True except _curses.error: self.has_default_colors=False self._setup_colour_pairs() curses.noecho() curses.meta(1) curses.halfdelay(10) # use set_input_timeouts to adjust self.s.keypad(0) if not self._signal_keys_set: self._old_signal_keys = self.tty_signal_keys() super(Screen, self)._start()
def __init__(self,win): self.win = win self.size = self.win.getmaxyx() curses.start_color() curses.use_default_colors() self.win.nodelay(1) for i in range(0, curses.COLORS): curses.init_pair(i + 1, i, -1) curses.curs_set(0)
def colortest(stdscr): # http://stackoverflow.com/questions/18551558/how-to-use-terminal-color-palette-with-curses curses.start_color() curses.use_default_colors() stdscr.addstr(0,0,"%s colors on \"%s\"\n" % (str(curses.COLORS),str(curses.termname().decode('ascii')))) for i in range(0, curses.COLORS): curses.init_pair(i + 1, i, -1) for i in range(curses.COLORS): try: stdscr.addstr(str(i)+"\t",curses.color_pair(i)) except: pass try: stdscr.getch() except: pass
def set_colours(colours): """ Set curses colours. Arguments: colours: Dict with colour information. """ crs.start_color() # Define colours. if colours['background'] == 'default': crs.use_default_colors() background = -1 else: crs.init_color(0, *hex_to_rgb(colours['background'])) background = 0 crs.init_color(1, *hex_to_rgb(colours['foreground'])) crs.init_color(2, *hex_to_rgb(colours['highlight'])) crs.init_color(3, *hex_to_rgb(colours['content1'])) crs.init_color(4, *hex_to_rgb(colours['content2'])) # Define colour pairs. crs.init_pair(1, 1, background) crs.init_pair(2, 2, background) crs.init_pair(3, 3, background) crs.init_pair(4, 4, background) # Set colours. crs.start_color() common.w.main.bkgdset(' ', crs.color_pair(1)) common.w.inbar.bkgdset(' ', crs.color_pair(1)) common.w.infobar.bkgdset(' ', crs.color_pair(2)) common.w.outbar.bkgdset(' ', crs.color_pair(4)) common.w.refresh()
def init_curses(cls, stdscr): # An attempt to limit the damage from this bug in curses: # https://bugs.python.org/issue13051 # The input textbox is 8 rows high. So assuming a maximum terminal # width of 512 columns, we arrive at 8x512=4096. Most terminal windows # should be smaller than this. sys.setrecursionlimit(4096) cls.stdscr = stdscr curses.use_default_colors() cls._init_color_pairs() curses.curs_set(1)
def config_curses(self): # use the default colors of the terminal curses.use_default_colors() # hide the cursor curses.curs_set(0) #add some color for multi_select #@todo make colors configurable curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_WHITE)
def init_curses(self): self.stdscr.refresh() curses.use_default_colors() self.max_y, self.max_x = self.stdscr.getmaxyx() curses.noecho() curses.cbreak() curses.curs_set(0) self.stdscr.keypad(1)
def main(stdscr): def init(): #?????? game_field.reset() return 'Game' def not_game(state): #?? GameOver ?? Win ??? game_field.draw(stdscr) #????????action?????????????? action = get_user_action(stdscr) responses = defaultdict(lambda: state) #??????????????????????? responses['Restart'], responses['Exit'] = 'Init', 'Exit' #??????????????? return responses[action] def game(): #???????? game_field.draw(stdscr) #????????action action = get_user_action(stdscr) if action == 'Restart': return 'Init' if action == 'Exit': return 'Exit' if game_field.move(action): # move successful if game_field.is_win(): return 'Win' if game_field.is_gameover(): return 'Gameover' return 'Game' state_actions = { 'Init': init, 'Win': lambda: not_game('Win'), 'Gameover': lambda: not_game('Gameover'), 'Game': game } curses.use_default_colors() game_field = GameField(win=32) state = 'Init' #??????? while state != 'Exit': state = state_actions[state]()
def win_init(self): """Set initial editor window size parameters, and reset them if window is resized. """ # self.cur_pos is the current y,x position of the cursor relative to # the visible area of the box self.cur_pos_y = 0 self.cur_pos_x = 0 # y_offset controls the up-down scrolling feature self.y_offset = 0 # Position of the cursor relative to the upper left corner of the data # (self.flattend_text) self.buffer_idx_y = 0 self.buffer_idx_x = 0 # Make sure requested window size is < available window size self.max_win_size_y, self.max_win_size_x = self.scr.getmaxyx() # Keep the input box inside the physical window self.win_size_y = min(self.win_size_orig_y, self.max_win_size_y) self.win_size_x = min(self.win_size_orig_x, self.max_win_size_x) # Validate win_location settings self.win_location_x = min(max(0, self.max_win_size_x - self.win_size_x), self.win_location_orig_x) self.win_location_y = min(max(0, self.max_win_size_y - self.win_size_y), self.win_location_orig_y) # Adjust max_win_size for different possible offsets # (e.g. if there is a title and/or a box) and initiate the curses # screen(s) self._win_scr_init() self.title, self.title_help = self._title_init() self.stdscr.keypad(1) try: curses.use_default_colors() except _curses.error: pass if self.pw_mode is True: try: curses.curs_set(0) except _curses.error: pass
def main(): steps = 0 scr = curses.initscr() scr.nodelay(1) curses.curs_set(0) curses.noecho() if USE_COLORS: curses.start_color() curses.use_default_colors() curses.init_pair(COLOR_CHAR_NORMAL, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(COLOR_CHAR_HIGHLIGHT, curses.COLOR_WHITE, curses.COLOR_GREEN) curses.init_pair(COLOR_WINDOW, curses.COLOR_GREEN, curses.COLOR_GREEN) height, width = scr.getmaxyx() window_animation = None lines = [] for i in range(DROPPING_CHARS): l = FallingChar(width, MIN_SPEED, MAX_SPEED) l.y = randint(0, height-2) lines.append(l) scr.refresh() while True: height, width = scr.getmaxyx() for line in lines: line.tick(scr, steps) for i in range(RANDOM_CLEANUP): x = randint(0, width-1) y = randint(0, height-1) scr.addstr(y, x, ' ') if randint(0, WINDOW_CHANCE) == 1: if window_animation is None: #start window animation line = random.choice(lines) window_animation = WindowAnimation(line.x, line.y) if not window_animation is None: still_active = window_animation.tick(scr, steps) if not still_active: window_animation = None scr.refresh() time.sleep(SLEEP_MILLIS) if SCREENSAVER_MODE: key_pressed = scr.getch() != -1 if key_pressed: raise KeyboardInterrupt() steps += 1
def using_curses(func): def inner(*largs, **kwargs): """ Calls decorated function with initial curses screen inserted as first argument. Content mostly taken from curses.wrapper, modified to function as a decorator, and to introduce cursor removal """ 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() curses.use_default_colors() except: pass # Set colour pallet curses.init_pair(CPI_GOOD, curses.COLOR_GREEN, -1) curses.init_pair(CPI_ERROR, curses.COLOR_RED, -1) curses.init_pair(CPI_WARNING, curses.COLOR_YELLOW, -1) # Remove blinking cursor curses.curs_set(0) func(stdscr, *largs, **kwargs) finally: # Set everything back to normal if 'stdscr' in locals(): curses.curs_set(1) stdscr.keypad(0) curses.echo() # revert curses.noecho() curses.nocbreak() # revert curses.cbreak() curses.endwin() return inner # ================== Status (header) Window ==================
def init(self, stdscr): self.stdscr = stdscr curses.curs_set(0) self.stdscr.keypad(1) self.height, self.width = stdscr.getmaxyx() curses.start_color() curses.use_default_colors() #curses.echo() self._init_colors() self.bar = curses.newwin(1, self.width, 0, 0) self.bar.keypad(True) self.barpan = curses.panel.new_panel(self.bar) self.TC, self.TCpan, self._TC, self._TCpan =\ newlinebox(MAXDISPLAYTC, self.width, 2, 0, "Telecommands") self.TC.scrollok(True) self.TC.idlok(True) self.TC.refresh() self.TM, self.TMpan, self._TM, self._TMpan =\ newlinebox(MAXDISPLAYTM, self.width, MAXDISPLAYTC+3, 0, "Telemetries") self.TM.scrollok(True) self.TM.idlok(True) self.TM.refresh() self.RP, self.RPpan, self._RP, self._RPpan =\ newlinebox(MAXDISPLAYRP, self.width, MAXDISPLAYTM+MAXDISPLAYTC+4, 0, "Reporting") self.RP.refresh() self.updpan() time.sleep(0.2) # give it a bit of air self.pan_box = 0 self.PANBOX = {0: self.TC, 1: self.TM} self.pan_loc = {0: 0, 1: 0, 2: 0} self.running = True #self.bar.erase()refresh self.disp(self.bar, PrintOut(' '*(self.width-1))) self.set_listenico(status=self.NOSTARTED) self.set_controlico(status=self.NOSTARTED) self.set_saveico(status=self.NOSTARTED) loopy = Thread(target=loop_time, args=(self,)) loopy.daemon = True loopy.start() loopy = Thread(target=update_it, args=(self,)) loopy.daemon = True loopy.start() self._key_catch() return
def main(stdscr): def init(): game_field.reset() return "Game" def not_game(state): game_field.draw(stdscr) action = get_user_action(stdscr) responses = defaultdict(lambda:state) responses["Restart"],responses["Exit"] = "Init","Exit" return responses[action] def game(): game_field.draw(stdscr) action = get_user_action(stdscr) if action == "Restart": return "Init" if action == "Exit": return "Exit" if game_field.move(action): if game_field.is_win(): return "Win" if game_field.is_gameover(): return "Gameover" return "Game" state_actions = { "Init":init, "Win":lambda:not_game("Win"), "Gameover":lambda:not_game("Gameover"), "Game":game } curses.use_default_colors() game_field = GameField(win = 32) state = "Init" while state != "Exit": state = state_actions[state]()
def __init__(self, cursesScreen): self.clicks = 0 self.debugMouseEvent = (0, 0, 0, 0, 0) self.exiting = False self.modalUi = None self.modeStack = [] self.priorClick = 0 self.savedMouseButton1Down = False self.savedMouseWindow = None self.savedMouseX = -1 self.savedMouseY = -1 self.cursesScreen = cursesScreen self.ch = 0 curses.mousemask(-1) curses.mouseinterval(0) # Enable mouse tracking in xterm. sys.stdout.write('\033[?1002;h\n') #sys.stdout.write('\033[?1005;h\n') curses.meta(1) # Access ^c before shell does. curses.raw() # Enable Bracketed Paste Mode. sys.stdout.write('\033[?2004;h\n') #curses.start_color() curses.use_default_colors() if 0: assert(curses.COLORS == 256) assert(curses.can_change_color() == 1) assert(curses.has_colors() == 1) app.log.detail("color_content:") for i in range(0, curses.COLORS): app.log.detail("color", i, ": ", curses.color_content(i)) for i in range(16, curses.COLORS): curses.init_color(i, 500, 500, i * 787 % 1000) app.log.detail("color_content, after:") for i in range(0, curses.COLORS): app.log.detail("color", i, ": ", curses.color_content(i)) self.setUpPalette() if 1: #rows, cols = self.cursesScreen.getmaxyx() cursesWindow = self.cursesScreen cursesWindow.leaveok(1) # Don't update cursor position. cursesWindow.scrollok(0) cursesWindow.timeout(10) cursesWindow.keypad(1) self.top, self.left = cursesWindow.getyx() self.rows, self.cols = cursesWindow.getmaxyx() app.window.mainCursesWindow = cursesWindow self.zOrder = []
def main(stdscr): def init(): # ?????? game_field.reset() return "Game" def not_game(state): # ?? Win ? GameOver ??? game_field.draw(stdscr) # ????????? action?????????????? action = get_user_action(stdscr) # ??????????????????????? responses = defaultdict(lambda: state) # ??????????????? responses['Restart'], responses['Exit'] = 'Init', 'Exit' return responses[action] def game(): # ???????? game_field.draw(stdscr) # ????????? action????????? action = get_user_action(stdscr) if action == 'Restart': return 'Init' if action == 'Exit': return 'Exit' # move successful if game_field.move(action): if game_field.is_win(): return 'Win' if game_field.is_gameover(): return 'Gameover' return 'Game' state_actions = { 'Init': init, 'Win': lambda: not_game('Win'), 'Gameover': lambda: not_game('Gameover'), 'Game': game } curses.use_default_colors() game_field = GameField(win=64) state = 'Init' # ??????? while state != 'Exit': state = state_actions[state]()