Python curses.color_pair() Examples
The following are 30
code examples of curses.color_pair().
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: evilmaid.py From EvilAbigail with GNU General Public License v2.0 | 6 votes |
def plot(self, progress): """ Actually fill the progress bars accordingly """ if progress < self.prevprogress: self.donedrives += 1 self.prevprogress = progress progress = progress + self.donedrives totalbar = int((progress/self.drives)*((self.width-2)/2)) currentbar = int(progress*((self.width-2)/2)) % (self.width/2) self.preptotal() self.prepcurrent() self.totalbar.addstr(1, 1, "-"*(totalbar-2), curses.color_pair(2)) self.currentbar.addstr(1, 1, "-"*(currentbar-2), curses.color_pair(2)) self.refresh()
Example #2
Source File: curses_ui.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def _screen_draw_text_line(self, row, line, attr=curses.A_NORMAL, color=None): """Render a line of text on the screen. Args: row: (int) Row index. line: (str) The line content. attr: curses font attribute. color: (str) font foreground color name. Raises: TypeError: If row is not of type int. """ if not isinstance(row, int): raise TypeError("Invalid type in row") if len(line) > self._max_x: line = line[:self._max_x] color_pair = (self._default_color_pair if color is None else self._color_pairs[color]) self._stdscr.addstr(row, 0, line, color_pair | attr) self._screen_refresh()
Example #3
Source File: curses_ui.py From lambda-packs with MIT License | 6 votes |
def _screen_draw_text_line(self, row, line, attr=curses.A_NORMAL, color=None): """Render a line of text on the screen. Args: row: (int) Row index. line: (str) The line content. attr: curses font attribute. color: (str) font foreground color name. Raises: TypeError: If row is not of type int. """ if not isinstance(row, int): raise TypeError("Invalid type in row") if len(line) > self._max_x: line = line[:self._max_x] color_pair = (self._default_color_pair if color is None else self._color_pairs[color]) self._stdscr.addstr(row, 0, line, color_pair | attr) self._screen_refresh()
Example #4
Source File: tui.py From awesome-finder with MIT License | 6 votes |
def display(self): """Display the found awesome content on result window""" self.result_window.erase() for idx, val in enumerate(self.matched_blocks[self.top:self.top + self.max_lines]): if val['type'] == 'category': # Highlight the current cursor line if idx == self.current: self.result_window.addstr(idx, 0, shorten(val['line'], self.width, placeholder='...'), curses.color_pair(2)) else: self.result_window.addstr(idx, 0, shorten(val['line'], self.width, placeholder='...'), curses.color_pair(1)) elif val['type'] == 'awesome': # Highlight the current cursor line if idx == self.current: self.result_window.addstr(idx, 2, shorten(val['line'], self.width - 3, placeholder='...'), curses.color_pair(2)) else: self.result_window.addstr(idx, 2, shorten(val['line'], self.width - 3, placeholder='...')) self.result_window.refresh()
Example #5
Source File: tui.py From awesome-finder with MIT License | 6 votes |
def init_layout(self): """Initialize the each windows with their size and shape""" self.height, self.width = self.window.getmaxyx() # Title section self.window.addstr(0, 0, '[awesome-{}] Find awesome things!'.format(self.awesome_title), curses.color_pair(1)) self.window.hline(1, 0, curses.ACS_HLINE, self.width) # Search result section self.result_window = curses.newwin(self.height - 4, self.width, 2, 0) self.result_window.keypad(True) # Search bar section self.window.hline(self.height - 2, 0, curses.ACS_HLINE, self.width) self.window.addch(self.height - 1, 0, '>') self.search_window = curses.newwin(1, self.width - 1, self.height - 1, 2) self.search_window.keypad(True) self.window.refresh()
Example #6
Source File: listbox.py From plasma with GNU General Public License v3.0 | 6 votes |
def draw(self): i = 0 while i < self.height: if self.win_y + i < len(self.token_lines): self.print_line(i) else: # force to clear the entire line self.screen.move(i, 0) self.screen.clrtoeol() i += 1 # Print the scroll cursor on the right. It uses utf-8 block characters. y = self.get_y_scroll() i = y % 8 y = y // 8 self.screen.insstr(y, self.width - 1, self.cursor_position_utf8[i], color_pair(COLOR_SCROLL_CURSOR)) if i != 0 and y + 1 < self.height: self.screen.insstr(y + 1, self.width - 1, self.cursor_position_utf8[i], color_pair(COLOR_SCROLL_CURSOR) | A_REVERSE)
Example #7
Source File: wallet.py From bitcoind-ncurses with MIT License | 6 votes |
def draw_window(state, window): window.clear() window.refresh() win_header = curses.newwin(2, 76, 0, 0) unit = 'BTC' if 'testnet' in state: if state['testnet']: unit = 'TNC' if 'wallet' in state: if 'balance' in state: balance_string = "balance: " + "%0.8f" % state['balance'] + " " + unit if 'unconfirmedbalance' in state: if state['unconfirmedbalance'] != 0: balance_string += " (+" + "%0.8f" % state['unconfirmedbalance'] + " unconf)" window.addstr(0, 1, balance_string, curses.A_BOLD) draw_transactions(state) else: win_header.addstr(0, 1, "no wallet information loaded", curses.A_BOLD + curses.color_pair(3)) win_header.addstr(1, 1, "loading... (is -disablewallet on?)", curses.A_BOLD) win_header.refresh()
Example #8
Source File: wallet.py From bitcoind-ncurses with MIT License | 6 votes |
def draw_transactions(state): window_height = state['y'] - 3 win_transactions = curses.newwin(window_height, 76, 2, 0) win_transactions.addstr(0, 1, "transactions: (UP/DOWN: scroll, ENTER: view)", curses.A_BOLD + curses.color_pair(5)) offset = state['wallet']['offset'] for index in range(offset, offset+window_height-1): if index < len(state['wallet']['view_string']): condition = (index == offset+window_height-2) and (index+1 < len(state['wallet']['view_string'])) condition = condition or ( (index == offset) and (index > 0) ) if condition: win_transactions.addstr(index+1-offset, 1, "...") else: win_transactions.addstr(index+1-offset, 1, state['wallet']['view_string'][index]) if index == (state['wallet']['cursor']*4 + 1): win_transactions.addstr(index+1-offset, 1, ">", curses.A_REVERSE + curses.A_BOLD) win_transactions.refresh()
Example #9
Source File: npysThemeManagers.py From apple_bleee with GNU General Public License v3.0 | 6 votes |
def findPair(self, caller, request='DEFAULT'): if not curses.has_colors() or npysGlobalOptions.DISABLE_ALL_COLORS: return False if request=='DEFAULT': request = caller.color # Locate the requested colour pair. Default to default if not found. try: pair = self._defined_pairs[self._names[request]] except: pair = self._defined_pairs[self._names['DEFAULT']] # now make the actual attribute color_attribute = curses.color_pair(pair[0]) return color_attribute
Example #10
Source File: footer.py From bitcoind-ncurses with MIT License | 6 votes |
def draw_window(state): win_footer = curses.newwin(1, 76, state['y']-1, 0) color = curses.color_pair(1) if 'testnet' in state: if state['testnet']: color = curses.color_pair(2) win_footer.addstr(0, 1, "ncurses", color + curses.A_BOLD) x = 10 for mode_string in g.modes: modifier = curses.A_BOLD if state['mode'] == mode_string: modifier += curses.A_REVERSE win_footer.addstr(0, x, mode_string[0].upper(), modifier + curses.color_pair(5)) win_footer.addstr(0, x+1, mode_string[1:], modifier) x += len(mode_string) + 2 win_footer.refresh()
Example #11
Source File: fm_cli.py From baidufm-py with MIT License | 6 votes |
def init_head(self): title = "BaiduFM" try: user_counts = self.api.get_fm_user_counts() user_name = ' / ' + (user_counts['user_name'] or "Visitor") total_listen = "Listen: %s" % user_counts['counts']['total_listen'] like_songs = "Like: %s" % user_counts['counts']['like_songs'] dislike_songs = "Dislike: %s" % user_counts['counts']['dislike_songs'] if user_counts['user_name'] and self.login_channel: self.login_channel.extend(self.channels) self.channels, self.login_channel = self.login_channel, None except Exception as e: fm_log(logger, "INIT HEAD: %s", str(e.args)) return len_x = len(title) self.head_win.addstr(0, 0, title, curses.color_pair(1)) self.head_win.addstr(0, len_x, user_name, curses.color_pair(2)) len_x += len(user_name) + 2 self.head_win.addstr(0, len_x, total_listen, curses.color_pair(3)) len_x += len(total_listen) + 2 self.head_win.addstr(0, len_x, like_songs, curses.color_pair(4)) len_x += len(like_songs) + 2 self.head_win.addstr(0, len_x, dislike_songs, curses.color_pair(5)) self.head_win.noutrefresh()
Example #12
Source File: __main__.py From asciidots with GNU Affero General Public License v3.0 | 6 votes |
def print_char(self, char, color_code, row=None, col=None): """ Print one char to the screen with coloration. In compat_debug this will just append the char to stdout. This checks for silent mode :param char: The character to print :param color_code: The colorcode 1234 = RGYB :param row: The y pos used with curses :param col: The x pos used with curses """ if self.silent: return 42 if self.compat_debug: if not color_code: # Zero is the regular print, but the code 33 will draw black over black and we dont want that print(char, end='') else: print('\033[0;3', color_code, 'm', char, '\033[0m', sep='', end='') else: self.win_program.addstr(row, col, char, curses.color_pair(color_code))
Example #13
Source File: peers.py From bitcoind-ncurses with MIT License | 6 votes |
def draw_window(state, window): window.clear() window.refresh() win_header = curses.newwin(3, 75, 0, 0) if 'peerinfo' in state: win_header.addstr(0, 1, "connected peers: " + str(len(state['peerinfo'])).ljust(10) + " (UP/DOWN: scroll)", curses.A_BOLD) win_header.addstr(2, 1, " Node IP Version Recv Sent Time Height", curses.A_BOLD + curses.color_pair(5)) draw_peers(state) else: win_header.addstr(0, 1, "no peer information loaded", curses.A_BOLD + curses.color_pair(3)) win_header.addstr(1, 1, "loading...", curses.A_BOLD) win_header.refresh()
Example #14
Source File: forks.py From bitcoind-ncurses with MIT License | 6 votes |
def draw_window(state, window): window.clear() window.refresh() win_header = curses.newwin(3, 75, 0, 0) if 'chaintips' in state: win_header.addstr(0, 1, "chain tips: " + str(len(state['chaintips'])).ljust(10) + " (UP/DOWN: scroll, F: refresh)", curses.A_BOLD) win_header.addstr(1, 1, "key: Active/Invalid/HeadersOnly/ValidFork/ValidHeaders", curses.A_BOLD) win_header.addstr(2, 1, "height length status 0-prefix hash", curses.A_BOLD + curses.color_pair(5)) draw_tips(state) else: win_header.addstr(0, 1, "no chain tip information loaded", curses.A_BOLD + curses.color_pair(3)) win_header.addstr(1, 1, "loading... (press F to try again)", curses.A_BOLD) win_header.refresh()
Example #15
Source File: cursesgui.py From ham2mon with GNU General Public License v3.0 | 5 votes |
def draw_channels(self, gui_lockout_channels): """Draws tuned channels list Args: rf_channels [string]: List of strings in MHz """ # Clear previous contents, draw border, and title self.win.clear() self.win.border(0) self.win.addnstr(0, self.dims[1]/2-3, "LOCKOUT", 7, curses.color_pair(4)) # Draw the lockout channels for idx, gui_lockout_channel in enumerate(gui_lockout_channels): # Don't draw past height of window if idx <= self.dims[0]-3: text = " " + gui_lockout_channel self.win.addnstr(idx+1, 1, text, 11) else: pass # Hide cursor self.win.leaveok(1) # Update virtual window self.win.noutrefresh()
Example #16
Source File: recipe-577933.py From code with MIT License | 5 votes |
def display_time(scr): t = time.ctime().split() write(scr, 0, 0, t[0], curses.color_pair(9)) write(scr, 0, 4, t[1], curses.color_pair(9)) write(scr, 0, 8, t[2], curses.color_pair(9)) write(scr, 0, 11, t[3], curses.color_pair(9)) write(scr, 0, 20, t[4], curses.color_pair(9))
Example #17
Source File: ui.py From musicbox with MIT License | 5 votes |
def build_playinfo( self, song_name, artist, album_name, quality, start, pause=False ): curses.noecho() # refresh top 2 line self.screen.move(1, 1) self.screen.clrtoeol() self.screen.move(2, 1) self.screen.clrtoeol() if pause: self.addstr( 1, self.indented_startcol, "_ _ z Z Z " + quality, curses.color_pair(3) ) else: self.addstr( 1, self.indented_startcol, "♫ ♪ ♫ ♪ " + quality, curses.color_pair(3) ) self.addstr( 1, min(self.indented_startcol + 18, self.x - 1), song_name + self.space + artist + " < " + album_name + " >", curses.color_pair(4), ) self.screen.refresh()
Example #18
Source File: cursesgui.py From ham2mon with GNU General Public License v3.0 | 5 votes |
def draw_channels(self, gui_tuned_channels): """Draws tuned channels list Args: rf_channels [string]: List of strings in MHz """ # Clear previous contents, draw border, and title self.win.clear() self.win.border(0) self.win.addnstr(0, self.dims[1]/2-4, "CHANNELS", 8, curses.color_pair(4)) # Limit the displayed channels to no more than two rows max_length = 2*(self.dims[0]-2) if len(gui_tuned_channels) > max_length: gui_tuned_channels = gui_tuned_channels[:max_length] else: pass # Draw the tuned channels prefixed by index in list (demodulator index) for idx, gui_tuned_channel in enumerate(gui_tuned_channels): text = str(idx) + ": " + gui_tuned_channel if idx < self.dims[0]-2: # Display in first column self.win.addnstr(idx+1, 1, text, 11) else: # Display in second column self.win.addnstr(idx-self.dims[0]+3, 13, text, 11) # Hide cursor self.win.leaveok(1) # Update virtual window self.win.noutrefresh()
Example #19
Source File: tui.py From python-curses-scroll-example with MIT License | 5 votes |
def display(self): """Display the items on window""" self.window.erase() for idx, item in enumerate(self.items[self.top:self.top + self.max_lines]): # Highlight the current cursor line if idx == self.current: self.window.addstr(idx, 0, item, curses.color_pair(2)) else: self.window.addstr(idx, 0, item, curses.color_pair(1)) self.window.refresh()
Example #20
Source File: tui.py From python-curses-scroll-example with MIT License | 5 votes |
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) self.height, self.width = self.window.getmaxyx()
Example #21
Source File: recipe-577933.py From code with MIT License | 5 votes |
def display_loadavg(scr): lavg = os.getloadavg() write(scr, 1, 0, 'System', curses.color_pair(9)) write(scr, 1, 7, 'Load:', curses.color_pair(9)) write(scr, 1, 13, '%.02f' % lavg[0], curses.color_pair(9)) write(scr, 1, 20, '%.02f' % lavg[1], curses.color_pair(9)) write(scr, 1, 27, '%.02f' % lavg[2], curses.color_pair(9))
Example #22
Source File: ui.py From musicbox with MIT License | 5 votes |
def build_timing(self): self.screen.move(6, 1) self.screen.clrtobot() self.screen.timeout(-1) self.addstr(8, self.startcol, "输入定时时间(min):", curses.color_pair(1)) self.addstr(11, self.startcol, "ps:定时时间为整数,输入0代表取消定时退出", curses.color_pair(1)) self.screen.timeout(-1) # disable the screen timeout curses.echo() timing_time = self.screen.getstr(8, self.startcol + 19, 60) self.screen.timeout(100) # restore the screen timeout return timing_time
Example #23
Source File: ui.py From musicbox with MIT License | 5 votes |
def build_login_error(self): self.screen.move(4, 1) self.screen.timeout(-1) # disable the screen timeout self.screen.clrtobot() self.addstr(8, self.startcol, "艾玛,登录信息好像不对呢 (O_O)#", curses.color_pair(1)) self.addstr(10, self.startcol, "[1] 再试一次") self.addstr(11, self.startcol, "[2] 稍后再试") self.addstr(14, self.startcol, "请键入对应数字:", curses.color_pair(2)) self.screen.refresh() x = self.screen.getch() self.screen.timeout(100) # restore the screen timeout return x
Example #24
Source File: ui.py From musicbox with MIT License | 5 votes |
def build_login_bar(self): curses.noecho() self.screen.move(4, 1) self.screen.clrtobot() self.addstr(5, self.startcol, "请输入登录信息(支持手机登录)", curses.color_pair(1)) self.addstr(8, self.startcol, "账号:", curses.color_pair(1)) self.addstr(9, self.startcol, "密码:", curses.color_pair(1)) self.screen.move(8, 24) self.screen.refresh()
Example #25
Source File: ui.py From musicbox with MIT License | 5 votes |
def build_loading(self): self.addstr(7, self.startcol, "享受高品质音乐,loading...", curses.color_pair(1)) self.screen.refresh()
Example #26
Source File: tx.py From bitcoind-ncurses with MIT License | 5 votes |
def draw_input_window(state, window, rpcc): color = curses.color_pair(1) if 'testnet' in state: if state['testnet']: color = curses.color_pair(2) window.clear() window.addstr(0, 1, "bitcoind-ncurses " + g.version + " [transaction input mode]", color + curses.A_BOLD) window.addstr(1, 1, "please enter txid", curses.A_BOLD) window.refresh() entered_txid = getstr.getstr(67, 3, 1) # w, y, x if len(entered_txid) == 64: # TODO: better checking for valid txid here s = {'txid': entered_txid} rpcc.request("getrawtransaction", entered_txid, 1) window.addstr(5, 1, "waiting for transaction (will stall here if not found)", color + curses.A_BOLD) window.refresh() state['mode'] = 'tx' else: window.addstr(5, 1, "not a valid txid", color + curses.A_BOLD) window.refresh() gevent.sleep(0.5) window.clear() window.refresh() state['mode'] = "monitor"
Example #27
Source File: curses_menu.py From curses-menu with MIT License | 5 votes |
def _set_up_colors(self): curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) self.highlight = curses.color_pair(1) self.normal = curses.A_NORMAL
Example #28
Source File: npysThemeManagers.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def initalize_pair(self, name, fg, bg): # Initialize a color_pair for the required colour and return the number. Raise an exception if this is not possible. if (len(list(self._defined_pairs.keys()))+1) == self._max_pairs: raise Exception("Too many colours") _this_pair_number = len(list(self._defined_pairs.keys())) + 1 curses.init_pair(_this_pair_number, fg, bg) self._defined_pairs[name] = (_this_pair_number, fg, bg) return _this_pair_number
Example #29
Source File: npysThemeManagers.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def initialize_pairs(self): # White on Black is fixed as color_pair 0 self._defined_pairs['WHITE_BLACK'] = (0, curses.COLOR_WHITE, curses.COLOR_BLACK) for cp in self.__class__._colors_to_define: if cp[0] == 'WHITE_BLACK': # silently protect the user from breaking things. continue self.initalize_pair(cp[0], cp[1], cp[2])
Example #30
Source File: theme.py From ttrv with MIT License | 5 votes |
def bind_curses(self): """ Bind the theme's colors to curses's internal color pair map. This method must be called once (after curses has been initialized) before any element attributes can be accessed. Color codes and other special attributes will be mixed bitwise into a single value that can be passed into curses draw functions. """ self._color_pair_map = {} self._attribute_map = {} for element, item in self.elements.items(): fg, bg, attrs = item color_pair = (fg, bg) if self.use_color and color_pair != (-1, -1): # Curses limits the number of available color pairs, so we # need to reuse them if there are multiple elements with the # same foreground and background. if color_pair not in self._color_pair_map: # Index 0 is reserved by curses for the default color index = len(self._color_pair_map) + 1 curses.init_pair(index, color_pair[0], color_pair[1]) self._color_pair_map[color_pair] = curses.color_pair(index) attrs |= self._color_pair_map[color_pair] self._attribute_map[element] = attrs