def init_colors(): """ Initialize color pairs from the terminal color palette. Pair 0 is the default, pairs 1-16 are the palette colors, pairs 17-32 are palette colors with a different background. We assume that color 8 has good contrast with other colors. """ global HAS_COLORS HAS_COLORS = curses.has_colors() if HAS_COLORS: curses.start_color() curses.use_default_colors() global HAS_BACKGROUND_COLORS HAS_BACKGROUND_COLORS = True if HAS_BACKGROUND_COLORS: info('Terminal supports background colors.') else: info('Terminal does not support background colors.') global COLOR_PAIRS #COLOR_PAIRS = min(16, curses.COLORS) COLOR_PAIRS = 16 info('Terminal supports {} colors. Using {} colorpairs.'.format(16, COLOR_PAIRS)) for i in range(COLOR_PAIRS): curses.init_pair(i + 1, i, -1) try: curses.init_pair(i + 1 + COLOR_PAIRS, i, 8) curses.init_pair(i + 1 + COLOR_PAIRS + COLOR_PAIRS, i, 9) except: HAS_BACKGROUND_COLORS = False
def _start(self): """ Initialize the screen and input mode. """ self.stdscr = 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(None, 1) #todo curses.meta( None,1) curses.halfdelay(1) # use set_input_timeouts to adjust self.stdscr.keypad(True) if not self._signal_keys_set: self._old_signal_keys = self.tty_signal_keys() self.set_mouse_tracking(True) super(Screen, self)._start()
def main(): if not curses.has_colors(): print("Your terminal emulator needs to have colors.") return 0 ## Curses normal init sequence stdscr = curses.initscr() curses.noecho() # no echo, but we still see the cursor curses.curs_set(False) #turns off the cursor drawing stdscr.keypad(True) # allows special keys and arrow keys try: curses.start_color() curses.update_panels() curses.doupdate() while True: key = curses.getch() if key == 27: break curses.update_panels() curses.doupdate() except Exception as e: stdscr.addstr(0, 0, str(e)) stdscr.getch() finally: curses.endwin() return 0
def main(): if not curses.has_colors(): print("Your terminal emulator needs to have colors.") return 0 ## Curses normal init sequence stdscr = curses.initscr() curses.noecho() # no echo, but we still see the cursor curses.curs_set(False) #turns off the cursor drawing stdscr.keypad(True) # allows special keys and arrow keys try: curses.start_color() avatar = Player(stdscr, "@", curses.COLOR_RED, curses.COLOR_BLACK, curses.A_BOLD) curses.attron(curses.color_pair(1)) curses.vline("|", 10) curses.hline("-", 10) curses.attroff(curses.color_pair(1)) while True: key = curses.getch() avatar.move(key) if key == 27: break curses.update_panels() curses.doupdate() except Exception as e: stdscr.addstr(0, 0, str(e)) stdscr.getch() finally: curses.endwin() return 0