Python curses 模块,COLOR_WHITE 实例源码

我们从Python开源项目中,提取了以下45个代码示例,用于说明如何使用curses.COLOR_WHITE

项目:Parallel.GAMIT    作者:demiangomez    | 项目源码 | 文件源码
def __init__(self, stdscreen):

        curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_RED, curses.COLOR_WHITE)
        curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)

        global screen
        screen = stdscreen
        self.screen = stdscreen
        curses.curs_set(0)

        main_menu_items = get_records()

        main_menu_items += [{'field': 'Insert new station information record', 'function': selection_main_menu}]

        main_menu = Menu(cnn, main_menu_items, self.screen, 'Station information new/edit/delete - %s.%s' % (stn['NetworkCode'], stn['StationCode']))

        main_menu.display()
项目:pyfeld    作者:scjurgen    | 项目源码 | 文件源码
def __init__(self):
        self.selected_index_stack = [0]
        self.returnString = ""
        self.play_in_room = None
        self.dir = DirBrowse()
        self.selected_index = 0
        self.selected_column = 0
        self.window = curses.initscr()
        curses.start_color()
        curses.noecho()
        curses.cbreak()
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
        curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_WHITE)
        curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLACK)
        curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_RED)
        curses.init_pair(5, curses.COLOR_YELLOW, curses.COLOR_BLUE)

        self.window.keypad(1)
        self.draw_ui()
项目:culour    作者:shohamp    | 项目源码 | 文件源码
def _add_line(y, x, window, line):
    # split but \033 which stands for a color change
    color_split = line.split('\033')

    # Print the first part of the line without color change
    default_color_pair = _get_color(curses.COLOR_WHITE, curses.COLOR_BLACK)
    window.addstr(y, x, color_split[0], curses.color_pair(default_color_pair))
    x += len(color_split[0])

    # Iterate over the rest of the line-parts and print them with their colors
    for substring in color_split[1:]:
        color_str = substring.split('m')[0]
        substring = substring[len(color_str)+1:]
        color_pair = _color_str_to_color_pair(color_str)
        window.addstr(y, x, substring, curses.color_pair(color_pair))
        x += len(substring)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def strng2():
    treescrn2.attrset(curses.A_BOLD | curses.A_BLINK)
    set_color(treescrn2, curses.COLOR_WHITE)

    treescrn2.addch(5, 14, ord('\''))
    treescrn2.addch(5, 13, ord(':'))
    treescrn2.addch(5, 12, ord('.'))
    treescrn2.addch(5, 11, ord(','))
    treescrn2.addch(6, 10, ord('\''))
    treescrn2.addch(6, 9, ord(':'))

    treescrn2.attroff(curses.A_BOLD | curses.A_BLINK)
    unset_color(treescrn2)

    treescrn2.refresh()
    w_del_msg.refresh()
    return
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def strng3():
    treescrn2.attrset(curses.A_BOLD | curses.A_BLINK)
    set_color(treescrn2, curses.COLOR_WHITE)

    treescrn2.addch(7, 16, ord('\''))
    treescrn2.addch(7, 15, ord(':'))
    treescrn2.addch(7, 14, ord('.'))
    treescrn2.addch(7, 13, ord(','))
    treescrn2.addch(8, 12, ord('\''))
    treescrn2.addch(8, 11, ord(':'))
    treescrn2.addch(8, 10, ord('.'))
    treescrn2.addch(8, 9, ord(','))

    treescrn2.attroff(curses.A_BOLD | curses.A_BLINK)
    unset_color(treescrn2)

    treescrn2.refresh()
    w_del_msg.refresh()
    return
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def strng4():
    treescrn2.attrset(curses.A_BOLD | curses.A_BLINK)
    set_color(treescrn2, curses.COLOR_WHITE)

    treescrn2.addch(9, 17, ord('\''))
    treescrn2.addch(9, 16, ord(':'))
    treescrn2.addch(9, 15, ord('.'))
    treescrn2.addch(9, 14, ord(','))
    treescrn2.addch(10, 13, ord('\''))
    treescrn2.addch(10, 12, ord(':'))
    treescrn2.addch(10, 11, ord('.'))
    treescrn2.addch(10, 10, ord(','))
    treescrn2.addch(11, 9, ord('\''))
    treescrn2.addch(11, 8, ord(':'))
    treescrn2.addch(11, 7, ord('.'))
    treescrn2.addch(11, 6, ord(','))
    treescrn2.addch(12, 5, ord('\''))

    treescrn2.attroff(curses.A_BOLD | curses.A_BLINK)
    unset_color(treescrn2)

    treescrn2.refresh()
    w_del_msg.refresh()
    return
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def strng5():
    treescrn2.attrset(curses.A_BOLD | curses.A_BLINK)
    set_color(treescrn2, curses.COLOR_WHITE)

    treescrn2.addch(11, 19, ord('\''))
    treescrn2.addch(11, 18, ord(':'))
    treescrn2.addch(11, 17, ord('.'))
    treescrn2.addch(11, 16, ord(','))
    treescrn2.addch(12, 15, ord('\''))
    treescrn2.addch(12, 14, ord(':'))
    treescrn2.addch(12, 13, ord('.'))
    treescrn2.addch(12, 12, ord(','))

    treescrn2.attroff(curses.A_BOLD | curses.A_BLINK)
    unset_color(treescrn2)

    # save a fully lit tree
    treescrn2.overlay(treescrn)

    treescrn2.refresh()
    w_del_msg.refresh()
    return
