Python curses 模块,COLORS 实例源码

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

项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr

# This is a similar wrapper for start_color(), which adds the COLORS and
# COLOR_PAIRS variables which are only available after start_color() is
# called.
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def start_color():
    import _curses, curses
    retval = _curses.start_color()
    if hasattr(_curses, 'COLORS'):
        curses.COLORS = _curses.COLORS
    if hasattr(_curses, 'COLOR_PAIRS'):
        curses.COLOR_PAIRS = _curses.COLOR_PAIRS
    return retval

# Import Python has_key() implementation if _curses doesn't contain has_key()
项目: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()
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr

# This is a similar wrapper for start_color(), which adds the COLORS and
# COLOR_PAIRS variables which are only available after start_color() is
# called.
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def start_color():
    import _curses, curses
    retval = _curses.start_color()
    if hasattr(_curses, 'COLORS'):
        curses.COLORS = _curses.COLORS
    if hasattr(_curses, 'COLOR_PAIRS'):
        curses.COLOR_PAIRS = _curses.COLOR_PAIRS
    return retval

# Import Python has_key() implementation if _curses doesn't contain has_key()
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr

# This is a similar wrapper for start_color(), which adds the COLORS and
# COLOR_PAIRS variables which are only available after start_color() is
# called.
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr

# This is a similar wrapper for start_color(), which adds the COLORS and
# COLOR_PAIRS variables which are only available after start_color() is
# called.
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr

# This is a similar wrapper for start_color(), which adds the COLORS and
# COLOR_PAIRS variables which are only available after start_color() is
# called.
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr

# This is a similar wrapper for start_color(), which adds the COLORS and
# COLOR_PAIRS variables which are only available after start_color() is
# called.
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr

# This is a similar wrapper for start_color(), which adds the COLORS and
# COLOR_PAIRS variables which are only available after start_color() is
# called.
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr

# This is a similar wrapper for start_color(), which adds the COLORS and
# COLOR_PAIRS variables which are only available after start_color() is
# called.
项目: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)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def start_color():
    import _curses, curses
    retval = _curses.start_color()
    if hasattr(_curses, 'COLORS'):
        curses.COLORS = _curses.COLORS
    if hasattr(_curses, 'COLOR_PAIRS'):
        curses.COLOR_PAIRS = _curses.COLOR_PAIRS
    return retval

# Import Python has_key() implementation if _curses doesn't contain has_key()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def start_color():
    import _curses, curses
    retval = _curses.start_color()
    if hasattr(_curses, 'COLORS'):
        curses.COLORS = _curses.COLORS
    if hasattr(_curses, 'COLOR_PAIRS'):
        curses.COLOR_PAIRS = _curses.COLOR_PAIRS
    return retval

# Import Python has_key() implementation if _curses doesn't contain has_key()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def start_color():
    import _curses, curses
    retval = _curses.start_color()
    if hasattr(_curses, 'COLORS'):
        curses.COLORS = _curses.COLORS
    if hasattr(_curses, 'COLOR_PAIRS'):
        curses.COLOR_PAIRS = _curses.COLOR_PAIRS
    return retval

# Import Python has_key() implementation if _curses doesn't contain has_key()
项目:ascii_qgis    作者:NathanW2    | 项目源码 | 文件源码
def assign_layer_colors():
    """
    Assign all the colors for each layer up front so we can use
    it though the application.
    """
    import itertools
    colors = itertools.cycle(range(11, curses.COLORS - 10))
    layercolormapping.clear()
    root = QgsProject.instance().layerTreeRoot()
    layers = [node.layer() for node in root.findLayers()]
    for layer in reversed(layers):
        if not layer.type() == QgsMapLayer.VectorLayer:
            continue
        layercolormapping[layer.id()] = colors.next()
项目: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)
项目:ascii_qgis    作者:NathanW2    | 项目源码 | 文件源码
def main(screen):
    """
    Main entry point
    :param screen:
    :return:
    """
    logging.info("Supports color: {}".format(curses.can_change_color()))
    logging.info("Colors: {}".format(curses.COLORS))
    logging.info("Color Pairs: {}".format(curses.COLOR_PAIRS))
    logging.info("Loading config")
    with open("ascii_qgis.config") as f:
        global config
        config = json.load(f)


    init_colors()

    screen.refresh()

    global scr, pad, aboutwindow, legendwindow, mapwindow, modeline
    scr = screen
    pad = EditPad()
    modeline = ModeLine()
    mapwindow = Map()
    legendwindow = Legend()
    aboutwindow = AboutWindow()

    legendwindow.render_legend()
    mapwindow.render_map()

    screen.addstr(0, 0, "ASCII")
    screen.addstr(0, 5, " QGIS Enterprise", curses.color_pair(4))
    screen.refresh()

    if config.get('showhelp', True):
        show_help()

    pad.focus()
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def start_color():
    import _curses, curses
    retval = _curses.start_color()
    if hasattr(_curses, 'COLORS'):
        curses.COLORS = _curses.COLORS
    if hasattr(_curses, 'COLOR_PAIRS'):
        curses.COLOR_PAIRS = _curses.COLOR_PAIRS
    return retval

# Import Python has_key() implementation if _curses doesn't contain has_key()
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def start_color():
    import _curses, curses
    retval = _curses.start_color()
    if hasattr(_curses, 'COLORS'):
        curses.COLORS = _curses.COLORS
    if hasattr(_curses, 'COLOR_PAIRS'):
        curses.COLOR_PAIRS = _curses.COLOR_PAIRS
    return retval

