Python curses.init_pair() Examples
The following are 30
code examples of curses.init_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: interface.py From bitcoind-ncurses with MIT License | 8 votes |
def init_curses(): window = curses.initscr() curses.noecho() # prevents user input from being echoed curses.curs_set(0) # make cursor invisible curses.start_color() curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_MAGENTA, curses.COLOR_BLACK) curses.init_pair(5, curses.COLOR_YELLOW, curses.COLOR_BLACK) window.timeout(50) window.keypad(1) # interpret arrow keys, etc return window
Example #2
Source File: CLI.py From email_hack with MIT License | 7 votes |
def init_curses(self): """Setup the curses""" self.window = curses.initscr() self.height, self.width = self.window.getmaxyx() if self.width < 60: self.too_small = True return self.window.keypad(True) # self.window.nodelay(True) curses.noecho() curses.curs_set(False) curses.cbreak() curses.start_color() curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_CYAN)
Example #3
Source File: ui.py From scorer.py with GNU General Public License v2.0 | 6 votes |
def main(stdscr, matches): curses.curs_set(False) selected = 0 curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) while True: printGames(stdscr, matches, selected) event = stdscr.getch() if event == ord("\n"): logging.info("Enter key pressed") return selected elif event == curses.KEY_UP: logging.info("Up key pressed") if selected != 0: selected -= 1 printGames(stdscr, matches, selected) elif event == curses.KEY_DOWN: logging.info("Down key pressed") if selected != len(matches) - 1: selected += 1 printGames(stdscr, matches, selected)
Example #4
Source File: termdown.py From termdown with GNU General Public License v3.0 | 6 votes |
def setup(stdscr): # curses curses.use_default_colors() curses.init_pair(1, curses.COLOR_RED, -1) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_RED) curses.init_pair(3, curses.COLOR_GREEN, -1) curses.init_pair(4, -1, curses.COLOR_RED) try: curses.curs_set(False) except curses.error: # fails on some terminals pass stdscr.timeout(0) # prepare input thread mechanisms curses_lock = Lock() input_queue = Queue() quit_event = Event() return (curses_lock, input_queue, quit_event)
Example #5
Source File: __init__.py From py_cui with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #6
Source File: space_invaders.py From sqlalchemy with MIT License | 6 votes |
def setup_curses(): """Setup terminal/curses state.""" window = curses.initscr() curses.noecho() window = curses.newwin( WINDOW_HEIGHT + (VERT_PADDING * 2), WINDOW_WIDTH + (HORIZ_PADDING * 2), WINDOW_TOP - VERT_PADDING, WINDOW_LEFT - HORIZ_PADDING, ) curses.start_color() global _COLOR_PAIRS _COLOR_PAIRS = {} for i, (k, v) in enumerate(COLOR_MAP.items(), 1): curses.init_pair(i, v, curses.COLOR_BLACK) _COLOR_PAIRS[k] = curses.color_pair(i) return window
Example #7
Source File: console.py From fluxclient with GNU Affero General Public License v3.0 | 6 votes |
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 #8
Source File: curses_display.py From anyMesh-Python with MIT License | 6 votes |
def _setup_colour_pairs(self): """ Initialize all 63 color pairs based on the term: bg * 8 + 7 - fg So to get a color, we just need to use that term and get the right color pair number. """ if not self.has_color: return for fg in xrange(8): for bg in xrange(8): # leave out white on black if fg == curses.COLOR_WHITE and \ bg == curses.COLOR_BLACK: continue curses.init_pair(bg * 8 + 7 - fg, fg, bg)
Example #9
Source File: lcd.py From bitnodes-hardware with MIT License | 6 votes |
def show(self, screen): self.screen = screen curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK) self.white = curses.color_pair(1) curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) self.green = curses.color_pair(2) curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK) self.yellow = curses.color_pair(3) curses.init_pair(4, curses.COLOR_RED, curses.COLOR_BLACK) self.red = curses.color_pair(4) curses.curs_set(0) self.addstr(1, 1, 'BITNODES HARDWARE', self.white) self.addstr(1, 19, 'LOADING', self.yellow) while True: time.sleep(self.update())
Example #10
Source File: app.py From toot with GNU General Public License v3.0 | 6 votes |
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 #11
Source File: gcore_box.py From gaycore with MIT License | 6 votes |
def _init_curses(self): self.stdscr = curses.initscr() self.stdscr.keypad(1) curses.noecho() curses.cbreak() curses.curs_set(0) curses.start_color() try: curses.init_pair(1, curses.COLOR_BLACK, 197) # 接近机核主题的颜色 except: # 树莓派 windows无法使用机核like色 curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_RED) curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK) self.stdscr.bkgd(curses.color_pair(2)) self.stdscr.timeout(100) self.stdscr.refresh()
Example #12
Source File: clockr.py From clockr with MIT License | 6 votes |
def getcolor(): """color selection""" colors = { "red": 1, "green": 2, "yellow": 3, "blue": 4, "magenta": 5, "cyan": 6, "white": 7, "orange": 9, "random": random.randint(1, 255) } if color is not None and color.lower() in colors.keys(): curses.init_pair(1, 0, -1) curses.init_pair(2, colors[color], -1) curses.init_pair(3, 0, colors[color]) else: pass
Example #13
Source File: raspcloud.py From RaspberryCloud with GNU General Public License v3.0 | 6 votes |
def main(): screen = init_curses() y, x = screen.getmaxyx() # create green curses.init_pair(1, curses.COLOR_GREEN, -1) # create red curses.init_pair(2, curses.COLOR_RED, -1) # -1 is default bcgd color # create white curses.init_pair(3, curses.COLOR_WHITE, -1) # create cyan curses.init_pair(4, curses.COLOR_CYAN, -1) # create yellow curses.init_pair(5, curses.COLOR_YELLOW, -1) # create black on white curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_WHITE) # print the splash screen out! splash_screen(screen, y, x) # check and see if this program is being run by itself # if so call the main function
Example #14
Source File: python_pick.py From NSC_BUILDER with MIT License | 5 votes |
def config_curses(self): # use the default colors of the terminal curses.use_default_colors() # hide the cursor curses.curs_set(0) #add some color for multi_select #@todo make colors configurable curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_WHITE)
Example #15
Source File: theme.py From rtv 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
Example #16
Source File: colors.py From pipenv-pipes with MIT License | 5 votes |
def __init__(self, index, fg, bg): self.index = index curses.init_pair(index, fg, bg)
Example #17
Source File: menu_screen.py From botany with ISC License | 5 votes |
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 #18
Source File: cursesAPI.py From PathPicker with MIT License | 5 votes |
def initPair(self, pairNumber, fg, bg): return curses.init_pair(pairNumber, fg, bg)
Example #19
Source File: __init__.py From pick with MIT License | 5 votes |
def config_curses(self): try: # use the default colors of the terminal curses.use_default_colors() # hide the cursor curses.curs_set(0) # add some color for multi_select # @todo make colors configurable curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_WHITE) except: # Curses failed to initialize color support, eg. when TERM=vt100 curses.initscr()
Example #20
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 #21
Source File: npysThemeManagers.py From TelegramTUI with MIT License | 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 #22
Source File: curses_menu.py From GPIOnext 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 #23
Source File: npysThemeManagers.py From HomePWN 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 #24
Source File: tui.py From wifiphisher with GNU General Public License v3.0 | 5 votes |
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 #25
Source File: terminal_dungeon.py From terminal_dungeon with MIT License | 5 votes |
def init_curses(screen): curses.curs_set(0) curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) screen.attron(curses.color_pair(1))
Example #26
Source File: tui.py From wifiphisher with GNU General Public License v3.0 | 5 votes |
def gather_info(self, screen, info): """ Get the information from pywifiphisher and print them out :param self: A TuiApSel object :type self: TuiApSel :param screen: A curses window object :type screen: _curses.curses.window :param info: A namedtuple of information from pywifiphisher :type info: namedtuple :return AccessPoint object if users type enter :rtype AccessPoint if users type enter else None """ # setup curses # make cursor invisible try: curses.curs_set(0) except curses.error: pass # don't wait for user input screen.nodelay(True) # setup the font color curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN) self.highlight_text = curses.color_pair(1) self.normal_text = curses.A_NORMAL # information regarding access points ap_info = self.init_display_info(screen, info) # show information until user presses Esc key while ap_info.key != 27: # display info will modifiy the key value is_done = self.display_info(screen, ap_info) if is_done: # turn off access point discovery and return the result self.access_point_finder.stop_finding_access_points() return self.access_points[ap_info.pos - 1] # turn off access point discovery self.access_point_finder.stop_finding_access_points()
Example #27
Source File: npysThemeManagers.py From EDCOP with Apache License 2.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 #28
Source File: start.py From gpymusic with MIT License | 5 votes |
def set_colours(colours): """ Set curses colours. Arguments: colours: Dict with colour information. """ crs.start_color() # Define colours. if colours['background'] == 'default': crs.use_default_colors() background = -1 else: crs.init_color(0, *hex_to_rgb(colours['background'])) background = 0 crs.init_color(1, *hex_to_rgb(colours['foreground'])) crs.init_color(2, *hex_to_rgb(colours['highlight'])) crs.init_color(3, *hex_to_rgb(colours['content1'])) crs.init_color(4, *hex_to_rgb(colours['content2'])) # Define colour pairs. crs.init_pair(1, 1, background) crs.init_pair(2, 2, background) crs.init_pair(3, 3, background) crs.init_pair(4, 4, background) # Set colours. crs.start_color() common.w.main.bkgdset(' ', crs.color_pair(1)) common.w.inbar.bkgdset(' ', crs.color_pair(1)) common.w.infobar.bkgdset(' ', crs.color_pair(2)) common.w.outbar.bkgdset(' ', crs.color_pair(4)) common.w.refresh()
Example #29
Source File: ui.py From NetEase-MusicBox with MIT License | 5 votes |
def __init__(self): self.screen = curses.initscr() # charactor break buffer curses.cbreak() self.screen.keypad(1) self.netease = NetEase() curses.start_color() curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)
Example #30
Source File: parse.py From eapeak with BSD 3-Clause "New" or "Revised" License | 5 votes |
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