项目:flux_line_bot    作者:blesscat    | 项目源码 | 文件源码
def setup(self):
        curses.start_color()
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)

        curses.cbreak()
        curses.echo()

        lines, cols = self.stdscr.getmaxyx()
        self.logwin = self.stdscr.subwin(lines - 2, cols, 0, 0)
        self.sepwin = self.stdscr.subwin(1, cols, lines - 2, 0)
        self.cmdwin = self.stdscr.subwin(1, cols, lines - 1, 0)

        self.logwin.scrollok(True)

        self.sepwin.bkgd(curses.color_pair(1))
        self.sepwin.refresh()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def _setup_colour_pairs(self):
        """
        Initialize all 63 color pairs based on the term:
        bg * 8 + 7 - fg
        So to get a color, we just need to use that term and get the right color
        pair number.
        """
        if not self.has_color:
            return

        for fg in xrange(8):
            for bg in xrange(8):
                # leave out white on black
                if fg == curses.COLOR_WHITE and \
                   bg == curses.COLOR_BLACK:
                    continue

                curses.init_pair(bg * 8 + 7 - fg, fg, bg)
项目:fingerpi    作者:zafartahirov    | 项目源码 | 文件源码
def processmenu(screen, menu, parent=None, status_bottom = 'Uninitialized...'):
    curses.init_pair(1,curses.COLOR_BLACK, curses.COLOR_WHITE)
    curses.curs_set(0)
    status_mid = ''
    optioncount = len(menu['options'])
    exitmenu = False
    # response = None
    while not exitmenu: #Loop until the user exits the menu
        getin = runmenu(screen, menu, parent, status_mid, status_bottom)
        if getin == optioncount:
            exitmenu = True
        elif menu['options'][getin]['type'] == COMMAND:
            screen.clear() #clears previous screen
            status_mid, status_bottom = processrequest(menu['options'][getin], screen) # Add additional space
            ## Show the updated status
            screen.clear() #clears previous screen on key press and updates display based on pos
        elif menu['options'][getin]['type'] == MENU:
            screen.clear() #clears previous screen on key press and updates display based on pos
            processmenu(screen, menu['options'][getin], menu, status_bottom) # display the submenu, and make sure the status is persistent
            screen.clear() #clears previous screen on key press and updates display based on pos
        elif menu['options'][getin]['type'] == EXITMENU:
            exitmenu = True
