Python curses.A_UNDERLINE Examples
The following are 22
code examples of curses.A_UNDERLINE().
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: formattedText.py From PathPicker with MIT License | 6 votes |
def parseFormatting(cls, formatting): """Parse ANSI formatting; the formatting passed in should be stripped of the control characters and ending character""" fore = -1 # -1 default means "use default", not "use white/black" back = -1 other = 0 intValues = [int(value) for value in formatting.split(';') if value] for code in intValues: if (code >= cls.FOREGROUND_RANGE.bottom and code <= cls.FOREGROUND_RANGE.top): fore = code - cls.FOREGROUND_RANGE.bottom elif (code >= cls.BACKGROUND_RANGE.bottom and code <= cls.BACKGROUND_RANGE.top): back = code - cls.BACKGROUND_RANGE.bottom elif code == cls.BOLD_ATTRIBUTE: other = other | curses.A_BOLD elif code == cls.UNDERLINE_ATTRIBUTE: other = other | curses.A_UNDERLINE return (fore, back, other)
Example #2
Source File: graphics.py From costar_plan with Apache License 2.0 | 6 votes |
def drawWorld(self, world, draw_actors=True): for i in range(world.worldmap.shape[0]): for j in range(world.worldmap.shape[1]): if world.worldmap[i, j] == W.DirectionEast: self.stdscr.addstr(i, j, '>', curses.color_pair(0)) elif world.worldmap[i, j] == W.DirectionWest: self.stdscr.addstr(i, j, '<', curses.color_pair(0)) elif world.worldmap[i, j] == W.DirectionNorth: self.stdscr.addstr(i, j, '^', curses.color_pair(0)) elif world.worldmap[i, j] == W.DirectionSouth: self.stdscr.addstr(i, j, 'v', curses.color_pair(0)) elif world.worldmap[i, j] == W.Sidewalk: self.stdscr.addstr(i, j, '#', curses.color_pair(0)) elif world.worldmap[i, j] == W.Intersection: self.stdscr.addstr(i, j, 'X', curses.color_pair(0)) else: self.stdscr.addstr(i, j, ' ') if draw_actors: for actor in world.actors: if actor.state.x >= 0 and actor.state.y >= 0: self.stdscr.addstr( actor.state.y, actor.state.x, actor.name, curses.color_pair(1) + curses.A_BOLD + curses.A_UNDERLINE) self.bottom_row = i
Example #3
Source File: syntax.py From babi with MIT License | 5 votes |
def attr(self, style: Style) -> int: pair = self._color_manager.color_pair(style.fg, style.bg) return ( curses.color_pair(pair) | curses.A_BOLD * style.b | A_ITALIC * style.i | curses.A_UNDERLINE * style.u )
Example #4
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 #5
Source File: curses_ui.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def _screen_color_init(self): """Initialization of screen colors.""" curses.start_color() curses.use_default_colors() self._color_pairs = {} color_index = 0 # Prepare color pairs. for fg_color in self._FOREGROUND_COLORS: for bg_color in self._BACKGROUND_COLORS: color_index += 1 curses.init_pair(color_index, self._FOREGROUND_COLORS[fg_color], self._BACKGROUND_COLORS[bg_color]) color_name = fg_color if bg_color != "transparent": color_name += "_on_" + bg_color self._color_pairs[color_name] = curses.color_pair(color_index) # Try getting color(s) available only under 256-color support. try: color_index += 1 curses.init_pair(color_index, 245, -1) self._color_pairs[cli_shared.COLOR_GRAY] = curses.color_pair(color_index) except curses.error: # Use fall-back color(s): self._color_pairs[cli_shared.COLOR_GRAY] = ( self._color_pairs[cli_shared.COLOR_GREEN]) # A_BOLD or A_BLINK is not really a "color". But place it here for # convenience. self._color_pairs["bold"] = curses.A_BOLD self._color_pairs["blink"] = curses.A_BLINK self._color_pairs["underline"] = curses.A_UNDERLINE # Default color pair to use when a specified color pair does not exist. self._default_color_pair = self._color_pairs[cli_shared.COLOR_WHITE]
Example #6
Source File: curses_display.py From anyMesh-Python with MIT License | 5 votes |
def _setattr(self, a): if a is None: self.s.attrset(0) return elif not isinstance(a, AttrSpec): p = self._palette.get(a, (AttrSpec('default', 'default'),)) a = p[0] if self.has_color: if a.foreground_basic: if a.foreground_number >= 8: fg = a.foreground_number - 8 else: fg = a.foreground_number else: fg = 7 if a.background_basic: bg = a.background_number else: bg = 0 attr = curses.color_pair(bg * 8 + 7 - fg) else: attr = 0 if a.bold: attr |= curses.A_BOLD if a.standout: attr |= curses.A_STANDOUT if a.underline: attr |= curses.A_UNDERLINE if a.blink: attr |= curses.A_BLINK self.s.attrset(attr)
Example #7
Source File: window.py From lyrics-in-terminal with MIT License | 5 votes |
def add_text(self): self.win.refresh() h, w = self.win.getmaxyx() self.win.addstr(3, 3, 'Help Page', curses.A_BOLD | curses.A_UNDERLINE) self.win.addstr(h - 2, 3, f"{'Press any key to exit...':>{w-5}}") keys = { curses.KEY_UP : '↑', curses.KEY_DOWN : '↓', curses.KEY_LEFT: '←', curses.KEY_RIGHT: '→', } # keybinds i, j = 6, 3 self.win.addstr(i, j, 'Keybindings', curses.A_UNDERLINE) i += 2 i = self.add_config(i, j, self.keybinds, keys) # options if w // 2 >= 30: i, j = 6, w // 2 else: i += 2 self.win.addstr(i, j, 'Default Options', curses.A_UNDERLINE) i+= 2 self.add_config(i, j, self.options, keys)
Example #8
Source File: test_theme.py From rtv with MIT License | 5 votes |
def test_theme_256_construct(): elements = {'CursorBar1': (None, 101, curses.A_UNDERLINE)} theme = Theme(elements=elements) assert theme.elements['CursorBar1'] == (-1, 101, curses.A_UNDERLINE) assert theme.required_colors == 256
Example #9
Source File: ui.py From oandapybot with MIT License | 5 votes |
def Render(self): self.stdscr.erase() self.stdscr.addstr(0,0,"OANDA bot",curses.A_UNDERLINE) # Current account status self.stdscr.addstr(2,0,"Account currency: "+self._account_currency) self.stdscr.addstr(3,0,"Trading instrument: "+self._instrument) # Ticker and heartbeat self.stdscr.addstr(5,0,"Heartbeat: "+self._heartbeatTime) self.stdscr.addstr(6,0,"Ticker: "+str(self._currentPrice)) # Account status self.stdscr.addstr(8, 0,"Position: "+self._currentPosition + " " + self._currentPositionSide) self.stdscr.addstr(9, 0,"Balance: "+self._balance) self.stdscr.addstr(10,0,"Available units: "+self._availableUnits) self.stdscr.addstr(11,0,"Cash invested: "+self._cashInvested + " leverage: "+self._leverage) self.stdscr.addstr(12,0,"Net Worth: "+self._netWorth + " unrealized PnL: "+self._unrealizedPnL) # Strategy status self.stdscr.addstr(14,0,"Stop Loss price: "+str(self._stoploss_price)) self.stdscr.addstr(15,0,"Trailing Stop price: "+str(self._trailingstop_price)) if self._strategy.TradingStatus(): status = "running" else: status = "paused" self.stdscr.addstr(16,0,"Strategy status: "+status) self.stdscr.addstr(18,0,"Available actions:", curses.A_UNDERLINE) if self._strategy.TradingStatus(): command = "(P)ause - pause strategy. Disable trading, but keep tickers coming" else: command = "(R)esume - resume strategy. Reenable trading" self.stdscr.addstr(19,0,command) self.stdscr.addstr(20,0,"(B)uy - take long position on instrument") self.stdscr.addstr(21,0,"(S)ell - take short position on instrument") self.stdscr.addstr(22,0,"(C)lose - close position on instrument") self.stdscr.addstr(23,0,"(Q)uit - exit") self.stdscr.refresh()
Example #10
Source File: screen.py From wpm with GNU Affero General Public License v3.0 | 5 votes |
def set_colors(self): """Sets up curses color pairs.""" hicolor = os.getenv("TERM").endswith("256color") if self.monochrome: color = self.config.monochromecolors elif hicolor: color = self.config.xterm256colors else: color = self.config.xtermcolors bg = color.background curses.init_pair(Screen.COLOR_AUTHOR, *color.author) curses.init_pair(Screen.COLOR_BACKGROUND, bg, bg) curses.init_pair(Screen.COLOR_CORRECT, *color.correct) curses.init_pair(Screen.COLOR_HISCORE, *color.score) curses.init_pair(Screen.COLOR_INCORRECT, *color.incorrect) curses.init_pair(Screen.COLOR_PROMPT, *color.prompt) curses.init_pair(Screen.COLOR_QUOTE, *color.quote) curses.init_pair(Screen.COLOR_STATUS, *color.top_bar) # Rebind class variables Screen.COLOR_AUTHOR = curses.color_pair(Screen.COLOR_AUTHOR) Screen.COLOR_BACKGROUND = curses.color_pair(Screen.COLOR_BACKGROUND) Screen.COLOR_CORRECT = curses.color_pair(Screen.COLOR_CORRECT) Screen.COLOR_HISCORE = curses.color_pair(Screen.COLOR_HISCORE) Screen.COLOR_INCORRECT = curses.color_pair(Screen.COLOR_INCORRECT) Screen.COLOR_PROMPT = curses.color_pair(Screen.COLOR_PROMPT) Screen.COLOR_QUOTE = curses.color_pair(Screen.COLOR_QUOTE) Screen.COLOR_STATUS = curses.color_pair(Screen.COLOR_STATUS) if not hicolor: # Make certain colors more visible Screen.COLOR_CORRECT |= curses.A_DIM Screen.COLOR_INCORRECT |= curses.A_UNDERLINE | curses.A_BOLD Screen.COLOR_QUOTE |= curses.A_BOLD Screen.COLOR_STATUS |= curses.A_BOLD
Example #11
Source File: curses_ui.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _screen_init(self): """Screen initialization. Creates curses stdscr and initialize the color pairs for display. """ self._stdscr = curses.initscr() self._command_window = None # Prepare color pairs. curses.start_color() self._color_pairs = {} color_index = 0 for fg_color in self._FOREGROUND_COLORS: for bg_color in self._BACKGROUND_COLORS: color_index += 1 curses.init_pair(color_index, self._FOREGROUND_COLORS[fg_color], self._BACKGROUND_COLORS[bg_color]) color_name = fg_color if bg_color != "black": color_name += "_on_" + bg_color self._color_pairs[color_name] = curses.color_pair(color_index) # A_BOLD or A_BLINK is not really a "color". But place it here for # convenience. self._color_pairs["bold"] = curses.A_BOLD self._color_pairs["blink"] = curses.A_BLINK self._color_pairs["underline"] = curses.A_UNDERLINE # Default color pair to use when a specified color pair does not exist. self._default_color_pair = self._color_pairs["white"]
Example #12
Source File: curses_ui.py From lambda-packs with MIT License | 5 votes |
def _screen_color_init(self): """Initialization of screen colors.""" curses.start_color() curses.use_default_colors() self._color_pairs = {} color_index = 0 # Prepare color pairs. for fg_color in self._FOREGROUND_COLORS: for bg_color in self._BACKGROUND_COLORS: color_index += 1 curses.init_pair(color_index, self._FOREGROUND_COLORS[fg_color], self._BACKGROUND_COLORS[bg_color]) color_name = fg_color if bg_color != "transparent": color_name += "_on_" + bg_color self._color_pairs[color_name] = curses.color_pair(color_index) # Try getting color(s) available only under 256-color support. try: color_index += 1 curses.init_pair(color_index, 245, -1) self._color_pairs[cli_shared.COLOR_GRAY] = curses.color_pair(color_index) except curses.error: # Use fall-back color(s): self._color_pairs[cli_shared.COLOR_GRAY] = ( self._color_pairs[cli_shared.COLOR_GREEN]) # A_BOLD or A_BLINK is not really a "color". But place it here for # convenience. self._color_pairs["bold"] = curses.A_BOLD self._color_pairs["blink"] = curses.A_BLINK self._color_pairs["underline"] = curses.A_UNDERLINE # Default color pair to use when a specified color pair does not exist. self._default_color_pair = self._color_pairs[cli_shared.COLOR_WHITE]
Example #13
Source File: listbox.py From plasma with GNU General Public License v3.0 | 5 votes |
def print_line(self, i): num_line = self.win_y + i is_current_line = self.cursor_y == i and self.has_focus force_exit = False x = 0 for (string, col, is_bold) in self.token_lines[num_line]: if x + len(string) >= self.width - 1: string = string[:self.width - x - 1] force_exit = True c = color_pair(col) if is_current_line: c |= A_UNDERLINE if is_bold: c |= curses.A_BOLD self.screen.addstr(i, x, string, c) x += len(string) if force_exit: break if is_current_line and not force_exit: n = self.width - x - 1 self.screen.addstr(i, x, " " * n, color_pair(0) | A_UNDERLINE) x += n self.highlight_search(i) self.screen.move(i, x)
Example #14
Source File: gui.py From ffw with GNU General Public License v3.0 | 5 votes |
def initCurses(): screen = curses.initscr() curses.noecho() # disable the keypress echo to prevent double input curses.cbreak() # disable line buffers to run the keypress immediately curses.curs_set(0) screen.keypad(1) # enable keyboard use screen.addstr(1, 2, "Fuzzing For Worms", curses.A_UNDERLINE) return screen
Example #15
Source File: curses_ui.py From keras-lambda with MIT License | 5 votes |
def _screen_init(self): """Screen initialization. Creates curses stdscr and initialize the color pairs for display. """ self._stdscr = curses.initscr() self._command_window = None # Prepare color pairs. curses.start_color() self._color_pairs = {} color_index = 0 for fg_color in self._FOREGROUND_COLORS: for bg_color in self._BACKGROUND_COLORS: color_index += 1 curses.init_pair(color_index, self._FOREGROUND_COLORS[fg_color], self._BACKGROUND_COLORS[bg_color]) color_name = fg_color if bg_color != "black": color_name += "_on_" + bg_color self._color_pairs[color_name] = curses.color_pair(color_index) # A_BOLD or A_BLINK is not really a "color". But place it here for # convenience. self._color_pairs["bold"] = curses.A_BOLD self._color_pairs["blink"] = curses.A_BLINK self._color_pairs["underline"] = curses.A_UNDERLINE # Default color pair to use when a specified color pair does not exist. self._default_color_pair = self._color_pairs["white"]
Example #16
Source File: wgtexttokens.py From TelegramTUI with MIT License | 4 votes |
def update(self, clear=True, cursor=True): if clear: self.clear() if self.begin_at < 0: self.begin_at = 0 if self.left_margin >= self.maximum_string_length: raise ValueError if self.cursor_position < 0: self.cursor_position = 0 if self.cursor_position > len(self.value): self.cursor_position = len(self.value) if self.cursor_position < self.begin_at: self.begin_at = self.cursor_position while self.find_cursor_offset_on_screen(self.cursor_position) > \ self.find_cursor_offset_on_screen(self.begin_at) + \ self.maximum_string_length - self.left_margin -1: # -1: self.begin_at += 1 text, highlighting = self.get_literal_text_to_display(start_at=self.begin_at) if self.do_colors(): if self.important: color = self.parent.theme_manager.findPair(self, 'IMPORTANT') | curses.A_BOLD else: color = self.parent.theme_manager.findPair(self, self.color) if self.show_bold: color = color | curses.A_BOLD if self.highlight: if not self.editing: color = color | curses.A_STANDOUT else: color = color | curses.A_UNDERLINE highlighting = [color for c in highlighting if c == curses.A_NORMAL] else: color = curses.A_NORMAL if self.important or self.show_bold: color = color | curses.A_BOLD if self.important: color = color | curses.A_UNDERLINE if self.highlight: if not self.editing: color = color | curses.A_STANDOUT else: color = color | curses.A_UNDERLINE highlighting = [color for c in highlighting if c == curses.A_NORMAL] self._print(text, highlighting) if self.editing and cursor: self.print_cursor()
Example #17
Source File: wgtexttokens.py From HomePWN with GNU General Public License v3.0 | 4 votes |
def update(self, clear=True, cursor=True): if clear: self.clear() if self.begin_at < 0: self.begin_at = 0 if self.left_margin >= self.maximum_string_length: raise ValueError if self.cursor_position < 0: self.cursor_position = 0 if self.cursor_position > len(self.value): self.cursor_position = len(self.value) if self.cursor_position < self.begin_at: self.begin_at = self.cursor_position while self.find_cursor_offset_on_screen(self.cursor_position) > \ self.find_cursor_offset_on_screen(self.begin_at) + \ self.maximum_string_length - self.left_margin -1: # -1: self.begin_at += 1 text, highlighting = self.get_literal_text_to_display(start_at=self.begin_at) if self.do_colors(): if self.important: color = self.parent.theme_manager.findPair(self, 'IMPORTANT') | curses.A_BOLD else: color = self.parent.theme_manager.findPair(self, self.color) if self.show_bold: color = color | curses.A_BOLD if self.highlight: if not self.editing: color = color | curses.A_STANDOUT else: color = color | curses.A_UNDERLINE highlighting = [color for c in highlighting if c == curses.A_NORMAL] else: color = curses.A_NORMAL if self.important or self.show_bold: color = color | curses.A_BOLD if self.important: color = color | curses.A_UNDERLINE if self.highlight: if not self.editing: color = color | curses.A_STANDOUT else: color = color | curses.A_UNDERLINE highlighting = [color for c in highlighting if c == curses.A_NORMAL] self._print(text, highlighting) if self.editing and cursor: self.print_cursor()
Example #18
Source File: viewer.py From suplemon with MIT License | 4 votes |
def __init__(self, app, window): """ Handle Viewer initialization :param App app: The main App class of Suplemon :param Window window: The ui window to use for the viewer """ self.app = app self.window = window self.logger = logging.getLogger(__name__) self.config = {} self.data = "" self.lines = [Line()] self.file_extension = "" # Map special extensions to generic ones for highlighting self.extension_map = { "scss": "css", "less": "css", "tmtheme": "xml", "ts": "js", } self.show_line_ends = True self.cursor_style = curses.A_UNDERLINE self.y_scroll = 0 self.x_scroll = 0 self.cursors = [Cursor()] # Copy/paste buffer self.buffer = [] # Last search used in 'find' self.last_find = "" # Runnable methods self.operations = { "arrow_right": self.arrow_right, # Arrow Right "arrow_left": self.arrow_left, # Arrow Left "arrow_up": self.arrow_up, # Arrow Up "arrow_down": self.arrow_down, # Arrow Down "jump_left": self.jump_left, # Ctrl + Left "jump_right": self.jump_right, # Ctrl + Right "jump_up": self.jump_up, # Ctrl + Up "jump_down": self.jump_down, # Ctrl + Down "page_up": self.page_up, # Page Up "page_down": self.page_down, # Page Down "home": self.home, # Home "end": self.end, # End "find": self.find_query, # Ctrl + F "find_next": self.find_next, # Ctrl + D "find_all": self.find_all, # Ctrl + A } self.pygments_syntax = None # Needs to be implemented in derived classes self.lexer = None # Needs to be implemented in derived classes
Example #19
Source File: wgtexttokens.py From EDCOP with Apache License 2.0 | 4 votes |
def update(self, clear=True, cursor=True): if clear: self.clear() if self.begin_at < 0: self.begin_at = 0 if self.left_margin >= self.maximum_string_length: raise ValueError if self.cursor_position < 0: self.cursor_position = 0 if self.cursor_position > len(self.value): self.cursor_position = len(self.value) if self.cursor_position < self.begin_at: self.begin_at = self.cursor_position while self.find_cursor_offset_on_screen(self.cursor_position) > \ self.find_cursor_offset_on_screen(self.begin_at) + \ self.maximum_string_length - self.left_margin -1: # -1: self.begin_at += 1 text, highlighting = self.get_literal_text_to_display(start_at=self.begin_at) if self.do_colors(): if self.important: color = self.parent.theme_manager.findPair(self, 'IMPORTANT') | curses.A_BOLD else: color = self.parent.theme_manager.findPair(self, self.color) if self.show_bold: color = color | curses.A_BOLD if self.highlight: if not self.editing: color = color | curses.A_STANDOUT else: color = color | curses.A_UNDERLINE highlighting = [color for c in highlighting if c == curses.A_NORMAL] else: color = curses.A_NORMAL if self.important or self.show_bold: color = color | curses.A_BOLD if self.important: color = color | curses.A_UNDERLINE if self.highlight: if not self.editing: color = color | curses.A_STANDOUT else: color = color | curses.A_UNDERLINE highlighting = [color for c in highlighting if c == curses.A_NORMAL] self._print(text, highlighting) if self.editing and cursor: self.print_cursor()
Example #20
Source File: top.py From python-alerta-client with Apache License 2.0 | 4 votes |
def update(self): self.lines, self.cols = self.screen.getmaxyx() self.screen.clear() now = datetime.utcnow() status = self.client.mgmt_status() version = status['version'] # draw header self._addstr(0, 0, self.client.endpoint, curses.A_BOLD) self._addstr(0, 'C', 'alerta {}'.format(version), curses.A_BOLD) self._addstr(0, 'R', '{}'.format(now.strftime('%H:%M:%S %d/%m/%y')), curses.A_BOLD) # TODO - draw bars # draw alerts text_width = self.cols - 95 if self.cols >= 95 else 0 self._addstr(2, 1, 'Sev. Time Dupl. Customer Env. Service Resource Group Event' + ' Value Text' + ' ' * (text_width - 4), curses.A_UNDERLINE) def short_sev(severity): return self.SEVERITY_MAP.get(severity, self.SEVERITY_MAP['unknown'])[0] def color(severity): return self.SEVERITY_MAP.get(severity, self.SEVERITY_MAP['unknown'])[1] r = self.client.http.get('/alerts') alerts = [Alert.parse(a) for a in r['alerts']] last_time = DateTime.parse(r['lastTime']) for i, alert in enumerate(alerts): row = i + 3 if row >= self.lines - 2: # leave room for footer break text = '{:<4} {} {:5d} {:8.8} {:<12} {:<12} {:<12.12} {:5.5} {:<12.12} {:<5.5} {:.{width}}'.format( short_sev(alert.severity), DateTime.localtime(alert.last_receive_time, self.timezone, fmt='%H:%M:%S'), alert.duplicate_count, alert.customer or '-', alert.environment, ','.join(alert.service), alert.resource, alert.group, alert.event, alert.value or 'n/a', alert.text, width=text_width ) # XXX - needed to support python2 and python3 if not isinstance(text, str): text = text.encode('ascii', errors='replace') self._addstr(row, 1, text, color(alert.severity)) # draw footer self._addstr(self.lines - 1, 0, 'Last Update: {}'.format(last_time.strftime('%H:%M:%S')), curses.A_BOLD) self._addstr(self.lines - 1, 'C', '{} - {}'.format(r['status'], r.get('message', 'no errors')), curses.A_BOLD) self._addstr(self.lines - 1, 'R', 'Count: {}'.format(r['total']), curses.A_BOLD) self.screen.refresh()
Example #21
Source File: wgtexttokens.py From apple_bleee with GNU General Public License v3.0 | 4 votes |
def update(self, clear=True, cursor=True): if clear: self.clear() if self.begin_at < 0: self.begin_at = 0 if self.left_margin >= self.maximum_string_length: raise ValueError if self.cursor_position < 0: self.cursor_position = 0 if self.cursor_position > len(self.value): self.cursor_position = len(self.value) if self.cursor_position < self.begin_at: self.begin_at = self.cursor_position while self.find_cursor_offset_on_screen(self.cursor_position) > \ self.find_cursor_offset_on_screen(self.begin_at) + \ self.maximum_string_length - self.left_margin -1: # -1: self.begin_at += 1 text, highlighting = self.get_literal_text_to_display(start_at=self.begin_at) if self.do_colors(): if self.important: color = self.parent.theme_manager.findPair(self, 'IMPORTANT') | curses.A_BOLD else: color = self.parent.theme_manager.findPair(self, self.color) if self.show_bold: color = color | curses.A_BOLD if self.highlight: if not self.editing: color = color | curses.A_STANDOUT else: color = color | curses.A_UNDERLINE highlighting = [color for c in highlighting if c == curses.A_NORMAL] else: color = curses.A_NORMAL if self.important or self.show_bold: color = color | curses.A_BOLD if self.important: color = color | curses.A_UNDERLINE if self.highlight: if not self.editing: color = color | curses.A_STANDOUT else: color = color | curses.A_UNDERLINE highlighting = [color for c in highlighting if c == curses.A_NORMAL] self._print(text, highlighting) if self.editing and cursor: self.print_cursor()
Example #22
Source File: fm_cli.py From baidufm-py with MIT License | 4 votes |
def login(self): username = self.api.is_login() if username: if isinstance(username, unicode): username = username.encode('utf-8') self.footer.write('%s 已登录.' % username) return curses.echo() self.login_win.erase() self.login_win.addstr(0, 2, "Username: ", curses.color_pair(1)) self.login_win.addstr(1, 2, " " * 43, curses.A_UNDERLINE) username = self.login_win.getstr(1, 2) password = '' if len(username) > 0: self.login_win.addstr(3, 2, "Password: ", curses.color_pair(1)) self.login_win.addstr(4, 2, " " * 43, curses.A_UNDERLINE) password = self.login_win.getstr(4, 2) fm_log(logger, "USERNAME: %s, PWD: %s", username, '*****') if username and password: try: result = self.api.login(username, password, '') login_count = 0 if result: while True: login_count += 1 try: image_to_display(self.login_win, result, 8) except: pass self.login_win.addstr(6, 2, "Captcha(%s): " % result, curses.color_pair(1)) self.login_win.addstr(7, 2, " " * 43, curses.A_UNDERLINE) captcha = self.login_win.getstr(7, 2) result = self.api.login(username, password, captcha) if not result or login_count > 3: break if not result: if isinstance(username, unicode): username = username.encode('utf-8') self.footer.write('%s 登录成功.' % username) except Exception as e: fm_log(logger, "Login error. %s", str(e.args)) self.refresh_body()