Python curses 模块,init_pair() 实例源码

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

项目:HTP    作者:nklose    | 项目源码 | 文件源码
def __init__(self, file):
        self.file = file
        self.scr = curses.initscr()
        self.scr.border()
        self.scr_height, self.scr_width = self.scr.getmaxyx()
        self.text_win = curses.newwin(self.scr_height - 1, self.scr_width, 1, 0)
        self.file_text = file.content
        if self.file_text != None:
            self.text_win.addstr(self.file_text)
        curses.noecho()
        #curses.start_color()
        #curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN)

        if self.file.exists:
            self.start_editor()
        else:
            curses.endwin()
            gc.error('An error occurred while editing this file.')
项目:HTP    作者:nklose    | 项目源码 | 文件源码
def __init__(self, username):
        os.environ.setdefault('ESCDELAY', '25') # shorten esc delay
        self.username = username

        # set up IRC
        self.channel = "##HTP"

        # set up curses
        self.scr = curses.initscr()
        self.disconnect = False
        curses.start_color()
        self.scr_height, self.scr_width = self.scr.getmaxyx()
        self.chatbar = curses.newwin(5, self.scr_height - 1, 5, 10)
        self.msg_text = ''
        self.logfile = '../data/irc.txt'
        self.log_text = []

        # curses color config
        curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN)

        # start the client
        try:
            curses.wrapper(self.start_loop())
        except Exception as e:
            self.scr.addstr(2, 0, str(e), curses.A_REVERSE)

    # client game loop
项目:defuse_division    作者:lelandbatey    | 项目源码 | 文件源码
def colors_init():
    """
    Initializes all color pairs possible into the dictionary CURSES_COLORPAIRS.
    Thus, getting an attribute for a black foreground and a green background
    would look like:
        >>> curses_color.colors_init()
        >>> green_black_attr = curses_color.CURSES_COLORPAIRS['black-green']
        >>> stdscr.addstr(0, 0, "test", curses.color_pair(green_black_attr))
    """
    if len(CURSES_COLORPAIRS): return
    assert curses.has_colors(
    ), "Curses wasn't configured to support colors. Call curses.start_color()"
    start_number = 120
    for fg in BASE_CURSES_COLORS.keys():
        for bg in BASE_CURSES_COLORS.keys():
            pair_num = len(CURSES_COLORPAIRS) + start_number
            curses.init_pair(pair_num, BASE_CURSES_COLORS[fg],
                             BASE_CURSES_COLORS[bg])
            pair_name = "{}-{}".format(fg, bg)
            CURSES_COLORPAIRS[pair_name] = pair_num
项目: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()
项目:captiv8    作者:wraith-wireless    | 项目源码 | 文件源码
def initcolors():
    """ initialize color pallet """
    curses.start_color()
    if not curses.has_colors():
        raise RuntimeError("Sorry. Terminal does not support colors")

    # setup colors on black background
    for i in range(1,9):
        curses.init_pair(i,i,BLACK)
        CPS[i] = curses.color_pair(i)

    # have to individually set up special cases
    curses.init_pair(BUTTON,WHITE,GRAY)     # white on gray for buttons
    CPS[BUTTON] = curses.color_pair(BUTTON)
    curses.init_pair(HLITE,BLACK,GREEN)     # black on Green for highlight aps,stas
    CPS[HLITE] = curses.color_pair(HLITE)
    curses.init_pair(ERR,WHITE,RED)         # white on red
    CPS[ERR] = curses.color_pair(ERR)
    curses.init_pair(WARN,BLACK,YELLOW)     # white on yellow
    CPS[WARN] = curses.color_pair(WARN)
    curses.init_pair(NOTE,WHITE,GREEN)      # white on red
    CPS[NOTE] = curses.color_pair(NOTE)