项目:botany    作者:jifunks    | 项目源码 | 文件源码
def define_colors(self):
        # set curses color pairs manually
        curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
        curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
        curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
        curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_BLACK)
        curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
        curses.init_pair(6, curses.COLOR_YELLOW, curses.COLOR_BLACK)
        curses.init_pair(7, curses.COLOR_RED, curses.COLOR_BLACK)
        curses.init_pair(8, curses.COLOR_CYAN, curses.COLOR_BLACK)
项目:slacky    作者:mathiasbc    | 项目源码 | 文件源码
def set_color_pairs():
    # based on the colors of pyradio
    curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
    curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
    curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_BLACK)
    curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_MAGENTA)
    curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_GREEN)
    curses.init_pair(8, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
    curses.init_pair(9, curses.COLOR_BLACK, curses.COLOR_GREEN)
项目:reinforcement_learning    作者:andreweskeclarke    | 项目源码 | 文件源码
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)
项目:paint-it    作者:plainspooky    | 项目源码 | 文件源码
def __init__(self, arena_size):
        self.arena_size = arena_size
        self.max_moves = int(25*(2*arena_size*COLORS)/(28*6))
        self.screen = curses.initscr()
        curses.noecho()
        curses.cbreak()
        curses.start_color()
        try:
            curses.curs_set(False)
        except curses.error:
            pass
        self.screen.nodelay(True)
        self.window_size = self.screen.getmaxyx()

        if self.window_size[0] < self.arena_size+4 or self.window_size[1] < self.arena_size*2:
            print('Your screen is too short!')
            exit()

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

        self.offset_x = int((self.window_size[1]-2*self.arena_size)/2)
        self.offset_y = int((self.window_size[0]-self.arena_size)/2)
        self.moves_position=[ self.offset_y+self.arena_size+1, self.offset_x+self.arena_size-5 ]

        self.arena_initialize()

        self.screen.addstr( self.offset_y-2, self.offset_x, self.title, curses.color_pair(0))
        self.screen.addstr( self.offset_y-2, self.offset_x+2*self.arena_size-17, "Press '?' to help", curses.color_pair(0))
项目:pyfeld    作者:scjurgen    | 项目源码 | 文件源码
def __init__(self):
        self.notification_count = 0
        self.window = curses.initscr()
        curses.start_color()
        curses.noecho()
        curses.cbreak()
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
        curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_WHITE)
        curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLACK)
        curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_RED)
        curses.init_pair(5, curses.COLOR_YELLOW, curses.COLOR_BLUE)

        self.window.keypad(1)
        self.draw_ui()
项目:xcode_archive    作者:zhipengbird    | 项目源码 | 文件源码
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)
项目:sandsifter    作者:xoreaxeaxeax    | 项目源码 | 文件源码
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)

            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)
项目:led    作者:rec    | 项目源码 | 文件源码
def main(screen):
    screen.clear()
    screen_y, screen_x = screen.getmaxyx()
    screen.addstr(0, 0, str(screen.getmaxyx()))
    curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
    global DIR
    DIR = dir(screen)
    while True:
        c = screen.getch()
        screen.addstr(2, 2, str(c) + '   ', curses.color_pair(1) |
                      curses.A_BLINK | curses.A_BOLD)
        if c == 'q' or c == ord('q'):
            break
项目:led    作者:rec    | 项目源码 | 文件源码
def __init__(self,
                 foreground=curses.COLOR_BLACK, background=curses.COLOR_WHITE):
        self.index = Color.next_index()
        self.set(foreground, background)
项目:led    作者:rec    | 项目源码 | 文件源码
def main(screen):
    screen.clear()
    screen_y, screen_x = screen.getmaxyx()
    screen.move(1, 1)
    screen.addstr(str(screen.getmaxyx()))
    curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
    while True:
        c = screen.getch()
        screen.move(2, 2)
        # screen.addstr(str(c), curses.A_BLINK | curses.A_BOLD)
        # screen.addstr(str(c), curses.color_pair(1))
        screen.addstr(str(c), curses.color_pair(1) | curses.A_BLINK)
        if c == 'q' or c == ord('q'):
            break
