Python curses.A_REVERSE Examples
The following are 30
code examples of curses.A_REVERSE().
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: __main__.py From asciidots with GNU Affero General Public License v3.0 | 6 votes |
def curses_input(self, stdscr, row, col, prompt_string, ascii_mode=False): """ Get an input string with curses. Row and col are the start position ot the prompt_string. """ curses.echo() stdscr.addstr(row, col, str(prompt_string), curses.A_REVERSE) stdscr.addstr(row + 1, col, " " * (curses.COLS - 1)) stdscr.refresh() input_val = "" while len(input_val) <= 0: if ascii_mode: input_val = chr(stdscr.getch()) break else: input_val = stdscr.getstr(row + 1, col, 20) return input_val
Example #2
Source File: pytrader.py From pytrader with MIT License | 6 votes |
def __init__(self, stdscr, instance): self.instance = instance self.pmin = 0 self.pmax = 0 self.change_type = None instance.history.signal_changed.connect(self.slot_history_changed) instance.orderbook.signal_changed.connect(self.slot_orderbook_changed) # some terminals do not support reverse video # so we cannot use reverse space for candle bodies if curses.A_REVERSE & curses.termattrs(): self.body_char = " " self.body_attr = curses.A_REVERSE else: self.body_char = curses.ACS_CKBOARD self.body_attr = 0 Win.__init__(self, stdscr)
Example #3
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 #4
Source File: zktop.py From python-scripts with GNU General Public License v3.0 | 6 votes |
def update(self, s): self.win.erase() self.addstr(1, 0, "CLIENT PORT S I QUEUED RECVD SENT", curses.A_REVERSE) self.sessions[s.server_id] = s.sessions items = [] for l in self.sessions: items.extend(l) items.sort(key=lambda x: int(x.queued), reverse=True) for i, session in enumerate(items): try: #ugh, need to handle if slow - thread for async resolver? host = self.hostname(session) if options.names else session.host self.addstr(i + 2, 0, "%-15s %5s %1s %1s %8s %8s %8s" % (host[:15], session.port, session.server_id, session.interest_ops, session.queued, session.recved, session.sent)) except: break
Example #5
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 #6
Source File: selection.py From babi with MIT License | 6 votes |
def highlight_until(self, lines: Buf, idx: int) -> None: if self.start is None or self.end is None: return # XXX: this assumes pair 1 is the background attr = curses.A_REVERSE | curses.A_DIM | curses.color_pair(1) (s_y, s_x), (e_y, e_x) = self.get() if s_y == e_y: self.regions[s_y] = (HL(x=s_x, end=e_x, attr=attr),) else: self.regions[s_y] = ( HL(x=s_x, end=len(lines[s_y]) + 1, attr=attr), ) for l_y in range(s_y + 1, e_y): self.regions[l_y] = ( HL(x=0, end=len(lines[l_y]) + 1, attr=attr), ) self.regions[e_y] = (HL(x=0, end=e_x, attr=attr),)
Example #7
Source File: top.py From psutil with BSD 3-Clause "New" or "Revised" License | 6 votes |
def print_line(line, highlight=False): """A thin wrapper around curses's addstr().""" global lineno try: if highlight: line += " " * (win.getmaxyx()[1] - len(line)) win.addstr(lineno, 0, line, curses.A_REVERSE) else: win.addstr(lineno, 0, line, 0) except curses.error: lineno = 0 win.refresh() raise else: lineno += 1 # --- /curses stuff
Example #8
Source File: displayutil.py From onion-expose with BSD 3-Clause "New" or "Revised" License | 6 votes |
def draw_fancy_text(self, text, y, x, attr=0): """ Displays text. A unicode `Superscript Two` (U+00B2) toggles bold formatting; a unicode `Superscript Three` (U+00B3) toggles color inversion. The bold and inversion formatting flags are ORed with the `attr` parameter. """ # TODO: Allow formatting other than bold (possibly using other exotic Unicode characters). pos = 0 for i in range(len(text)): if text[i] == "\xb2": attr ^= curses.A_BOLD elif text[i] == "\xb3": attr ^= curses.A_REVERSE else: self.window.addch(y, x + pos, text[i], attr) pos += 1
Example #9
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 #10
Source File: test_theme.py From rtv with MIT License | 6 votes |
def test_theme_from_file(): with _ephemeral_directory() as dirname: with NamedTemporaryFile(mode='w+', dir=dirname) as fp: with pytest.raises(ConfigError): Theme.from_file(fp.name, 'installed') fp.write('[theme]\n') fp.write('Unknown = - -\n') fp.write('Upvote = - red\n') fp.write('Downvote = ansi_255 default bold\n') fp.write('NeutralVote = #000000 #ffffff bold+reverse\n') fp.flush() theme = Theme.from_file(fp.name, 'installed') assert theme.source == 'installed' assert 'Unknown' not in theme.elements assert theme.elements['Upvote'] == ( -1, curses.COLOR_RED, curses.A_NORMAL) assert theme.elements['Downvote'] == ( 255, -1, curses.A_BOLD) assert theme.elements['NeutralVote'] == ( 16, 231, curses.A_BOLD | curses.A_REVERSE)
Example #11
Source File: screen.py From babi with MIT License | 5 votes |
def _draw_header(self) -> None: filename = self.file.filename or '<<new file>>' if self.file.modified: filename += ' *' if len(self.files) > 1: files = f'[{self.i + 1}/{len(self.files)}] ' version_width = len(VERSION_STR) + 2 + len(files) else: files = '' version_width = len(VERSION_STR) + 2 centered = filename.center(self.margin.cols)[version_width:] s = f' {VERSION_STR} {files}{centered}{files}' self.stdscr.insstr(0, 0, s, curses.A_REVERSE)
Example #12
Source File: cli.py From wifibroadcast with GNU General Public License v3.0 | 5 votes |
def lineReceived(self, line): attrs = json.loads(line) p = attrs['packets'] rssi_d = attrs['rssi'] self.factory.window.clear() self.factory.window.addstr(0, 0, 'TX ANT %02x**' % (attrs['tx_ant'],) if self.factory.has_tx else 'NO TX') self.factory.window.addstr(1, 0, 'RX PKT: recv %d d_ok %d fec_r %d lost %d d_err %d bad %d\n' % \ (p['all'][1], p['dec_ok'][1], p['fec_rec'][1], p['lost'][1], p['dec_err'][1], p['bad'][1])) msg_l = (('RX PKT/s: recv %d d_ok %d ' % (p['all'][0], p['dec_ok'][0]), 0), ('fec_r %d' % p['fec_rec'][0], curses.A_REVERSE if p['fec_rec'][0] else 0), (' ', 0), ('lost %d' % p['lost'][0], curses.A_REVERSE if p['lost'][0] else 0), (' ', 0), ('d_err %d' % p['dec_err'][0], curses.A_REVERSE if p['dec_err'][0] else 0), (' ', 0), ('bad %d\n' % p['bad'][0], curses.A_REVERSE if p['bad'][0] else 0)) x = 0 xmax = self.factory.window.getmaxyx()[1] for msg, attr in msg_l: if x < xmax: self.factory.window.addstr(2, x, msg, attr) x += len(msg) if rssi_d: for i, (k, v) in enumerate(sorted(rssi_d.items())): pkt_s, rssi_min, rssi_avg, rssi_max = v self.factory.window.addstr(i + 4, 0, '%04x: %d pkt/s, rssi %d < %d < %d\n' % (int(k, 16), pkt_s, rssi_min, rssi_avg, rssi_max)) else: self.factory.window.addstr(4, 0, 'Link lost!', curses.A_REVERSE) self.factory.window.refresh()
Example #13
Source File: command.py From SpotipyTUI with MIT License | 5 votes |
def draw_track_list(self): """Handles all of the track list displaying.""" self.track_window.clear() result_line = '{0:<2} | {1:<40} | {2:<25} | {3:<40}' result_header = result_line.format('#', 'Song Name', 'Artist', 'Album') separator_bar = '=' * (self.track_window.getmaxyx()[1] - 5) self.track_window.addstr(0, 0, result_header) self.track_window.addstr(1, 0, separator_bar) for song_index, track in enumerate(self.track_list, start=1): if (self.curr_position - self.track_start) == track[0]: mode = curses.A_REVERSE else: mode = curses.A_NORMAL song_index = str(song_index) if len(song_index) == 1: song_index = '0' + song_index track_string = result_line.format(song_index, track[1][:40], track[2][:25], track[3][:40]) self.track_window.addstr(track[0] + self.track_start, 0, track_string, mode) bottom_bar_position = self.track_start + len(self.track_list) self.track_window.addstr(bottom_bar_position, 0, separator_bar) self.track_window.refresh()
Example #14
Source File: menu_screen.py From botany with ISC License | 5 votes |
def __init__(self, this_plant, this_data): '''Initialization''' self.initialized = False self.screen = curses.initscr() curses.noecho() curses.raw() if curses.has_colors(): curses.start_color() try: curses.curs_set(0) except curses.error: # Not all terminals support this functionality. # When the error is ignored the screen will look a little uglier, but that's not terrible # So in order to keep botany as accesible as possible to everyone, it should be safe to ignore the error. pass self.screen.keypad(1) self.plant = this_plant self.visited_plant = None self.user_data = this_data self.plant_string = self.plant.parse_plant() self.plant_ticks = str(int(self.plant.ticks)) self.exit = False self.infotoggle = 0 self.maxy, self.maxx = self.screen.getmaxyx() # Highlighted and Normal line definitions if curses.has_colors(): self.define_colors() self.highlighted = curses.color_pair(1) else: self.highlighted = curses.A_REVERSE self.normal = curses.A_NORMAL # Threaded screen update for live changes screen_thread = threading.Thread(target=self.update_plant_live, args=()) screen_thread.daemon = True screen_thread.start() # Recusive lock to prevent both threads from drawing at the same time self.screen_lock = threading.RLock() self.screen.clear() self.show(["water","look","garden","visit", "instructions"], title=' botany ', subtitle='options')
Example #15
Source File: ui.py From suplemon with MIT License | 5 votes |
def show_top_status(self): """Show top status row.""" self.header_win.erase() size = self.get_size() display = self.app.config["display"] head_parts = [] if display["show_app_name"]: name_str = "Suplemon Editor v{0} -".format(self.app.version) if self.app.config["app"]["use_unicode_symbols"]: logo = "\U0001f34b" # Fancy lemon name_str = " {0} {1}".format(logo, name_str) head_parts.append(name_str) # Add module statuses to the status bar in descending order module_keys = sorted(self.app.modules.modules.keys()) for name in module_keys: module = self.app.modules.modules[name] if module.options["status"] == "top": status = module.get_status() if status: head_parts.append(status) if display["show_file_list"]: head_parts.append(self.file_list_str()) head = " ".join(head_parts) head = head + (" " * (size[0]-wcswidth(head)-1)) head_width = wcswidth(head) if head_width > size[0]: head = head[:size[0]-head_width] try: if self.app.config["display"]["invert_status_bars"]: self.header_win.addstr(0, 0, head, curses.color_pair(0) | curses.A_REVERSE) else: self.header_win.addstr(0, 0, head, curses.color_pair(0)) except curses.error: pass self.header_win.refresh()
Example #16
Source File: viewer.py From suplemon with MIT License | 5 votes |
def set_cursor_style(self, cursor_style): """Set cursor style. :param str cursor_style: Cursor type, either 'underline' or 'reverse'. """ if cursor_style == "underline": self.cursor_style = curses.A_UNDERLINE elif cursor_style == "reverse": self.cursor_style = curses.A_REVERSE else: return False return True
Example #17
Source File: zktop.py From python-scripts with GNU General Public License v3.0 | 5 votes |
def resize(self, maxy, maxx): BaseUI.resize(self, maxy, maxx) self.addstr(1, 0, "ID SERVER PORT M OUTST RECVD SENT CONNS MINLAT AVGLAT MAXLAT", curses.A_REVERSE)
Example #18
Source File: test_subreddit.py From rtv with MIT License | 5 votes |
def test_subreddit_page_construct(reddit, terminal, config, oauth): window = terminal.stdscr.subwin with terminal.loader(): page = SubredditPage(reddit, terminal, config, oauth, '/r/python') assert terminal.loader.exception is None page.draw() # Title title = '/r/python'.encode('utf-8') window.addstr.assert_any_call(0, 0, title) # Banner menu = '[1]hot [2]top [3]rising [4]new [5]controversial [6]gilded'.encode('utf-8') window.addstr.assert_any_call(0, 0, menu) # Submission text = page.content.get(0)['split_title'][0].encode('utf-8') window.subwin.addstr.assert_any_call(0, 1, text, 2097152) # Cursor should have been drawn window.subwin.addch.assert_any_call(0, 0, ' ', curses.A_REVERSE) # Reload with a smaller terminal window terminal.stdscr.ncols = 20 terminal.stdscr.nlines = 10 with terminal.loader(): page = SubredditPage(reddit, terminal, config, oauth, '/r/python') assert terminal.loader.exception is None page.draw()
Example #19
Source File: color.py From ci_edit with Apache License 2.0 | 5 votes |
def get(self, colorType, delta=0): if type(colorType) == type(0): colorIndex = colorType else: colorIndex = self.__colorPrefs[colorType] colorIndex = min(self.colors - 1, colorIndex + delta) color = self.__cache.get(colorIndex) or curses.color_pair(colorIndex) self.__cache[colorIndex] = color if colorType in ('error', 'misspelling'): color |= curses.A_BOLD | curses.A_REVERSE return color
Example #20
Source File: test_theme.py From rtv with MIT License | 5 votes |
def test_theme_element_selected_attributes(): elements = { 'Normal': (1, 2, curses.A_REVERSE), 'Selected': (2, 3, None), 'TitleBar': (4, None, curses.A_BOLD), 'Link': (5, None, None)} theme = Theme(elements=elements) assert theme.elements['Normal'] == (1, 2, curses.A_REVERSE) # All of the normal elements fallback to the attributes of "Normal" assert theme.elements['Selected'] == (2, 3, curses.A_REVERSE) assert theme.elements['TitleBar'] == (4, 2, curses.A_BOLD) assert theme.elements['Link'] == (5, 2, curses.A_REVERSE) # The @Selected mode will overwrite any other attributes with # the ones defined in "Selected". Because "Selected" defines # a foreground and a background color, they will override the # ones that "Link" had defined. # assert theme.elements['@Link'] == (2, 3, curses.A_REVERSE) # I can't remember why the above rule was implemented, so I reverted it assert theme.elements['@Link'] == (5, 3, curses.A_REVERSE) assert '@Normal' not in theme.elements assert '@Selected' not in theme.elements assert '@TitleBar' not in theme.elements
Example #21
Source File: status.py From babi with MIT License | 5 votes |
def draw(self, stdscr: 'curses._CursesWindow', margin: Margin) -> None: if margin.footer or self._status: stdscr.insstr(margin.lines - 1, 0, ' ' * margin.cols) if self._status: status = f' {self._status} ' x = (margin.cols - len(status)) // 2 if x < 0: x = 0 status = status.strip() stdscr.insstr(margin.lines - 1, x, status, curses.A_REVERSE)
Example #22
Source File: prompt.py From babi with MIT License | 5 votes |
def _render_prompt(self, *, base: Optional[str] = None) -> None: base = base or self._prompt if not base or self._screen.margin.cols < 7: prompt_s = '' elif len(base) > self._screen.margin.cols - 6: prompt_s = f'{base[:self._screen.margin.cols - 7]}…: ' else: prompt_s = f'{base}: ' width = self._screen.margin.cols - len(prompt_s) line = scrolled_line(self._s, self._x, width) cmd = f'{prompt_s}{line}' prompt_line = self._screen.margin.lines - 1 self._screen.stdscr.insstr(prompt_line, 0, cmd, curses.A_REVERSE) x = len(prompt_s) + self._x - line_x(self._x, width) self._screen.stdscr.move(prompt_line, x)
Example #23
Source File: test_terminal.py From rtv with MIT License | 5 votes |
def test_terminal_attr(terminal): assert terminal.attr('CursorBlock') == 0 assert terminal.attr('@CursorBlock') == curses.A_REVERSE assert terminal.attr('NeutralVote') == curses.A_BOLD with terminal.theme.turn_on_selected(): assert terminal.attr('CursorBlock') == curses.A_REVERSE assert terminal.attr('NeutralVote') == curses.A_BOLD
Example #24
Source File: trailing_whitespace_test.py From babi with MIT License | 5 votes |
def test_trailing_whitespace_highlighting(run, tmpdir): f = tmpdir.join('f') f.write('0123456789 \n') with run(str(f), term='screen-256color', width=20) as h, and_exit(h): h.await_text('123456789') h.assert_screen_attr_equals(0, [(-1, -1, curses.A_REVERSE)] * 20) attrs = [(-1, -1, 0)] * 10 + [(-1, 1, 0)] * 5 + [(-1, -1, 0)] * 5 h.assert_screen_attr_equals(1, attrs)
Example #25
Source File: syntax_highlight_test.py From babi with MIT License | 5 votes |
def test_syntax_highlighting(run, demo): with run(str(demo), term='screen-256color', width=20) as h, and_exit(h): h.await_text('still more') for i, attr in enumerate([ [(236, 40, curses.A_REVERSE)] * 20, # header [(52, 203, 0)] * 5 + [(236, 40, 0)] * 15, # - foo [(243, 40, 0)] * 14 + [(236, 40, 0)] * 6, # # comment here [(236, 40, 0)] * 20, # uncolored [(17, 40, 0)] * 7 + [(236, 40, 0)] * 13, # """tqs! [(17, 40, 0)] * 10 + [(236, 40, 0)] * 10, # still more [(17, 40, 0)] * 3 + [(236, 40, 0)] * 17, # """ ]): h.assert_screen_attr_equals(i, attr)
Example #26
Source File: runner.py From babi with MIT License | 5 votes |
def to_attrs(screen, width): fg = bg = -1 attr = 0 idx = 0 ret: List[List[Tuple[int, int, int]]] ret = [[] for _ in range(len(screen.splitlines()))] for tp, match in tokenize_colors(screen): if tp is Token.FG_ESC: fg = int(match[1]) elif tp is Token.BG_ESC: bg = int(match[1]) elif tp is Token.RESET: fg = bg = -1 attr = 0 elif tp is Token.ESC: if match[1] == '7': attr |= curses.A_REVERSE elif match[1] == '39': fg = -1 elif match[1] == '49': bg = -1 elif 40 <= int(match[1]) <= 47: bg = int(match[1]) - 40 else: raise AssertionError(f'unknown escape {match[1]}') elif tp is Token.NL: ret[idx].extend([(fg, bg, attr)] * (width - len(ret[idx]))) idx += 1 elif tp is Token.CHAR: ret[idx].append((fg, bg, attr)) else: raise AssertionError(f'unreachable {tp} {match}') return ret
Example #27
Source File: block.py From bitcoind-ncurses with MIT License | 5 votes |
def draw_transactions(state): window_height = state['y'] - 6 win_transactions = curses.newwin(window_height, 75, 5, 0) height = str(state['blocks']['browse_height']) blockdata = state['blocks'][height] tx_count = len(blockdata['tx']) bytes_per_tx = blockdata['size'] / tx_count win_transactions.addstr(0, 1, "Transactions: " + ("% 4d" % tx_count + " (" + str(bytes_per_tx) + " bytes/tx)").ljust(26) + "(UP/DOWN: scroll, ENTER: view)", curses.A_BOLD + curses.color_pair(5)) # reset cursor if it's been resized off the bottom if state['blocks']['cursor'] > state['blocks']['offset'] + (window_height-2): state['blocks']['offset'] = state['blocks']['cursor'] - (window_height-2) offset = state['blocks']['offset'] for index in range(offset, offset+window_height-1): if index < len(blockdata['tx']): if index == state['blocks']['cursor']: win_transactions.addstr(index+1-offset, 1, ">", curses.A_REVERSE + curses.A_BOLD) condition = (index == offset+window_height-2) and (index+1 < len(blockdata['tx'])) condition = condition or ( (index == offset) and (index > 0) ) if condition: win_transactions.addstr(index+1-offset, 3, "...") else: win_transactions.addstr(index+1-offset, 3, blockdata['tx'][index]) win_transactions.refresh()
Example #28
Source File: example_simple.py From PyZwaver with GNU General Public License v3.0 | 5 votes |
def _titleyx(self, y: int, x: int, line, w=80): if len(line) < w: line += " " * (w - len(line)) return self._printyx(y, x, [line], curses.A_REVERSE | curses.A_BOLD)
Example #29
Source File: iotop.py From psutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def print_line(line, highlight=False): """A thin wrapper around curses's addstr().""" global lineno try: if highlight: line += " " * (win.getmaxyx()[1] - len(line)) win.addstr(lineno, 0, line, curses.A_REVERSE) else: win.addstr(lineno, 0, line, 0) except curses.error: lineno = 0 win.refresh() raise else: lineno += 1
Example #30
Source File: nettop.py From psutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def print_line(line, highlight=False): """A thin wrapper around curses's addstr().""" global lineno try: if highlight: line += " " * (win.getmaxyx()[1] - len(line)) win.addstr(lineno, 0, line, curses.A_REVERSE) else: win.addstr(lineno, 0, line, 0) except curses.error: lineno = 0 win.refresh() raise else: lineno += 1