示例#1
0
文件: terminal.py 项目: Chiel92/tfate
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
示例#2
0
    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()
示例#3
0
    def __init__(self):
        global stdscr
        global _BASE_SCREEN

        stdscr = unicurses.initscr()
        unicurses.start_color()
        unicurses.use_default_colors()
        self.screen = stdscr

        _BASE_SCREEN = self
示例#4
0
            self.main_menu.key_event(key)
        elif not self.main_menu.enabled and self.game_menu_interface.blocked:
            self.game_field.key_event(key)
        else:
            self.game_menu_interface.key_event(key)


if __name__ == "__main__":
    stdscr = initscr()
    clear()
    noecho()
    cbreak()
    curs_set(0)
    keypad(stdscr, True)
    start_color()
    use_default_colors()
    nodelay(stdscr, True)
    init_pair(1, COLOR_BLACK, COLOR_WHITE)
    init_pair(2, COLOR_WHITE, COLOR_BLUE)
    init_pair(3, COLOR_BLACK, COLOR_BLUE)
    init_pair(4, COLOR_WHITE, COLOR_CYAN)
    init_pair(5, COLOR_YELLOW, COLOR_GREEN)
    init_pair(6, COLOR_GREEN, COLOR_BLACK)
    init_pair(7, COLOR_RED, COLOR_BLACK)
    init_pair(8, COLOR_BLUE, COLOR_YELLOW)
    init_pair(9, COLOR_RED, COLOR_YELLOW)
    init_pair(10, COLOR_WHITE, COLOR_RED)
    init_pair(11, COLOR_RED, COLOR_CYAN)

    WHITE_BLACK = COLOR_PAIR(1)
    BLUE_WHITE = COLOR_PAIR(2)
示例#5
0
        elif self.main_menu.enabled and self.game_menu_interface.blocked:
            self.main_menu.key_event(key)
        elif not self.main_menu.enabled and self.game_menu_interface.blocked:
            self.game_field.key_event(key)
        else:
            self.game_menu_interface.key_event(key)

if __name__ == "__main__":
    stdscr = initscr()
    clear()
    noecho()
    cbreak()
    curs_set(0)
    keypad(stdscr, True)
    start_color()
    use_default_colors()
    nodelay(stdscr, True)
    init_pair(1, COLOR_BLACK, COLOR_WHITE)
    init_pair(2, COLOR_WHITE, COLOR_BLUE)
    init_pair(3, COLOR_BLACK, COLOR_BLUE)
    init_pair(4, COLOR_WHITE, COLOR_CYAN)
    init_pair(5, COLOR_YELLOW, COLOR_GREEN)
    init_pair(6, COLOR_GREEN, COLOR_BLACK)
    init_pair(7, COLOR_RED, COLOR_BLACK)
    init_pair(8, COLOR_BLUE, COLOR_YELLOW)
    init_pair(9, COLOR_RED, COLOR_YELLOW)
    init_pair(10, COLOR_WHITE, COLOR_RED)
    init_pair(11, COLOR_RED, COLOR_CYAN)

    WHITE_BLACK = COLOR_PAIR(1)
    BLUE_WHITE = COLOR_PAIR(2)