项目:culour    作者:shohamp    | 项目源码 | 文件源码
def _color_str_to_color_pair(color):
    if color == TerminalColors.END:
        fg = curses.COLOR_WHITE
    else:
        fg = TERMINAL_COLOR_TO_CURSES[color]
    color_pair = _get_color(fg, curses.COLOR_BLACK)
    return color_pair
项目:isar    作者:ilbers    | 项目源码 | 文件源码
def __init__( self, x, y, width, height, fg=curses.COLOR_BLACK, bg=curses.COLOR_WHITE ):
            self.win = curses.newwin( height, width, y, x )
            self.dimensions = ( x, y, width, height )
            """
            if curses.has_colors():
                color = 1
                curses.init_pair( color, fg, bg )
                self.win.bkgdset( ord(' '), curses.color_pair(color) )
            else:
                self.win.bkgdset( ord(' '), curses.A_BOLD )
            """
            self.erase()
            self.setScrolling()
            self.win.noutrefresh()
项目:isar    作者:ilbers    | 项目源码 | 文件源码
def __init__( self, title, x, y, width, height, fg=curses.COLOR_BLACK, bg=curses.COLOR_WHITE ):
            NCursesUI.Window.__init__( self, x+1, y+3, width-2, height-4, fg, bg )
            self.decoration = NCursesUI.Window( x, y, width, height, fg, bg )
            self.decoration.setBoxed()
            self.decoration.win.hline( 2, 1, curses.ACS_HLINE, width-2 )
            self.setTitle( title )
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def strng1():
    treescrn2.attrset(curses.A_BOLD | curses.A_BLINK)
    set_color(treescrn2, curses.COLOR_WHITE)

    treescrn2.addch(3, 13, ord('\''))
    treescrn2.addch(3, 12, ord(':'))
    treescrn2.addch(3, 11, ord('.'))

    treescrn2.attroff(curses.A_BOLD | curses.A_BLINK)
    unset_color(treescrn2)

    treescrn2.refresh()
    w_del_msg.refresh()
    return
项目:Halite    作者:shummie    | 项目源码 | 文件源码
def setup_colors():
    """Setup the colors for each player. Entry 8 is reserved for
    zero-strength unowned squares.
    """
    curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_RED)
    curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_BLUE)
    curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_GREEN)
    curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_MAGENTA)
    curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_CYAN)
    curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_YELLOW)
    curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_BLACK)
项目:ascii_qgis    作者:NathanW2    | 项目源码 | 文件源码
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)
项目:solent    作者:solent-eng    | 项目源码 | 文件源码
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)
项目:youtube_watcher    作者:Sjc1000    | 项目源码 | 文件源码
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
项目:trtop    作者:aol    | 项目源码 | 文件源码
def _init_screen(self):
        screen = curses.initscr()
        curses.noecho()
        curses.cbreak()
        curses.start_color()
        curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
        screen.border(0)
        return screen
项目:YATE    作者:GarethNelson    | 项目源码 | 文件源码
def init_color_pairs(self):
       curses.init_pair(TOPSTATUS,TOPSTATUS_FG,TOPSTATUS_BG)
       curses.init_pair(TOPSTATUS_ONLINE,curses.COLOR_GREEN,TOPSTATUS_BG)
       curses.init_pair(TOPSTATUS_OFFLINE,curses.COLOR_RED,TOPSTATUS_BG)
       # create some color pairs for voxel types in a hacky way
       for item in dir(yateproto):
           if item.startswith('YATE_VOXEL_'):
              curses.init_pair(VOXEL_COLOR_PAIR + getattr(yateproto,item), curses.COLOR_WHITE,voxel_colors[getattr(yateproto,item)])
