Python curses.cbreak() Examples

The following are 30 code examples of curses.cbreak(). 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: CLI.py    From email_hack with MIT License 7 votes vote down vote up
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 #2
Source File: npyssafewrapper.py    From HomePWN with GNU General Public License v3.0 6 votes vote down vote up
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 #3
Source File: screen.py    From babi with MIT License 6 votes vote down vote up
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 #4
Source File: npyssafewrapper.py    From TelegramTUI with MIT License 6 votes vote down vote up
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 #5
Source File: wrapper.py    From BinderFilter with MIT License 6 votes vote down vote up
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 #6
Source File: npyssafewrapper.py    From EDCOP with Apache License 2.0 6 votes vote down vote up
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: cli.py    From SecureChat with MIT License 6 votes vote down vote up
def setup(self):
        """
        Perform basic command-line interface setup.
        """
        curses.curs_set(1)
        curses.noecho()
        curses.cbreak()
        # Keypad disabled until scrolling properly implemented
        # self.stdscr.keypad(True)
        self.stdscr.clear()
        self.stdscr.addstr("SecureChat v{}".format(__version__))
        self.chat_container.box()
        self.chat_win.addstr("Welcome to SecureChat!")
        self.chat_win.scrollok(True)
        self.chat_win.setscrreg(0, self.max_y - 5)
        self.prompt_win.addstr("> ")
        self.refresh_all() 
Example #8
Source File: npyssafewrapper.py    From apple_bleee with GNU General Public License v3.0 6 votes vote down vote up
def wrapper_basic(call_function):
    #set the locale properly
    locale.setlocale(locale.LC_ALL, '')
    return curses.wrapper(call_function)

#def wrapper(call_function):
#   locale.setlocale(locale.LC_ALL, '')
#   screen = curses.initscr()
#   curses.noecho()
#   curses.cbreak()
#   
#   return_code = call_function(screen)
#   
#   curses.nocbreak()
#   curses.echo()
#   curses.endwin() 
Example #9
Source File: npyssafewrapper.py    From apple_bleee with GNU General Public License v3.0 6 votes vote down vote up
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 #10
Source File: npyssafewrapper.py    From EDCOP with Apache License 2.0 6 votes vote down vote up
def wrapper_basic(call_function):
    #set the locale properly
    locale.setlocale(locale.LC_ALL, '')
    return curses.wrapper(call_function)

#def wrapper(call_function):
#   locale.setlocale(locale.LC_ALL, '')
#   screen = curses.initscr()
#   curses.noecho()
#   curses.cbreak()
#   
#   return_code = call_function(screen)
#   
#   curses.nocbreak()
#   curses.echo()
#   curses.endwin() 
Example #11
Source File: mitop.py    From mitogen with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #12
Source File: pg-top.py    From postgresql-perf-tools with GNU General Public License v2.0 6 votes vote down vote up
def pg_top(scr, pgt, con, opts):

	curses.noecho()		# disable echo
	curses.cbreak()		# keys are read directly, without hitting Enter
#	curses.curs_set(0)	# disable mouse

	pgt.init(scr, con, opts)
	t = threading.Thread(target=main_loop, args=(pgt,))
	t.daemon = True
	t.start()

	while 1:
		try:
			key = pgt.getkey()
			if key == 'q':
				pgt.terminate = True
				break
		except KeyboardInterrupt:
			break
	pgt.terminate = True 
Example #13
Source File: airpydump.py    From airpydump with MIT License 6 votes vote down vote up
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 #14
Source File: console.py    From fluxclient with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #15
Source File: gcore_box.py    From gaycore with MIT License 6 votes vote down vote up
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 #16
Source File: npyssafewrapper.py    From HomePWN with GNU General Public License v3.0 6 votes vote down vote up
def wrapper_basic(call_function):
    #set the locale properly
    locale.setlocale(locale.LC_ALL, '')
    return curses.wrapper(call_function)

