python类COLOR_RED的实例源码

ndw.py 文件源码 项目:DarkWallet 作者: DissentDifference 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
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()
monitor.py 文件源码 项目:foe-bot 作者: m3talstorm 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def run(self):
        """
        """

        self.setup()

        # Clear screen
        self.screen.clear()
        #
        curses.start_color()

        curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
        curses.init_pair(3, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
        curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)
        curses.init_pair(5, curses.COLOR_RED, curses.COLOR_BLACK)
        curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_BLACK)

        while True:
            #
            session.expire_all()
            # TODO: Add some standard header to the top? (like interval time etc)
            #
            self.render()
            #
            self.increment.reset()
            #
            self.screen.refresh()
            #
            time.sleep(self.interval)

            self.running += self.interval

        return
recipe-577933.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def getStats(scr):
    curses.init_pair(9,  curses.COLOR_WHITE,  curses.COLOR_BLACK)
    curses.init_pair(10, curses.COLOR_YELLOW, curses.COLOR_BLACK)
    curses.init_pair(11, curses.COLOR_RED,    curses.COLOR_BLACK)
    curses.init_pair(12, curses.COLOR_GREEN,  curses.COLOR_BLACK)
    (maxY, maxX) = scr.getmaxyx()
    while 1:
        try:
            display_time(scr)
            display_loadavg(scr)
            display_header(scr)
            #write(scr, 3, 0, '%-4s %-20s %-15s %-40s%s' % ('Slot', 'Remote Host', 'State', 'Filename', ' '*(maxX-83)), curses.A_BOLD)
            cnt = 5
            try:
                for i in os.listdir(DISTCC_DIR+'/state'):
                    data = struct.unpack('@iLL128s128siiP', open(DISTCC_DIR+'/state/'+i).readline().strip())
                    file = data[3].split('\x00')[0] or 'None'
                    host = data[4].split('\x00')[0] or 'None'
                    slot = int(data[5])
                    stte = states[int(data[6])]
                    scr.move(cnt,0)
                    scr.clrtoeol()
                    if 'None' not in (file, host):
                        write(scr, cnt, 0, '%s' % slot, curses.color_pair(9))
                        write(scr, cnt, 5, '%s' % host, curses.color_pair(9))
                        if int(data[6]) in (2,3):
                            write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(10))
                        elif int(data[6]) in (0,1):
                            write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(11))
                        elif int(data[6]) in (4,5):
                            write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(12))
                        elif int(data[6]) in (6,7):
                            write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(12)|curses.A_BOLD)
                        else: write(scr, cnt, 25, '%s ' % (stte))
                        write(scr, cnt, 45, '%s' % file, curses.color_pair(9))
                        cnt += 1
            except struct.error: pass
            except IOError: pass
            scr.refresh()
            time.sleep(0.75)
            scr.erase()
            scr.move(0,0)
        except KeyboardInterrupt:
            sys.exit(-1)
menu.py 文件源码 项目:new 作者: atlj 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def create(liste):
    screen = curses.initscr()
    curses.start_color()
    curses.init_pair(1,curses.COLOR_RED, curses.COLOR_WHITE)
    s = curses.color_pair(1)
    h = curses.A_NORMAL
    pos = 0

    while 1:
        curses.noecho()
        screen.clear()
        screen.border(0)
        screen.keypad(True)
        screen.addstr(1,2,"(w)Yukari/Up (s)Asagi/Down (e)Sec", curses.A_BOLD)
        a = 0
        b = 4
        c = 3
        for oge in liste:
            if int(a/15)<1:
                if pos == a:
                    screen.addstr(b, 4, "".join(liste[a]), s)
                else:
                    screen.addstr(b, 4, "".join(liste[a]), h)
            else:
                c = c + 1
                if pos == a:
                    screen.addstr(c, 23, "".join(liste[a]), s)
                else:
                    screen.addstr(c, 23, "".join(liste[a]), h)


            a = a + 1
            b = b + 1
        screen.refresh()
        try:
            inp = screen.getkey(1,1)

            if inp == 'e':
                screen.refresh()
                curses.echo()
                screen.keypad(False)
                curses.endwin()
                break
            if inp == 'w':
                if pos > 0:
                    pos = pos - 1
                else:
                    pos = len(liste)-1
            if inp== 's':
                if pos < len(liste)-1:
                    pos = pos + 1
                else:
                    pos=0
        except Exception as e:
            pass
    return pos
