Python curses.can_change_color() Examples

The following are 12 code examples of curses.can_change_color(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module curses , or try the search function .
Example #1
Source File: sifter.py    From sandsifter with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def gray(self, scale):
        if curses.can_change_color():
            return curses.color_pair(self.GRAY_BASE + int(round(scale * (self.GRAYS - 1))))
        else:
            return curses.color_pair(self.WHITE) 
Example #2
Source File: gui.py    From sandsifter with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #3
Source File: gui.py    From sandsifter with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def gray(self, scale):
        if curses.can_change_color():
            return curses.color_pair(self.GRAY_BASE + int(round(scale * (self.GRAYS - 1))))
        else:
            return curses.color_pair(self.WHITE) 
Example #4
Source File: npysThemeManagers.py    From apple_bleee with GNU General Public License v3.0 5 votes vote down vote up
def define_colour_numbers(self):
        if curses.can_change_color():
            for c in self._color_values:
                curses.init_color(c[0], *c[1]) 
Example #5
Source File: npysThemeManagers.py    From HomePWN with GNU General Public License v3.0 5 votes vote down vote up
def define_colour_numbers(self):
        if curses.can_change_color():
            for c in self._color_values:
                curses.init_color(c[0], *c[1]) 
Example #6
Source File: npysThemeManagers.py    From EDCOP with Apache License 2.0 5 votes vote down vote up
def define_colour_numbers(self):
        if curses.can_change_color():
            for c in self._color_values:
                curses.init_color(c[0], *c[1]) 
Example #7
Source File: color_manager.py    From babi with MIT License 5 votes vote down vote up
def init_color(self, color: Color) -> None:
        if curses.can_change_color():
            n = min(self.colors.values(), default=256) - 1
            self.colors[color] = n
            curses.init_color(n, *_color_to_curses(color))
        elif curses.COLORS >= 256:
            self.colors[color] = color_kd.nearest(color, color_kd.make_256())
        else:
            self.colors[color] = -1 
Example #8
Source File: worldmap.py    From EasY_HaCk with Apache License 2.0 5 votes vote down vote up
def __init__(self, map_name='world', map_conf=None, window=None, encoding=None):
        if map_conf is None:
            map_conf = MAPS[map_name]
        self.map = map_conf['data']
        self.coords = map_conf['coords']
        self.corners = map_conf['corners']
        if window is None:
            window = curses.newwin(0, 0)
        self.window = window

        self.data = []
        self.data_timestamp = None

        # JSON contents _should_ be UTF8 (so, python internal unicode here...)
        if encoding is None:
            encoding = locale.getpreferredencoding()
        self.encoding = encoding

        # check if we can use transparent background or not
        if curses.can_change_color():
            curses.use_default_colors()
            background = -1
        else:
            background = curses.COLOR_BLACK

        tmp_colors = [
            ('red', curses.COLOR_RED, background),
            ('blue', curses.COLOR_BLUE, background),
            ('pink', curses.COLOR_MAGENTA, background)
        ]

        self.colors = {}
        if curses.has_colors():
            for i, (name, fgcolor, bgcolor) in enumerate(tmp_colors, 1):
                curses.init_pair(i, fgcolor, bgcolor)
                self.colors[name] = i 
Example #9
Source File: npysThemeManagers.py    From TelegramTUI with MIT License 5 votes vote down vote up
def define_colour_numbers(self):
        if curses.can_change_color():
            for c in self._color_values:
                curses.init_color(c[0], *c[1]) 
Example #10
Source File: sifter.py    From sandsifter with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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) 
Example #11
Source File: debug_window.py    From ci_edit with Apache License 2.0 4 votes vote down vote up
def debugDraw(self, program, win):
        """Draw real-time debug information to the screen."""
        textBuffer = win.textBuffer
        self.writeLineRow = 0
        intent = u"noIntent"
        if hasattr(win, u"userIntent"):
            intent = win.userIntent
        color = program.color.get(u'debug_window')
        self.writeLine(
            u"   cRow %3d    cCol %2d goalCol %2d  %s" %
            (win.textBuffer.penRow, win.textBuffer.penCol,
             win.textBuffer.goalCol, intent), color)
        self.writeLine(
            u"   pRow %3d    pCol %2d chRow %4d" %
            (textBuffer.penRow, textBuffer.penCol,
             textBuffer.debugUpperChangedRow), color)
        self.writeLine(
            u" mkrRow %3d  mkrCol %2d sm %d" %
            (textBuffer.markerRow, textBuffer.markerCol,
             textBuffer.selectionMode), color)
        self.writeLine(
            u"scrlRow %3d scrlCol %2d lines %3d" %
            (win.scrollRow, win.scrollCol, textBuffer.parser.rowCount()), color)
        y, x = win.top, win.left
        maxRow, maxCol = win.rows, win.cols
        self.writeLine(
            u"y %2d x %2d maxRow %d maxCol %d baud %d color %d" %
            (y, x, maxRow, maxCol, curses.baudrate(),
             curses.can_change_color()), color)
        screenRows, screenCols = program.cursesScreen.getmaxyx()
        self.writeLine(
            u"scr rows %d cols %d mlt %f/%f pt %f" %
            (screenRows, screenCols, program.mainLoopTime,
             program.mainLoopTimePeak, textBuffer.parserTime), color)
        self.writeLine(
            u"ch %3s %s" % (program.ch, app.curses_util.cursesKeyName(
                program.ch) or u'UNKNOWN'), color)
        self.writeLine(u"win %r" % (win,), color)
        self.writeLine(u"foc %r" % (program.programWindow.focusedWindow,),
                       color)
        self.writeLine(u"tb %r" % (textBuffer,), color)
        (id, mouseCol, mouseRow, mouseZ, bState) = program.debugMouseEvent
        self.writeLine(
            u"mouse id %d, mouseCol %d, mouseRow %d, mouseZ %d" %
            (id, mouseCol, mouseRow, mouseZ), color)
        self.writeLine(
            u"bState %s %d" % (app.curses_util.mouseButtonName(bState), bState),
            color)
        self.writeLine(u"startAndEnd %r" % (textBuffer.startAndEnd(),), color) 
Example #12
Source File: ci_program.py    From ci_edit with Apache License 2.0 4 votes vote down vote up
def setUpCurses(self, cursesScreen):
        self.cursesScreen = cursesScreen
        curses.mousemask(-1)
        curses.mouseinterval(0)
        # Enable mouse tracking in xterm.
        sys.stdout.write('\033[?1002;h')
        #sys.stdout.write('\033[?1005;h')
        curses.meta(1)
        # Access ^c before shell does.
        curses.raw()
        # Enable Bracketed Paste Mode.
        sys.stdout.write('\033[?2004;h')
        # Push the escape codes out to the terminal. (Whether this is needed
        # seems to vary by platform).
        sys.stdout.flush()
        try:
            curses.start_color()
            if not curses.has_colors():
                userMessage("This terminal does not support color.")
                self.quitNow()
            else:
                curses.use_default_colors()
        except curses.error as e:
            app.log.error(e)
        app.log.startup(u"curses.COLORS", curses.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))
        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)
            app.window.mainCursesWindow = cursesWindow