项目:pystocker    作者:coffeeandscripts    | 项目源码 | 文件源码
def input_n(cursor, scr_bottom, max_stock_range, stock_list, scr_dim):

    stock_input = None
    curses.start_color()
    curses.init_pair(5,curses.COLOR_WHITE,curses.COLOR_BLUE)
    stock_win = curses.newwin(1, 10, scr_dim[0]-1, 0)
    stock_win.bkgd(curses.color_pair(5))
    stock_box = textpad.Textbox(stock_win)
    stock_win.refresh()
    scr_bottom.addstr(0, curses.COLS-20, "   [Enter]Save/Exit")
    scr_bottom.refresh()
    stock_input = stock_box.edit()
    stock_input = stock_input.upper()

    if str(stock_input) != "" and str(stock_input) not in stock_list:
        stocks.add_stock_code(str(stock_input))
        total_stocks = len(stock_list) + 1
        if total_stocks > scr_dim[0] - 6:
            cursor[1] = total_stocks
            cursor[2] = max_stock_range
        else:
            cursor[1] = max_stock_range + 1
            cursor[2] = cursor[1]
    elif str(stock_input) or ((str(stock_input)[0:(len(str(stock_input)) - 2)] and str(stock_input)[len(str(stock_input))])) in stock_list:
        total_stocks = len(stock_list)
        stock_pos = stock_list.index(str(stock_input)) + 1
        cursor[1] = stock_pos
        if total_stocks > max_stock_range:
            cursor[2] = 1
        else:
            cursor[2] = cursor[1]

    return cursor
项目:HaliteBot    作者:jheilema-nerdery    | 项目源码 | 文件源码
def setup_colors():
    """Setup the colors for each player. Entry 8 is reserved for
    zero-strength unowned squares.
    """
    curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_RED)
    curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_BLUE)
    curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_GREEN)
    curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_MAGENTA)
    curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_CYAN)
    curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_YELLOW)
    curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_BLACK)
项目:Utils    作者:disconsis    | 项目源码 | 文件源码
def parse_args():
    parser = argparse.ArgumentParser()
    # parser.add_argument('-a', '--abs', action='store_true')
    parser.add_argument('abs_rel', choices=['at', 'after'])
    font_choices = [font.split('.')[0]
                    for font in os.listdir('/usr/share/figlet')
                    if font.split('.')[1] == 'tlf']
    parser.add_argument('-f', '--font', default=DEFAULT_FONT,
                        choices=font_choices)
    parser.add_argument('-m', '--msg', default=None)
    # parser.add_argument('-z', '--snooze', type=float, default=2)
    parser_volume = parser.add_mutually_exclusive_group()
    parser_song = parser_volume.add_argument_group()
    parser_song.add_argument('-d', '--dir', default=DEFAULT_MUSIC_DIR)
    parser_song.add_argument('--song', default=DEFAULT_SONG)
    parser_volume.add_argument('-ns', '--silent', action='store_true')
    parser.add_argument('-fg', choices=['black', 'red', 'green', 'yellow',
                                        'blue', 'magenta', 'cyan', 'white'],
                        default='white')
    parser.add_argument('-bg', choices=['black', 'red', 'green', 'yellow',
                                        'blue', 'magenta', 'cyan', 'white'],
                        default='black')
    parser.add_argument('time', nargs='+')
    args = parser.parse_args()
    args.abs = False if args.abs_rel == 'after' else True
    if not args.silent:
        args.song = validate_song(args)
    args.time = ' '.join(args.time)
    color_mapping = {
        'black': curses.COLOR_BLACK,
        'red': curses.COLOR_RED,
        'green': curses.COLOR_GREEN,
        'yellow': curses.COLOR_YELLOW,
        'blue': curses.COLOR_BLUE,
        'magenta': curses.COLOR_MAGENTA,
        'cyan': curses.COLOR_CYAN,
        'white': curses.COLOR_WHITE,
    }
    args.fg = color_mapping[args.fg]
    args.bg = color_mapping[args.bg]
    return args
项目:py_wsjtx    作者:teabreakninja    | 项目源码 | 文件源码
def setup_colours(self):
        curses.start_color()
        # 0 - NOT_WORKED
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_RED)
        # 1 - WORKED_COUNTRY_AND_STATION
        curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
        # 2 - WORKED_COUNTRY_NOT_STATION
        curses.init_pair(3, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
        # 3 - WORKED_COUNTRY_DIFF_BAND
        curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK)