sifter.py 文件源码 项目:sandsifter 作者: xoreaxeaxeax 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def init_colors(self):
        if curses.has_colors() and curses.can_change_color():
            curses.init_color(self.COLOR_BLACK, 0, 0, 0)
            curses.init_color(self.COLOR_WHITE, 1000, 1000, 1000)
            curses.init_color(self.COLOR_BLUE, 0, 0, 1000)
            curses.init_color(self.COLOR_RED, 1000, 0, 0)
            curses.init_color(self.COLOR_GREEN, 0, 1000, 0)

            # this will remove flicker, but gives boring colors
            '''
            self.COLOR_BLACK = curses.COLOR_BLACK
            self.COLOR_WHITE = curses.COLOR_WHITE
            self.COLOR_BLUE = curses.COLOR_BLUE
            self.COLOR_RED = curses.COLOR_RED
            self.COLOR_GREEN = curses.COLOR_GREEN
            '''

            for i in xrange(0, self.GRAYS):
                curses.init_color(
                        self.GRAY_BASE + i,
                        i * 1000 / (self.GRAYS - 1),
                        i * 1000 / (self.GRAYS - 1),
                        i * 1000 / (self.GRAYS - 1)
                        )
                curses.init_pair(
                        self.GRAY_BASE + i,
                        self.GRAY_BASE + i,
                        self.COLOR_BLACK
                        )

        else:
            self.COLOR_BLACK = curses.COLOR_BLACK
            self.COLOR_WHITE = curses.COLOR_WHITE
            self.COLOR_BLUE = curses.COLOR_BLUE
            self.COLOR_RED = curses.COLOR_RED
            self.COLOR_GREEN = curses.COLOR_GREEN

            for i in xrange(0, self.GRAYS):
                curses.init_pair(
                        self.GRAY_BASE + i,
                        self.COLOR_WHITE,
                        self.COLOR_BLACK
                        )

        curses.init_pair(self.BLACK, self.COLOR_BLACK, self.COLOR_BLACK)
        curses.init_pair(self.WHITE, self.COLOR_WHITE, self.COLOR_BLACK)
        curses.init_pair(self.BLUE, self.COLOR_BLUE, self.COLOR_BLACK)
        curses.init_pair(self.RED, self.COLOR_RED, self.COLOR_BLACK)
        curses.init_pair(self.GREEN, self.COLOR_GREEN, self.COLOR_BLACK)
window.py 文件源码 项目:grbl-stream 作者: fragmuffin 项目源码 文件源码 阅读 57 收藏 0 点赞 0 评论 0
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 ==================
_term.py 文件源码 项目:deb-python-rjsmin 作者: openstack 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self):
        """ Initialization """
        dict.__init__(self, {
            'NORMAL': '',
            'BOLD': '',
            'ERASE': '\n',
            'RED': '',
            'YELLOW': '',
            'GREEN': '',
        })
        try:
            import curses as _curses
        except ImportError:
            # fixup if a submodule of curses failed.
            if 'curses' in _sys.modules:
                del _sys.modules['curses']
        else:
            try:
                _curses.setupterm()
            except (TypeError, _curses.error):
                pass
            else:
                try:
                    _curses.tigetstr('sgr0')
                except TypeError:  # pypy3
                    # pylint: disable = invalid-name
                    bc = lambda val: val.encode('ascii')
                else:
                    bc = lambda val: val  # pylint: disable = invalid-name

                def make_color(color):
                    """ Make color control string """
                    seq = _curses.tigetstr(bc('setaf'))
                    if seq is not None:
                        seq = _curses.tparm(seq, color).decode('ascii')
                    return seq

                self['NORMAL'] = _curses.tigetstr(bc('sgr0')).decode('ascii')
                self['BOLD'] = _curses.tigetstr(bc('bold')).decode('ascii')

                erase = _curses.tigetstr(bc('el1')).decode('ascii')
                if erase is not None:
                    self['ERASE'] = erase + \
                        _curses.tigetstr(bc('cr')).decode('ascii')

                self['RED'] = make_color(_curses.COLOR_RED)
                self['YELLOW'] = make_color(_curses.COLOR_YELLOW)
                self['GREEN'] = make_color(_curses.COLOR_GREEN)