项目: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()
项目:Qaf    作者:jonathanabennett    | 项目源码 | 文件源码
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()
项目:Qaf    作者:jonathanabennett    | 项目源码 | 文件源码
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
项目:melomaniac    作者:sdispater    | 项目源码 | 文件源码
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)
项目:cursebox    作者:Tenchi2xh    | 项目源码 | 文件源码
def __getitem__(self, pair):
        fg, bg = pair
        assert isinstance(fg, int) and -1 <= fg < 256
        assert isinstance(bg, int) and -1 <= bg < 256

        if pair in self.pair_numbers:
            # If pair is stored, retrieve it.
            return curses.color_pair(self.pair_numbers[pair])
        elif self.counter < MAX_PAIRS:
            # If we still haven't filled our queue, add the new pair.
            curses.init_pair(self.counter, fg, bg)
            self.pair_numbers[pair] = self.counter
            self.counter += 1
            return curses.color_pair(self.counter - 1)
        else:
            # If the queue is full, pop the oldest one out
            # and use its pair number to create the new one.
            _, oldest = self.pair_numbers.popitem(last=False)
            curses.init_pair(oldest, fg, bg)
            self.pair_numbers[pair] = oldest
            return curses.color_pair(oldest)
项目:gdax-trader    作者:mcardillo55    | 项目源码 | 文件源码
def __init__(self, enable=True):
        self.enable = enable
        if not self.enable:
            return
        self.logger = logging.getLogger('trader-logger')
        self.stdscr = curses.initscr()
        self.pad = curses.newpad(23, 120)
        self.order_pad = curses.newpad(10, 120)
        self.timestamp = ""
        self.last_order_update = 0
        curses.start_color()
        curses.noecho()
        curses.cbreak()
        curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN)
        curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_RED)
        self.stdscr.keypad(1)
        self.pad.addstr(1, 0, "Waiting for a trade...")
项目:logviewer    作者:romuloceccon    | 项目源码 | 文件源码
def __init__(self, curses, curses_window):
        curses.start_color()

        curses.curs_set(0)
        curses_window.nodelay(1)

        curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_MAGENTA, 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_CYAN, curses.COLOR_BLACK)
        curses.init_pair(6, curses.COLOR_BLUE, curses.COLOR_BLACK)

        self._curses = curses
        self._curses_window = curses_window

        self._stack = list()
项目: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()
项目:Utils    作者:disconsis    | 项目源码 | 文件源码
def countdown(stdscr, end_time, font, fg_color, bg_color, msg=None):
    stdscr.clear()
    curses.curs_set(False)
    curses.init_pair(1, fg_color, bg_color)

    now = datetime.datetime.now()
    timefmt = '%I:%M %p' if now.day == end_time.day else '%I:%M %p, %d %b'
    stdscr.addstr(0, 0, 'Alarm set for: ' + end_time.strftime(timefmt))
    stdscr.refresh()

    win = None
    while now < end_time:
        time_left = str(end_time - now).split('.')[0]
        win = center(stdscr, time_left, font, curses.color_pair(1), win)
        sleep(1)
        now = datetime.datetime.now()

    alert(stdscr, args, win)
项目:webnuke    作者:bugbound    | 项目源码 | 文件源码
def get_screen(self):
        self.screen = 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)

        if self.x == 0:
            starty, startx = self.screen.getmaxyx()
            self.x = startx
            self.y = starty

        resize = curses.is_term_resized(self.y, self.x)

        # Action in loop if resize is True:
        if resize is True:
            y, x = self.screen.getmaxyx()
            self.screen.clear()
            curses.resizeterm(self.y, self.x)
            self.screen.refresh()


        self.show_header()

        return self.screen
项目: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)
项目:awesome-finder    作者:mingrammer    | 项目源码 | 文件源码
def init_curses(self):
        """Setup the curses"""
        self.window = curses.initscr()
        self.window.keypad(True)

        curses.noecho()
        curses.cbreak()

        curses.start_color()
        curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_CYAN)

        self.current = curses.color_pair(2)