项目:connect4    作者:guglielmilo    | 项目源码 | 文件源码
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)
项目:DarkWallet    作者:DissentDifference    | 项目源码 | 文件源码
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()
项目:foe-bot    作者:m3talstorm    | 项目源码 | 文件源码
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
项目:pick    作者:wong2    | 项目源码 | 文件源码
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)
项目:code    作者:ActiveState    | 项目源码 | 文件源码
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)
项目:new    作者:atlj    | 项目源码 | 文件源码
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
项目:sandsifter    作者:xoreaxeaxeax    | 项目源码 | 文件源码
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)
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
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
项目:treesel    作者:mcchae    | 项目源码 | 文件源码
def c_main(stdscr):
    cargo_cult_routine(stdscr)
    stdscr.nodelay(0)
    mydir = factory(start)
    mydir.expand()
    curidx = 3
    pending_action = None
    pending_save = False

    while True:
        stdscr.clear()
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
        line = 0
        offset = max(0, curidx - curses.LINES + 3)
        for data, depth in mydir.traverse():
            if line == curidx:
                stdscr.attrset(curses.color_pair(1) | curses.A_BOLD)
                if pending_action:
                    getattr(data, pending_action)()
                    pending_action = None
                elif pending_save:
                    global result
                    result = data.name
                    return
            else:
                stdscr.attrset(curses.color_pair(0))
            if 0 <= line - offset < curses.LINES - 1:
                stdscr.addstr(line - offset, 0,
                              data.render(depth, curses.COLS))
            line += 1
        stdscr.refresh()
        ch = stdscr.getch()
        if ch == curses.KEY_UP:
            curidx -= 1
        elif ch == curses.KEY_DOWN:
            curidx += 1
        elif ch == curses.KEY_PPAGE:
            curidx -= curses.LINES
            if curidx < 0: curidx = 0
        elif ch == curses.KEY_NPAGE:
            curidx += curses.LINES
            if curidx >= line: curidx = line - 1
        elif ch == curses.KEY_RIGHT:
            pending_action = 'expand'
        elif ch == curses.KEY_LEFT:
            pending_action = 'collapse'
        elif ch == ESC:
            return
        elif ch == ord('\n'):
            pending_save = True

        curidx %= line


################################################################################
项目:colorful2048    作者:liuyuxuan123    | 项目源码 | 文件源码
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)
项目:zmq-chat    作者:jnthnwn    | 项目源码 | 文件源码
def main(stdscr):
    config_file = args.config_file if args.config_file is not None else 'zmqchat.cfg'
    config = configparser.ConfigParser()
    config.read(config_file)
    config = config['default']

    receiver = zmq.Context().instance().socket(zmq.PAIR)
    receiver.bind("inproc://clientchat")
    sender = zmq.Context().instance().socket(zmq.PAIR)
    sender.connect("inproc://clientchat")
    client = ClientChat(args.username, config['server_host'],
                        config['chat_port'], receiver)
    client.run()

    display_receiver = zmq.Context().instance().socket(zmq.PAIR)
    display_receiver.bind("inproc://clientdisplay")
    display_sender = zmq.Context().instance().socket(zmq.PAIR)
    display_sender.connect("inproc://clientdisplay")
    display = ClientDisplay(config['server_host'], config['display_port'], display_sender)
    display.run()

    ### curses set up
    curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
    curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
    # ensure that user input is echoed to the screen
    curses.echo()
    curses.curs_set(0)

    window_height = curses.LINES
    window_width = curses.COLS
    division_line =  int(window_height * 0.8)

    # instaniate two pads - one for displaying received messages
    # and one for showing the message the user is about to send off
    top_pad = stdscr.subpad(division_line, window_width, 0, 0)
    bottom_pad = stdscr.subpad(window_height - division_line, window_width, division_line, 0)

    top_thread = threading.Thread(target=start_top_window, args=(top_pad, display_receiver))
    top_thread.daemon = True
    top_thread.start()

    bottom_thread = threading.Thread(target=start_bottom_window, args=(bottom_pad, sender))
    bottom_thread.daemon = True
    bottom_thread.start()

    top_thread.join()
    bottom_thread.join()