2049.py 文件源码 项目:colorful2048 作者: liuyuxuan123 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def draw(self,screen):
        help_string1 = '(W)Up (S)Down (A)Left (D)Right'
        help_string2 = '     (R)Restart (Q)Exit'
        gameover_string = '           GAME OVER'
        win_string = '          YOU WIN!'

        def cast(string):
            screen.addstr(string + "\n")

        def cast_pawn(string):
            curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
            curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_WHITE)
            curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_WHITE)
            curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_WHITE)
            word_list = string.split() 
            for element in word_list:
                if element in "0123456789":
                    if int(element) == 2:
                        screen.addstr(element,curses.color_pair(1))
                    elif int(element) == 4:
                        screen.addstr(element,curses.color_pair(2))
                    elif int(element) == 8:
                        screen.addstr(element,curses.color_pair(3))
                    else:
                        screen.addstr(element,curses.color_pair(4))
                else:
                    screen.addstr(element)
            screen.addstr("\n")


        def draw_hor_separator():
            line = "+" + ("+------" * self.width + "+")[1:]
            separator = defaultdict(lambda:line)
            if not hasattr(draw_hor_separator,"counter"):
                draw_hor_separator.counter = 0
            cast(separator[draw_hor_separator.counter])
            draw_hor_separator.counter += 1

        def draw_row(row):
            cast_pawn(''.join('|{: ^5} '.format(num) if num > 0 else '|      ' for num in row) + '|')

        screen.clear()
        cast("SCORE: " + str(self.score))
        if 0 != self.high_score:
            cast("HIGH SCORE " + str(self.high_score))
        for row in self.field:
            draw_hor_separator()
            draw_row(row)
        draw_hor_separator()
        if self.is_win():
            cast(win_string)
        else:
            if self.is_gameover():
                cast(gameover_string)
            else:
                cast(help_string1)
        cast(help_string2)
_term.py 文件源码 项目:deb-python-rcssmin 作者: openstack 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self):
        """ Initialization """
        dict.__init__(self, {
            'NORMAL': '',
            'BOLD': '',
            'ERASE': '\n',
            'RED': '',
            'YELLOW': '',
            'GREEN': '',
        })
        try:
            import curses as _curses
        except ImportError:
            # fixup if a submodule of curses failed.
            if 'curses' in _sys.modules:
                del _sys.modules['curses']
        else:
            try:
                _curses.setupterm()
            except (TypeError, _curses.error):
                pass
            else:
                try:
                    _curses.tigetstr('sgr0')
                except TypeError:  # pypy3
                    # pylint: disable = invalid-name
                    bc = lambda val: val.encode('ascii')
                else:
                    bc = lambda val: val  # pylint: disable = invalid-name

                def make_color(color):
                    """ Make color control string """
                    seq = _curses.tigetstr(bc('setaf'))
                    if seq is not None:
                        seq = _curses.tparm(seq, color).decode('ascii')
                    return seq

                self['NORMAL'] = _curses.tigetstr(bc('sgr0')).decode('ascii')
                self['BOLD'] = _curses.tigetstr(bc('bold')).decode('ascii')

                erase = _curses.tigetstr(bc('el1')).decode('ascii')
                if erase is not None:
                    self['ERASE'] = erase + \
                        _curses.tigetstr(bc('cr')).decode('ascii')

                self['RED'] = make_color(_curses.COLOR_RED)
                self['YELLOW'] = make_color(_curses.COLOR_YELLOW)
                self['GREEN'] = make_color(_curses.COLOR_GREEN)
