Python curses.COLOR_BLUE Examples

The following are 19 code examples of curses.COLOR_BLUE(). 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: app.py    From toot with GNU General Public License v3.0 6 votes vote down vote up
def setup_palette(class_):
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
        curses.init_pair(3, curses.COLOR_GREEN, 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_CYAN, curses.COLOR_BLACK)
        curses.init_pair(7, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
        curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_BLUE)
        curses.init_pair(9, curses.COLOR_WHITE, curses.COLOR_RED)

        class_.WHITE = curses.color_pair(1)
        class_.BLUE = curses.color_pair(2)
        class_.GREEN = curses.color_pair(3)
        class_.YELLOW = curses.color_pair(4)
        class_.RED = curses.color_pair(5)
        class_.CYAN = curses.color_pair(6)
        class_.MAGENTA = curses.color_pair(7)
        class_.WHITE_ON_BLUE = curses.color_pair(8)
        class_.WHITE_ON_RED = curses.color_pair(9)

        class_.HASHTAG = class_.BLUE | curses.A_BOLD 
Example #2
Source File: __init__.py    From py_cui with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _initialize_colors(self):
        """Function for initialzing curses colors. Called when CUI is first created.
        """

        # Start colors in curses
        curses.start_color()
        curses.init_pair(WHITE_ON_BLACK,    curses.COLOR_WHITE,     curses.COLOR_BLACK)
        curses.init_pair(BLACK_ON_GREEN,    curses.COLOR_BLACK,     curses.COLOR_GREEN)
        curses.init_pair(BLACK_ON_WHITE,    curses.COLOR_BLACK,     curses.COLOR_WHITE)
        curses.init_pair(WHITE_ON_RED,      curses.COLOR_WHITE,     curses.COLOR_RED)
        curses.init_pair(YELLOW_ON_BLACK,   curses.COLOR_YELLOW,    curses.COLOR_BLACK)
        curses.init_pair(RED_ON_BLACK,      curses.COLOR_RED,       curses.COLOR_BLACK)
        curses.init_pair(CYAN_ON_BLACK,     curses.COLOR_CYAN,      curses.COLOR_BLACK)
        curses.init_pair(MAGENTA_ON_BLACK,  curses.COLOR_MAGENTA,   curses.COLOR_BLACK)
        curses.init_pair(GREEN_ON_BLACK,    curses.COLOR_GREEN,     curses.COLOR_BLACK)
        curses.init_pair(BLUE_ON_BLACK,     curses.COLOR_BLUE,      curses.COLOR_BLACK) 
Example #3
Source File: console.py    From fluxclient with GNU Affero General Public License v3.0 6 votes vote down vote up
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() 
Example #4
Source File: ColorStreamHandler.py    From emailhunter-clone with MIT License 6 votes vote down vote up
def __init__(self, use_colors):
		logging.Handler.__init__(self)
		self.use_colors = use_colors

		# Initialize environment
		curses.setupterm()

		# Get the foreground color attribute for this environment
		self.fcap = curses.tigetstr('setaf')

		#Get the normal attribute
		self.COLOR_NORMAL = curses.tigetstr('sgr0')

		# Get + Save the color sequences
		self.COLOR_INFO = curses.tparm(self.fcap, curses.COLOR_GREEN)
		self.COLOR_ERROR = curses.tparm(self.fcap, curses.COLOR_RED)
		self.COLOR_WARNING = curses.tparm(self.fcap, curses.COLOR_YELLOW)
		self.COLOR_DEBUG = curses.tparm(self.fcap, curses.COLOR_BLUE) 
Example #5
Source File: menu_screen.py    From botany with ISC License 5 votes vote down vote up
def define_colors(self):
        # TODO: implement colors
        # 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) 