# Import Python has_key() implementation if _curses doesn't contain has_key()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def _start(self):
        """
        Initialize the screen and input mode.
        """
        self.s = curses.initscr()
        self.has_color = curses.has_colors()
        if self.has_color:
            curses.start_color()
            if curses.COLORS < 8:
                # not colourful enough
                self.has_color = False
        if self.has_color:
            try:
                curses.use_default_colors()
                self.has_default_colors=True
            except _curses.error:
                self.has_default_colors=False
        self._setup_colour_pairs()
        curses.noecho()
        curses.meta(1)
        curses.halfdelay(10) # use set_input_timeouts to adjust
        self.s.keypad(0)

        if not self._signal_keys_set:
            self._old_signal_keys = self.tty_signal_keys()

        super(Screen, self)._start()
项目:ci_edit    作者:google    | 项目源码 | 文件源码
def setUpPalette(self):
    def applyPalette(name):
      palette = app.prefs.palette[name]
      foreground = palette['foregroundIndexes']
      background = palette['backgroundIndexes']
      for i in range(1, curses.COLORS):
        curses.init_pair(i, foreground[i], background[i])
    def twoTries(primary, fallback):
      try:
        applyPalette(primary)
      except:
        try:
          applyPalette(fallback)
        except:
          pass
    if curses.COLORS == 8:
      app.prefs.prefs['color'] = app.prefs.color8
      app.prefs.color = app.prefs.color8
      app.color.colors = 8
      twoTries(app.prefs.editor['palette8'], 'default8')
    elif curses.COLORS == 256:
      app.prefs.prefs['color'] = app.prefs.color256
      app.prefs.color = app.prefs.color256
      app.color.colors = 256
      twoTries(app.prefs.editor['palette'], 'default')
    else:
      raise Exception('unknown palette color count ' + repr(curses.COLORS))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def start_color():
    import _curses, curses
    retval = _curses.start_color()
    if hasattr(_curses, 'COLORS'):
        curses.COLORS = _curses.COLORS
    if hasattr(_curses, 'COLOR_PAIRS'):
        curses.COLOR_PAIRS = _curses.COLOR_PAIRS
    return retval

# Import Python has_key() implementation if _curses doesn't contain has_key()
项目:tscrnsvr    作者:illinoisjackson    | 项目源码 | 文件源码
def __init__(self,win):
        self.win    = win
        self.size   = self.win.getmaxyx()
        curses.start_color()
        curses.use_default_colors()
        self.win.nodelay(1)
        for i in range(0, curses.COLORS):
            curses.init_pair(i + 1, i, -1)
        curses.curs_set(0)
项目:tscrnsvr    作者:illinoisjackson    | 项目源码 | 文件源码
def colortest(stdscr):
    # http://stackoverflow.com/questions/18551558/how-to-use-terminal-color-palette-with-curses
    curses.start_color()
    curses.use_default_colors()
    stdscr.addstr(0,0,"%s colors on \"%s\"\n" % (str(curses.COLORS),str(curses.termname().decode('ascii'))))
    for i in range(0, curses.COLORS):
        curses.init_pair(i + 1, i, -1)
    for i in range(curses.COLORS):
        try:
            stdscr.addstr(str(i)+"\t",curses.color_pair(i))
        except:
            pass
    try:
        stdscr.getch()
    except: pass
项目:ci_edit    作者:google    | 项目源码 | 文件源码
def __init__(self, cursesScreen):
    self.clicks = 0
    self.debugMouseEvent = (0, 0, 0, 0, 0)
    self.exiting = False
    self.modalUi = None
    self.modeStack = []
    self.priorClick = 0
    self.savedMouseButton1Down = False
    self.savedMouseWindow = None
    self.savedMouseX = -1
    self.savedMouseY = -1
    self.cursesScreen = cursesScreen
    self.ch = 0
    curses.mousemask(-1)
    curses.mouseinterval(0)
    # Enable mouse tracking in xterm.
    sys.stdout.write('\033[?1002;h\n')
    #sys.stdout.write('\033[?1005;h\n')
    curses.meta(1)
    # Access ^c before shell does.
    curses.raw()
    # Enable Bracketed Paste Mode.
    sys.stdout.write('\033[?2004;h\n')
    #curses.start_color()
    curses.use_default_colors()
    if 0:
      assert(curses.COLORS == 256)
      assert(curses.can_change_color() == 1)
      assert(curses.has_colors() == 1)
      app.log.detail("color_content:")
      for i in range(0, curses.COLORS):
        app.log.detail("color", i, ": ", curses.color_content(i))
      for i in range(16, curses.COLORS):
        curses.init_color(i, 500, 500, i * 787 % 1000)
      app.log.detail("color_content, after:")
      for i in range(0, curses.COLORS):
        app.log.detail("color", i, ": ", curses.color_content(i))
    self.setUpPalette()
    if 1:
      #rows, cols = self.cursesScreen.getmaxyx()
      cursesWindow = self.cursesScreen
      cursesWindow.leaveok(1)  # Don't update cursor position.
      cursesWindow.scrollok(0)
      cursesWindow.timeout(10)
      cursesWindow.keypad(1)
      self.top, self.left = cursesWindow.getyx()
      self.rows, self.cols = cursesWindow.getmaxyx()
      app.window.mainCursesWindow = cursesWindow
    self.zOrder = []