项目:cryptop    作者:huwwp    | 项目源码 | 文件源码
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)
项目: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 set(self, foreground=None, background=None):
        self.foreground = foreground or self.foreground
        self.background = background or self.background
        curses.init_pair(self.index, self.foreground, self.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 _get_color(fg, bg):
    key = (fg, bg)
    if key not in COLOR_PAIRS_CACHE:
        # Use the pairs from 101 and after, so there's less chance they'll be overwritten by the user
        pair_num = len(COLOR_PAIRS_CACHE) + 101
        curses.init_pair(pair_num, fg, bg)
        COLOR_PAIRS_CACHE[key] = pair_num

    return COLOR_PAIRS_CACHE[key]
项目:huhamhire-hosts    作者:jiangsile    | 项目源码 | 文件源码
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)
项目: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()
项目:AsciiDots-Java    作者:LousyLynx    | 项目源码 | 文件源码
def __init__(self, ticks, silent, debug, compat_debug, debug_lines, autostep_debug, head):
        super().__init__()

        self.ticks = ticks
        self.silent = silent
        self.debug = debug
        self.compat_debug = compat_debug
        self.debug_lines = debug_lines
        self.autostep_debug = autostep_debug
        self.head = head

        self.tick_number = 0

        self.output_count = 0

        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()

            curses.curs_set(False)

            self.win_program = curses.newwin(self.debug_lines, curses.COLS - 1, 0, 0)

            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)
项目:nanosat-control    作者:ceyzeriat    | 项目源码 | 文件源码
def _init_colors(self):
        for i in range(curses.COLORS):
            curses.init_pair(i + 1, i, -1)
        for i in range(curses.COLORS):
            curses.init_pair(i + curses.COLORS, i, 0)
        self.WHITE = curses.color_pair(0)
        self.BLACK = curses.color_pair(1)
        self.RED = curses.color_pair(2)
        self.GREEN = curses.color_pair(3)
        self.YELLOW = curses.color_pair(4)
        self.BLUE = curses.color_pair(5)
        self.PURPLE = curses.color_pair(6)
        self.CYAN = curses.color_pair(7)
        self.NOSTARTED = self.BLUE
        self.ALIVE = self.GREEN
        self.DEAD = self.RED
        self.NONE = self.BLUE
        self.OK = self.GREEN
        self.ERROR = self.RED
        self.WAIT = self.YELLOW
        curses.init_pair(8, 7, 0)
        self.WHITE_BG = curses.color_pair(8)
        self.RED_BG = curses.color_pair(9)
        self.GREEN_BG = curses.color_pair(10)
        self.YELLOW_BG = curses.color_pair(11)
        self.BLUE_BG = curses.color_pair(12)
        self.PURPLE_BG = curses.color_pair(13)
        self.CYAN_BG = curses.color_pair(14)
项目:WxNeteaseMusic    作者:yaphone    | 项目源码 | 文件源码
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
项目:sciibo    作者:fdev    | 项目源码 | 文件源码
def create_color(foreground, background, attrs=0):
    """Create a new color pair."""
    try:
        create_color.index += 1
    except:
        create_color.index = 1
    curses.init_pair(create_color.index, foreground, background)
    return curses.color_pair(create_color.index) | attrs


# Character attributes
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def set_color(win, color):
    if curses.has_colors():
        n = color + 1
        curses.init_pair(n, color, my_bg)
        win.attroff(curses.A_COLOR)
        win.attron(curses.color_pair(n))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def mkpanel(color, rows, cols, tly, tlx):
    win = curses.newwin(rows, cols, tly, tlx)
    pan = panel.new_panel(win)
    if curses.has_colors():
        if color == curses.COLOR_BLUE:
            fg = curses.COLOR_WHITE
        else:
            fg = curses.COLOR_BLACK
        bg = color
        curses.init_pair(color, fg, bg)
        win.bkgdset(ord(' '), curses.color_pair(color))
    else:
        win.bkgdset(ord(' '), curses.A_BOLD)

    return pan
项目: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)
项目:Music-Scraper    作者:srivatsan-ramesh    | 项目源码 | 文件源码
def init_display():
        """
        Inits the display GUI
        """
        if not GUI.gui_stopped:
            curses.noecho()
            curses.cbreak()
            curses.start_color()
            GUI.screen.keypad(1)
            curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN)
            GUI.high_light_text = curses.color_pair(1)
            GUI.normal_text = curses.A_NORMAL
            curses.curs_set(0)
            GUI.refresh_values()
            GUI.position = 1
            GUI.page = 1
            GUI.box = curses.newwin(GUI.max_row + 3, curses.COLS, 0, 0)
            GUI.box.addstr(1, 1, GUI.status, GUI.high_light_text)
            GUI.add_bottom_menus()
            GUI.screen.refresh()
            GUI.box.refresh()