nc.py 文件源码 项目:soyouhaveanidea 作者: yigitbey 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def init_ui():
    check_size()
    begin_x = 1
    begin_y = 1
    height = 40
    width = 160
    left_win_width = 28
    middle_win_width = 80
    right_win_width = width - left_win_width - middle_win_width - 4

    win = newwin(height, width, begin_y, begin_x)
    win.border(0, 0, 0, 0, 0, 0, 0, 0)
    win.addstr("So You Have an Idea")
    win.refresh()

    left_win = win.subwin(height-5, left_win_width, 2, 2)
    left_win.border(0, 0, 0, 0, 0, 0, 0, 0)
    left_win.refresh()
    left_win = left_win.derwin(height-7, left_win_width-2, 1, 1)

    middle_win = win.subwin(height-5, middle_win_width, 2, left_win_width+2)
    middle_win.border(0, 0, 0, 0, 0, 0, 0, 0)
    for x in range(6, 20, 2):
        middle_win.addstr(x, middle_win_width-1, ">")
    middle_win.refresh()
    middle_win = middle_win.derwin(height-7, middle_win_width-2, 1, 1)

    right_win = win.subwin(height-5, right_win_width, 2, left_win_width + middle_win_width + 2)
    right_win.border(0, 0, 0, 0, 0, 0, 0, 0)
    for x in range(7, 21, 2):
        right_win.addstr(x, 0, "<")
    right_win.refresh()
    right_win = right_win.derwin(height-7, right_win_width-2, 1, 1)

    bottom_win = win.subwin(3, width-4, height-3, 2)
    bottom_win.border(0, 0, 0, 0, 0, 0, 0, 0)
    bottom_win.refresh()
    bottom_win = bottom_win.derwin(1, 114, 1, 1)

    left_win.refresh()
    middle_win.refresh()
    right_win.refresh()
    bottom_win.refresh()

    curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_BLACK)
    curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK)
    curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK)

    return left_win, middle_win, right_win, bottom_win, win
__main__.py 文件源码 项目:asciidots 作者: aaronduino 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, env, ticks, silent, debug, compat_debug, debug_lines, autostep_debug, output_limit):
        """

        :param dots.environment.Env env: The env of the interpreter
        :param int ticks: The max number of ticks for the program
        :param bool silent: True to turn off all outputs
        :param bool debug: True to show the execution of the program
        :param bool compat_debug: True to show the debug with only builtin functions
        :param int debug_lines: The number of lines to show the debug
        :param float autostep_debug: The timebetween automatic ticks. 0 disables the auto ticks.
        :param int output_limit: The max number of outputs for the program
        """
        super().__init__(env)

        # if it is zero or false, we don't want to stop
        self.ticks_left = ticks or float('inf')
        self.outputs_left = output_limit or float('inf')

        self.silent = silent
        self.debug = debug
        self.compat_debug = compat_debug
        self.debug_lines = debug_lines
        self.debug_cols = terminalsize.get_terminal_size()[0] - 1
        self.autostep_debug = autostep_debug

        self.compat_logging_buffer = ''
        self.compat_logging_buffer_lines = terminal_lines - debug_lines - 1

        self.first_tick = True

        if self.debug and not self.compat_debug:
            self.logging_loc = 0
            self.logging_x = 1

            self.stdscr = curses.initscr()

            curses.start_color()

            curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
            curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
            curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
            curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_BLACK)

            curses.noecho()

            # hides the cursor
            curses.curs_set(False)

            # defining the two main parts of the screen: the view of the program
            self.win_program = curses.newwin(self.debug_lines, curses.COLS, 0, 0)
            # and pad for the output of the prog
            self.logging_pad = curses.newpad(1000, curses.COLS - 1)

            def signal_handler(signal, frame):
                self.on_finish()
                sys.exit(0)

            signal.signal(signal.SIGINT, signal_handler)


问题


面经


文章

微信
公众号

扫码关注公众号