Example #6
Source File: format.py    From PathPicker with MIT License 5 votes vote down vote up
def updateDecoratedMatch(self, maxLen=None):
        '''Update the cached decorated match formatted string, and
        dirty the line, if needed'''
        if self.hovered and self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_RED,
                          FormattedText.BOLD_ATTRIBUTE)
        elif self.hovered:
            attributes = (curses.COLOR_WHITE, curses.COLOR_BLUE,
                          FormattedText.BOLD_ATTRIBUTE)
        elif self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_GREEN,
                          FormattedText.BOLD_ATTRIBUTE)
        elif not self.allInput:
            attributes = (0, 0, FormattedText.UNDERLINE_ATTRIBUTE)
        else:
            attributes = (0, 0, 0)

        decoratorText = self.getDecorator()

        # we may not be connected to a controller (during processInput,
        # for example)
        if self.controller:
            self.controller.dirtyLine(self.index)

        plainText = decoratorText + self.getMatch()
        if maxLen and len(plainText + str(self.beforeText)) > maxLen:
            # alright, we need to chop the ends off of our
            # decorated match and glue them together with our
            # truncation decorator. We subtract the length of the
            # before text since we consider that important too.
            spaceAllowed = maxLen - len(self.TRUNCATE_DECORATOR) \
                - len(decoratorText) \
                - len(str(self.beforeText))
            midPoint = int(spaceAllowed / 2)
            beginMatch = plainText[0:midPoint]
            endMatch = plainText[-midPoint:len(plainText)]
            plainText = beginMatch + self.TRUNCATE_DECORATOR + endMatch

        self.decoratedMatch = FormattedText(
            FormattedText.getSequenceForAttributes(*attributes) +
            plainText) 
Example #7
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 #8
Source File: parse.py    From eapeak with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def init_curses(self):
		"""
		This initializes the screen for curses useage.  It must be
		called before Curses can be used.
		"""
		self.user_marker_pos = 1  # Used with curses
		self.curses_row_offset = 0  # Used for marking the visible rows on the screen to allow scrolling
		self.curses_row_offset_store = 0  # Used for storing the row offset when switching from detailed to non-detailed view modes
		self.curses_detailed = None  # Used with curses
		self.screen = curses.initscr()
		curses.start_color()
		curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_WHITE)
		size = self.screen.getmaxyx()
		if size[0] < CURSES_MIN_Y or size[1] < CURSES_MIN_X:
			curses.endwin()
			return 1
		self.curses_max_rows = size[0] - 2  # Minus 2 for the border on the top and bottom
		self.curses_max_columns = size[1] - 2

		self.screen.border(0)
		self.screen.addstr(2, TAB_LENGTH, 'EAPeak Capturing Live')
		self.screen.addstr(3, TAB_LENGTH, 'Found 0 Networks')
		self.screen.addstr(4, TAB_LENGTH, 'Processed 0 Packets')
		self.screen.addstr(self.user_marker_pos + USER_MARKER_OFFSET, TAB_LENGTH, USER_MARKER)
		self.screen.refresh()
		try:
			curses.curs_set(1)
			curses.curs_set(0)
		except curses.error:  # Ignore exceptions from terminals that don't support setting the cursor's visibility
			pass
		curses.noecho()
		curses.cbreak()
		self.curses_enabled = True
		self.curses_lower_refresh_counter = 1
		return 0 
Example #9
Source File: tui.py    From wifiphisher with GNU General Public License v3.0 5 votes vote down vote up
def gather_info(self, screen, info):
        """
        Get the information from pywifiphisher and print them out
        :param self: A TuiMain object
        :param screen: A curses window object
        :param info: A namedtuple of printing information
        :type self: TuiMain
        :type screen: _curses.curses.window
        :type info: namedtuple
        :return: None
        :rtype: None
        """

        # setup curses
        try:
            curses.curs_set(0)
        except curses.error:
            pass
        screen.nodelay(True)
        curses.init_pair(1, curses.COLOR_BLUE, screen.getbkgd())
        curses.init_pair(2, curses.COLOR_YELLOW, screen.getbkgd())
        curses.init_pair(3, curses.COLOR_RED, screen.getbkgd())
        self.blue_text = curses.color_pair(1) | curses.A_BOLD
        self.yellow_text = curses.color_pair(2) | curses.A_BOLD
        self.red_text = curses.color_pair(3) | curses.A_BOLD

        while True:
            # catch the exception when screen size is smaller than
            # the text length
            is_done = self.display_info(screen, info)
            if is_done:
                return 
Example #10
Source File: grid.py    From ngrid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def show_model(model, cfg={}, num_frozen=0):
    """
    Shows an interactive view of the model on a connected TTY.

    @type model
      A model instance from this module.
    """
    full_cfg = dict(DEFAULT_CFG)
    full_cfg.update(cfg)
    cfg = full_cfg

    view = GridView(model, cfg, num_frozen=num_frozen)
    scr = curses.initscr()

    curses.start_color()
    curses.use_default_colors()
    curses.init_pair(1, -1, -1)                                     # normal
    curses.init_pair(2, curses.COLOR_BLUE, -1)                      # frozen
    curses.init_pair(3, -1, -1)                                     # separator
    curses.init_pair(4, -1, -1)                                     # footer
    curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_WHITE)     # cursor
    curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_BLUE)      # selection
    curses.init_pair(7, curses.COLOR_BLUE,  curses.COLOR_WHITE)     # frz sel

    try:
        curses.noecho()
        curses.cbreak()
        scr.keypad(1)
        view.set_screen(scr, locale.getpreferredencoding())
        view.show()
    finally:
        curses.nocbreak()
        scr.keypad(0)
        curses.echo()
        curses.endwin() 