项目: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
项目:RasWxNeteaseMusic    作者:yaphone    | 项目源码 | 文件源码
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
项目: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__(self,scr):
       self.scr = scr
       curses.curs_set(0)
       self.init_color_pairs()
       curses.init_pair(TOPSTATUS,TOPSTATUS_FG,TOPSTATUS_BG)
       self.scr.nodelay(1)
       self.running   = False
       self.y,self.x = self.scr.getbegyx()
       self.h,self.w = self.scr.getmaxyx()
       self.av_pos = (0,0,0)

       self.init_log()
       self.init_voxel_display()
       self.percept_delay = 0

       self.cmdfuncs = {'help':self.helpfunc}

       self.disp_func = self.log_display
       self.client    = yateclient.YATEClient(voxel_update_cb=self.voxel_update_cb,avatar_pos_cb=self.avatar_pos_cb)
       self.running = True
       yatelog.info('yate_console','Starting up')
       self.draw_scr()
       self.pool = eventlet.GreenPool(100)
       self.pool.spawn(self.main_ui_loop)
       while self.running: eventlet.greenthread.sleep(1)
       curses.curs_set(1)
项目: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 print_stock_data(col, row, data, title, scr_main, scr_strip, cursor_row, change_amount, scr_dim):

    scr_strip.addstr(0, col+10, title)

    data_length = len(str(data))
    spaces_length = 9 - data_length
    n = 0

    if col+10+18 > scr_dim[1]:
        spaces_length = spaces_length + scr_dim[1] - col-10-9

    while n < spaces_length:
        data = data + " "
        n = n + 1
    curses.start_color()
    curses.init_pair(8, curses.COLOR_BLACK, curses.COLOR_RED)
    curses.init_pair(9, curses.COLOR_BLACK, curses.COLOR_GREEN)
    curses.init_pair(10, curses.COLOR_BLACK, curses.COLOR_YELLOW)
    curses.init_pair(11, curses.COLOR_RED, curses.COLOR_BLACK)
    curses.init_pair(12, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(13, curses.COLOR_YELLOW, curses.COLOR_BLACK)
    if cursor_row == 1:
        if change_amount == -1:
            scr_main.addstr(row, col, data, curses.color_pair(8))
        elif change_amount == 1:
            scr_main.addstr(row, col, data, curses.color_pair(9))
        else:
            scr_main.addstr(row, col, data, curses.color_pair(10))
    else:
        if change_amount == -1:
            scr_main.addstr(row, col, data, curses.color_pair(11))
        elif change_amount == 1:
            scr_main.addstr(row, col, data, curses.color_pair(12))
        else:
            scr_main.addstr(row, col, data, curses.color_pair(13))
项目: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
项目:pystocker    作者:coffeeandscripts    | 项目源码 | 文件源码
def print_permanents(scr_top, perm, row, col, perm_data, scr_dim):

    if perm == "GC=F":
        perm = "Gold"
    elif perm == "SI=F":
        perm = "Silver"
    elif perm == "HG=F":
        perm = "Copper"
    elif perm == "CL=F":
        perm = "Crude"
    elif perm[-2:] == "=X":
        perm = perm[0:3] + "/" + perm[3:6]
    elif perm[0] == "^":
        perm = perm[1:]

    curses.start_color()

    curses.init_pair(20, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(21, curses.COLOR_YELLOW, curses.COLOR_BLACK)
    curses.init_pair(22, curses.COLOR_RED, curses.COLOR_BLACK)

    try:
        printing_perm = str(perm) + "=" + str(perm_data["price"])
    except:
        printing_perm = str(perm) + "=N/A"

    perm_length = len(printing_perm) + 1

    if perm_length+col < scr_dim[1]:
        if perm_data["change"] != "N/A":
            if float(perm_data["change"]) >= 0.5:
                scr_top.addstr(1+row, col, str(printing_perm), curses.color_pair(20))
            if float(perm_data["change"]) <= -0.5:
                scr_top.addstr(1+row, col, str(printing_perm), curses.color_pair(22))
            else:
                scr_top.addstr(1+row, col, str(printing_perm), curses.color_pair(21))
        else:
            scr_top.addstr(1+row, col, str(printing_perm))

    return perm_length