Python curses.start_color() Examples
The following are 30
code examples of curses.start_color().
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: 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 #4
Source File: npysThemeManagers.py From apple_bleee with GNU General Public License v3.0 | 6 votes |
def __init__(self): #curses.use_default_colors() self.define_colour_numbers() self._defined_pairs = {} self._names = {} try: self._max_pairs = curses.COLOR_PAIRS - 1 do_color = True except AttributeError: # curses.start_color has failed or has not been called do_color = False # Disable all color use across the application disableColor() if do_color and curses.has_colors(): self.initialize_pairs() self.initialize_names()
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: npyssafewrapper.py From apple_bleee with GNU General Public License v3.0 | 6 votes |
def wrapper_fork(call_function, reset=True): pid = os.fork() if pid: # Parent os.waitpid(pid, 0) if reset: external_reset() else: locale.setlocale(locale.LC_ALL, '') _SCREEN = curses.initscr() try: curses.start_color() except: pass _SCREEN.keypad(1) curses.noecho() curses.cbreak() curses.def_prog_mode() curses.reset_prog_mode() return_code = call_function(_SCREEN) _SCREEN.keypad(0) curses.echo() curses.nocbreak() curses.endwin() sys.exit(0)
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: npysThemeManagers.py From EDCOP with Apache License 2.0 | 6 votes |
def __init__(self): #curses.use_default_colors() self.define_colour_numbers() self._defined_pairs = {} self._names = {} try: self._max_pairs = curses.COLOR_PAIRS - 1 do_color = True except AttributeError: # curses.start_color has failed or has not been called do_color = False # Disable all color use across the application disableColor() if do_color and curses.has_colors(): self.initialize_pairs() self.initialize_names()
Example #9
Source File: screen.py From babi with MIT License | 6 votes |
def _init_screen() -> 'curses._CursesWindow': # set the escape delay so curses does not pause waiting for sequences if sys.version_info >= (3, 9): # pragma: no cover curses.set_escdelay(25) else: # pragma: no cover os.environ.setdefault('ESCDELAY', '25') stdscr = curses.initscr() curses.noecho() curses.cbreak() # <enter> is not transformed into '\n' so it can be differentiated from ^J curses.nonl() # ^S / ^Q / ^Z / ^\ are passed through curses.raw() stdscr.keypad(True) with contextlib.suppress(curses.error): curses.start_color() curses.use_default_colors() return stdscr
Example #10
Source File: wrapper.py From BinderFilter with MIT License | 6 votes |
def wrapper(func, *args, **kwds): """Wrapper function that initializes curses and calls another function, restoring normal keyboard/screen behavior on error. The callable object 'func' is then passed the main window 'stdscr' as its first argument, followed by any other arguments passed to wrapper(). """ try: # Initialize curses stdscr = curses.initscr() # Turn off echoing of keys, and enter cbreak mode, # where no buffering is performed on keyboard input curses.noecho() curses.cbreak() # In keypad mode, escape sequences for special keys # (like the cursor keys) will be interpreted and # a special value like curses.KEY_LEFT will be returned stdscr.keypad(1) # Start color, too. Harmless if the terminal doesn't have # color; user can test with has_color() later on. The try/catch # works around a minor bit of over-conscientiousness in the curses # module -- the error return from C start_color() is ignorable. try: curses.start_color() except: pass return func(stdscr, *args, **kwds) finally: # Set everything back to normal if 'stdscr' in locals(): stdscr.keypad(0) curses.echo() curses.nocbreak() curses.endwin()
Example #11
Source File: npysThemeManagers.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def __init__(self): #curses.use_default_colors() self.define_colour_numbers() self._defined_pairs = {} self._names = {} try: self._max_pairs = curses.COLOR_PAIRS - 1 do_color = True except AttributeError: # curses.start_color has failed or has not been called do_color = False # Disable all color use across the application disableColor() if do_color and curses.has_colors(): self.initialize_pairs() self.initialize_names()
Example #12
Source File: npyssafewrapper.py From EDCOP with Apache License 2.0 | 6 votes |
def wrapper_fork(call_function, reset=True): pid = os.fork() if pid: # Parent os.waitpid(pid, 0) if reset: external_reset() else: locale.setlocale(locale.LC_ALL, '') _SCREEN = curses.initscr() try: curses.start_color() except: pass _SCREEN.keypad(1) curses.noecho() curses.cbreak() curses.def_prog_mode() curses.reset_prog_mode() return_code = call_function(_SCREEN) _SCREEN.keypad(0) curses.echo() curses.nocbreak() curses.endwin() sys.exit(0)
Example #13
Source File: npyssafewrapper.py From TelegramTUI with MIT License | 6 votes |
def wrapper_fork(call_function, reset=True): pid = os.fork() if pid: # Parent os.waitpid(pid, 0) if reset: external_reset() else: locale.setlocale(locale.LC_ALL, '') _SCREEN = curses.initscr() try: curses.start_color() except: pass _SCREEN.keypad(1) curses.noecho() curses.cbreak() curses.def_prog_mode() curses.reset_prog_mode() return_code = call_function(_SCREEN) _SCREEN.keypad(0) curses.echo() curses.nocbreak() curses.endwin() sys.exit(0)
Example #14
Source File: npyssafewrapper.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def wrapper_fork(call_function, reset=True): pid = os.fork() if pid: # Parent os.waitpid(pid, 0) if reset: external_reset() else: locale.setlocale(locale.LC_ALL, '') _SCREEN = curses.initscr() try: curses.start_color() except: pass _SCREEN.keypad(1) curses.noecho() curses.cbreak() curses.def_prog_mode() curses.reset_prog_mode() return_code = call_function(_SCREEN) _SCREEN.keypad(0) curses.echo() curses.nocbreak() curses.endwin() sys.exit(0)
Example #15
Source File: npysThemeManagers.py From TelegramTUI with MIT License | 6 votes |
def __init__(self): #curses.use_default_colors() self.define_colour_numbers() self._defined_pairs = {} self._names = {} try: self._max_pairs = curses.COLOR_PAIRS - 1 do_color = True except AttributeError: # curses.start_color has failed or has not been called do_color = False # Disable all color use across the application disableColor() if do_color and curses.has_colors(): self.initialize_pairs() self.initialize_names()
Example #16
Source File: airpydump.py From airpydump with MIT License | 6 votes |
def __init__(self, scanner): self.scanner = scanner self.screen = curses.initscr() curses.noecho() curses.cbreak() self.screen.keypad(1) self.screen.scrollok(True) self.x, self.y = self.screen.getmaxyx() curses.start_color() curses.use_default_colors() try: self.screen.curs_set(0) except: try: self.screen.curs_set(1) except: pass
Example #17
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 #18
Source File: mitop.py From mitogen with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, hosts): self.stdscr = curses.initscr() curses.start_color() self.height, self.width = self.stdscr.getmaxyx() curses.cbreak() curses.noecho() self.stdscr.keypad(1) self.hosts = hosts self.format = ( '%(hostname)10.10s ' '%(pid)7.7s ' '%(ppid)7.7s ' '%(pcpu)6.6s ' '%(rss)5.5s ' '%(command)20s' )
Example #19
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 #20
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 #21
Source File: wrapper.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def wrapper(func, *args, **kwds): """Wrapper function that initializes curses and calls another function, restoring normal keyboard/screen behavior on error. The callable object 'func' is then passed the main window 'stdscr' as its first argument, followed by any other arguments passed to wrapper(). """ try: # Initialize curses stdscr = curses.initscr() # Turn off echoing of keys, and enter cbreak mode, # where no buffering is performed on keyboard input curses.noecho() curses.cbreak() # In keypad mode, escape sequences for special keys # (like the cursor keys) will be interpreted and # a special value like curses.KEY_LEFT will be returned stdscr.keypad(1) # Start color, too. Harmless if the terminal doesn't have # color; user can test with has_color() later on. The try/catch # works around a minor bit of over-conscientiousness in the curses # module -- the error return from C start_color() is ignorable. try: curses.start_color() except: pass return func(stdscr, *args, **kwds) finally: # Set everything back to normal if 'stdscr' in locals(): stdscr.keypad(0) curses.echo() curses.nocbreak() curses.endwin()
Example #22
Source File: npyssafewrapper.py From TelegramTUI with MIT License | 5 votes |
def wrapper_no_fork(call_function, reset=False): global _NEVER_RUN_INITSCR if not _NEVER_RUN_INITSCR: warnings.warn("""Repeated calls of endwin may cause a memory leak. Use wrapper_fork to avoid.""") global _SCREEN return_code = None if _NEVER_RUN_INITSCR: _NEVER_RUN_INITSCR = False locale.setlocale(locale.LC_ALL, '') _SCREEN = curses.initscr() try: curses.start_color() except: pass curses.noecho() curses.cbreak() _SCREEN.keypad(1) curses.noecho() curses.cbreak() _SCREEN.keypad(1) try: return_code = call_function(_SCREEN) finally: _SCREEN.keypad(0) curses.echo() curses.nocbreak() # Calling endwin() and then refreshing seems to cause a memory leak. curses.endwin() if reset: external_reset() return return_code
Example #23
Source File: inspect.py From flowcraft with GNU General Public License v3.0 | 5 votes |
def display_overview(self): """Displays the default pipeline inspection overview """ stay_alive = True self.screen = curses.initscr() self.screen.keypad(True) self.screen.nodelay(-1) curses.cbreak() curses.noecho() curses.start_color() self.screen_lines = self.screen.getmaxyx()[0] # self.screen_width = self.screen.getmaxyx()[1] try: while stay_alive: # Provide functionality to certain keybindings self._curses_keybindings() # Updates main inspector attributes self.update_inspection() # Display curses interface self.flush_overview() sleep(self.refresh_rate) except FileNotFoundError: sys.stderr.write(colored_print( "ERROR: nextflow log and/or trace files are no longer " "reachable!", "red_bold")) except Exception as e: sys.stderr.write(str(e)) finally: curses.nocbreak() self.screen.keypad(0) curses.echo() curses.endwin()
Example #24
Source File: cgroup_top.py From ctop with MIT License | 5 votes |
def init_screen(): curses.start_color() # load colors curses.use_default_colors() curses.noecho() # do not echo text curses.cbreak() # do not wait for "enter" curses.mousemask(curses.ALL_MOUSE_EVENTS) # Hide cursor, if terminal AND curse supports it if hasattr(curses, 'curs_set'): try: curses.curs_set(0) except: pass
Example #25
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
Example #26
Source File: curses_display.py From anyMesh-Python with MIT License | 5 votes |
def start(self): """ Initialize the screen and input mode. """ assert self._started == False self.s = curses.initscr() self.has_color = curses.has_colors() if self.has_color: curses.start_color() if curses.COLORS < 8: # not colourful enough self.has_color = False if self.has_color: try: curses.use_default_colors() self.has_default_colors=True except _curses.error: self.has_default_colors=False self._setup_colour_pairs() curses.noecho() curses.meta(1) curses.halfdelay(10) # use set_input_timeouts to adjust self.s.keypad(0) if not self._signal_keys_set: self._old_signal_keys = self.tty_signal_keys() super(Screen, self).start()
Example #27
Source File: wrapper.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def wrapper(func, *args, **kwds): """Wrapper function that initializes curses and calls another function, restoring normal keyboard/screen behavior on error. The callable object 'func' is then passed the main window 'stdscr' as its first argument, followed by any other arguments passed to wrapper(). """ try: # Initialize curses stdscr = curses.initscr() # Turn off echoing of keys, and enter cbreak mode, # where no buffering is performed on keyboard input curses.noecho() curses.cbreak() # In keypad mode, escape sequences for special keys # (like the cursor keys) will be interpreted and # a special value like curses.KEY_LEFT will be returned stdscr.keypad(1) # Start color, too. Harmless if the terminal doesn't have # color; user can test with has_color() later on. The try/catch # works around a minor bit of over-conscientiousness in the curses # module -- the error return from C start_color() is ignorable. try: curses.start_color() except: pass return func(stdscr, *args, **kwds) finally: # Set everything back to normal if 'stdscr' in locals(): stdscr.keypad(0) curses.echo() curses.nocbreak() curses.endwin()
Example #28
Source File: npyssafewrapper.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def wrapper_no_fork(call_function, reset=False): global _NEVER_RUN_INITSCR if not _NEVER_RUN_INITSCR: warnings.warn("""Repeated calls of endwin may cause a memory leak. Use wrapper_fork to avoid.""") global _SCREEN return_code = None if _NEVER_RUN_INITSCR: _NEVER_RUN_INITSCR = False locale.setlocale(locale.LC_ALL, '') _SCREEN = curses.initscr() try: curses.start_color() except: pass curses.noecho() curses.cbreak() _SCREEN.keypad(1) curses.noecho() curses.cbreak() _SCREEN.keypad(1) try: return_code = call_function(_SCREEN) finally: _SCREEN.keypad(0) curses.echo() curses.nocbreak() # Calling endwin() and then refreshing seems to cause a memory leak. curses.endwin() if reset: external_reset() return return_code
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: raspcloud.py From RaspberryCloud with GNU General Public License v3.0 | 5 votes |
def init_curses(): s = curses.initscr() curses.start_color() curses.use_default_colors() curses.noecho() s.scrollok(1) curses.curs_set(0) s.keypad(1) s.refresh() return s