Example #11
Source File: evilmaid.py    From EvilAbigail with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self):
        """
        Setup the main screen, progress bars and logging box
        """
        self.screen = curses.initscr()
        curses.curs_set(0)

        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_MAGENTA, curses.COLOR_BLACK)
        curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK)
        curses.init_pair(5, curses.COLOR_BLUE, curses.COLOR_BLACK)
        curses.init_pair(6, curses.COLOR_YELLOW, curses.COLOR_BLACK)

        self.height, self.width = self.screen.getmaxyx()
        self.screen.border()

        self.preptotal()
        self.prepcurrent()
        self.preplog()
        self.banner()
        self.sig()

        self.drives = len(glob.glob("/dev/sd?1"))
        self.donedrives = 0
        self.prevprogress = 0
        self.loglines = []
        self.idx = 1 
Example #12
Source File: traffic_junction_env.py    From IC3Net with MIT License 5 votes vote down vote up
def init_curses(self):
        self.stdscr = curses.initscr()
        curses.start_color()
        curses.use_default_colors()
        curses.init_pair(1, curses.COLOR_RED, -1)
        curses.init_pair(2, curses.COLOR_YELLOW, -1)
        curses.init_pair(3, curses.COLOR_CYAN, -1)
        curses.init_pair(4, curses.COLOR_GREEN, -1)
        curses.init_pair(5, curses.COLOR_BLUE, -1) 
Example #13
Source File: fm_cli.py    From baidufm-py with MIT License 5 votes vote down vote up
def setup(self, stdscr):
        fm_log(logger, 'init baidufm fm cli')
        self.stdscr = stdscr

        # init color
        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_GREEN, curses.COLOR_BLACK)
        curses.init_pair(10, curses.COLOR_RED, curses.COLOR_BLACK)

        curses.start_color()
        for i in range(0, curses.COLORS):
            if i < 10:
                continue
            curses.init_pair(i + 1, curses.COLOR_BLACK, i)

        self.player = choose_player()(self.footer, self.event)

        self.stdscr.nodelay(0)
        self.setup_and_draw_screen()
        self.run() 
Example #14
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 #15
Source File: top.py    From python-alerta-client with Apache License 2.0 4 votes vote down vote up
def main(self, stdscr):
        self.screen = stdscr

        curses.use_default_colors()

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

        COLOR_RED = curses.color_pair(1)
        COLOR_MAGENTA = curses.color_pair(2)
        COLOR_YELLOW = curses.color_pair(3)
        COLOR_BLUE = curses.color_pair(4)
        COLOR_CYAN = curses.color_pair(5)
        COLOR_GREEN = curses.color_pair(6)
        COLOR_BLACK = curses.color_pair(7)

        self.SEVERITY_MAP = {
            'security': ['Sec', COLOR_BLACK],
            'critical': ['Crit', COLOR_RED],
            'major': ['Majr', COLOR_MAGENTA],
            'minor': ['Minr', COLOR_YELLOW],
            'warning': ['Warn', COLOR_BLUE],
            'indeterminate': ['Ind ', COLOR_CYAN],
            'cleared': ['Clr', COLOR_GREEN],
            'normal': ['Norm', COLOR_GREEN],
            'ok': ['Ok', COLOR_GREEN],
            'informational': ['Info', COLOR_GREEN],
            'debug': ['Dbug', COLOR_BLACK],
            'trace': ['Trce', COLOR_BLACK],
            'unknown': ['Unkn', COLOR_BLACK]
        }

        self.screen.keypad(1)
        self.screen.nodelay(1)

        while True:
            self.update()
            event = self.screen.getch()
            if 0 < event < 256:
                self._key_press(chr(event))
            else:
                if event == curses.KEY_RESIZE:
                    self.update()
            time.sleep(2) 