#def wrapper(call_function):
#   locale.setlocale(locale.LC_ALL, '')
#   screen = curses.initscr()
#   curses.noecho()
#   curses.cbreak()
#   
#   return_code = call_function(screen)
#   
#   curses.nocbreak()
#   curses.echo()
#   curses.endwin() 
Example #17
Source File: gui.py    From sandsifter with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def start(self, no_delay):
        self.window = curses.initscr()
        curses.start_color()
        curses.use_default_colors()
        curses.noecho()
        curses.cbreak()
        curses.curs_set(0)
        self.window.nodelay(no_delay)
        self.init_colors()
        self.window.bkgd(curses.color_pair(self.WHITE))
        locale.setlocale(locale.LC_ALL, '')    # set your locale
        self.code = locale.getpreferredencoding() 
Example #18
Source File: top.py    From python-scripts with GNU General Public License v3.0 5 votes vote down vote up
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 #19
Source File: curses_display.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def _getch_nodelay(self):
        self.s.nodelay(1)
        while 1:
            # this call fails sometimes, but seems to work when I try again
            try:
                curses.cbreak()
                break
            except _curses.error:
                pass
            
        return self.s.getch() 
Example #20
Source File: npyssafewrapper.py    From EDCOP with Apache License 2.0 5 votes vote down vote up
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 #21
Source File: curses_display.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def _getch(self, wait_tenths):
        if wait_tenths==0:
            return self._getch_nodelay()
        if wait_tenths is None:
            curses.cbreak()
        else:
            curses.halfdelay(wait_tenths)
        self.s.nodelay(0)
        return self.s.getch() 
Example #22
Source File: dvedeky.py    From typhon-vx with GNU General Public License v3.0 5 votes vote down vote up
def maindraw():
	global phones
	global mainpad
	global height,width
	mainpad.erase()
	for i in range(0,len(phones)):
		phoneline(i)
	helptext()
	curses.noecho()
	curses.cbreak()
	stdscr.keypad(1)
	stdscr.refresh()
	mainpad.redrawwin()
	mainpad.refresh( 0,0, 0,0, height,width) 
Example #23
Source File: screen.py    From WiFiBroot with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, verbosity):
		self.screen = curses.initscr()
		curses.noecho()
		curses.cbreak()
		self.screen.keypad(1)
		self.screen.scrollok(True)
		self.verbose = verbosity 
Example #24
Source File: wrapper.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #25
Source File: npyssafewrapper.py    From TelegramTUI with MIT License 5 votes vote down vote up
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 #26
Source File: curses_ui.py    From whatsapp-cli with MIT License 5 votes vote down vote up
def __curses(self, stdscr):
        curses.noecho()
        curses.cbreak()    #enable cbreak mode

        stdscr.nodelay(True) 
        
        (mlines, mcols) = stdscr.getmaxyx()

    	win = Window(self, self.lock, 0, 'whatsapp', mlines, mcols)
        self.windows.append(win)
        self.__show_all('',0)
        self.__refresh()
        win.register_command(self.lock) 
Example #27
Source File: npyssafewrapper.py    From HomePWN with GNU General Public License v3.0 5 votes vote down vote up
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 #28
Source File: curses_ui.py    From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License 5 votes vote down vote up
def _screen_launch(self, enable_mouse_on_start):
    """Launch the curses screen."""

    curses.noecho()
    curses.cbreak()
    self._stdscr.keypad(1)

    self._mouse_enabled = enable_mouse_on_start
    self._screen_set_mousemask()

    self._screen_create_command_window() 
Example #29
Source File: curses_ui.py    From keras-lambda with MIT License 5 votes vote down vote up
def _screen_launch(self, enable_mouse_on_start):
    """Launch the curses screen."""

    curses.noecho()
    curses.cbreak()
    self._stdscr.keypad(1)

    self._mouse_enabled = enable_mouse_on_start
    self._screen_set_mousemask()

    self._screen_create_command_window() 
Example #30
Source File: parse.py    From eapeak with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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