Example #16
Source File: rgcurses.py    From rgkit with The Unlicense 4 votes vote down vote up
def _init_curses(self):

        # Colors and attributes

        colors_empty = 1
        colors_obstacle = 2
        colors_bot1 = 3
        colors_bot2 = 4
        # Selected
        colors_empty_s = 5
        colors_obstacle_s = 6
        colors_bot1_s = 7
        colors_bot2_s = 8
        # Other
        colors_text = 9

        # (Color pair, Foreground, Background)
        cs.init_pair(colors_empty, cs.COLOR_WHITE, cs.COLOR_BLACK)
        cs.init_pair(colors_obstacle, cs.COLOR_BLACK, cs.COLOR_WHITE)
        cs.init_pair(colors_bot1, cs.COLOR_WHITE, cs.COLOR_RED)
        cs.init_pair(colors_bot2, cs.COLOR_WHITE, cs.COLOR_BLUE)
        cs.init_pair(colors_empty_s, cs.COLOR_WHITE, cs.COLOR_YELLOW)
        cs.init_pair(colors_obstacle_s, cs.COLOR_BLACK, cs.COLOR_YELLOW)
        cs.init_pair(colors_bot1_s, cs.COLOR_WHITE, cs.COLOR_MAGENTA)
        cs.init_pair(colors_bot2_s, cs.COLOR_WHITE, cs.COLOR_CYAN)
        cs.init_pair(colors_text, cs.COLOR_WHITE, cs.COLOR_BLACK)

        # Attributes
        attr_empty = cs.A_NORMAL
        attr_obstacle = cs.A_NORMAL
        attr_bot1 = cs.A_BOLD
        attr_bot2 = cs.A_BOLD
        attr_empty_s = cs.A_NORMAL
        attr_obstacle_s = cs.A_NORMAL
        attr_bot1_s = cs.A_BOLD
        attr_bot2_s = cs.A_BOLD
        attr_text = cs.A_NORMAL

        # **** Do not edit settings below this line ***

        cs.curs_set(0)
        self._attr_empty = cs.color_pair(colors_empty) | attr_empty
        self._attr_obstacle = cs.color_pair(colors_obstacle) | attr_obstacle
        self._attr_bot1 = cs.color_pair(colors_bot1) | attr_bot1
        self._attr_bot2 = cs.color_pair(colors_bot2) | attr_bot2
        self._attr_empty_s = cs.color_pair(colors_empty_s) | attr_empty_s
        self._attr_obstacle_s = cs.color_pair(colors_obstacle_s) \
            | attr_obstacle_s
        self._attr_bot1_s = cs.color_pair(colors_bot1_s) | attr_bot1_s
        self._attr_bot2_s = cs.color_pair(colors_bot2_s) | attr_bot2_s
        self._attr_text = cs.color_pair(colors_text) | attr_text 
Example #17
Source File: text.py    From encompass with GNU General Public License v3.0 4 votes vote down vote up
def __init__(self, config, network):

        self.config = config
        self.network = network
        storage = WalletStorage(config)
        if not storage.file_exists:
            print "Wallet not found. try 'electrum create'"
            exit()

        self.wallet = Wallet(storage)
        self.wallet.start_threads(self.network)

        locale.setlocale(locale.LC_ALL, '')
        self.encoding = locale.getpreferredencoding()

        self.stdscr = curses.initscr()
        curses.noecho()
        curses.cbreak()
        curses.start_color()
        curses.use_default_colors()
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
        curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_CYAN)
        self.stdscr.keypad(1)
        self.stdscr.border(0)
        self.maxy, self.maxx = self.stdscr.getmaxyx()
        self.set_cursor(0)
        self.w = curses.newwin(10, 50, 5, 5)

        set_verbosity(False)
        self.tab = 0
        self.pos = 0
        self.popup_pos = 0

        self.str_recipient = ""
        self.str_description = ""
        self.str_amount = ""
        self.str_fee = ""
        self.history = None
       
        if self.network: 
            self.network.register_callback('updated', self.update)
            self.network.register_callback('connected', self.refresh)
            self.network.register_callback('disconnected', self.refresh)
            self.network.register_callback('disconnecting', self.refresh)

        self.tab_names = [_("History"), _("Send"), _("Receive"), _("Contacts"), _("Wall")]
        self.num_tabs = len(self.tab_names) 
Example #18
Source File: __main__.py    From asciidots with GNU Affero General Public License v3.0 4 votes vote down vote up
def __init__(self, env, ticks, silent, debug, compat_debug, debug_lines, autostep_debug, output_limit):
        """

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

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

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

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

        self.first_tick = True

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

            self.stdscr = curses.initscr()

            curses.start_color()

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

            curses.noecho()

            # hides the cursor
            curses.curs_set(False)

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

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

            signal.signal(signal.SIGINT, signal_handler) 
Example #19
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)