Python readline.redisplay() Examples

The following are 18 code examples of readline.redisplay(). 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 readline , or try the search function .
Example #1
Source File: cli.py    From pytgbot with GNU General Public License v3.0 6 votes vote down vote up
def print(self, text):
        current_input = readline.get_line_buffer()
        delete_chars = len(self.query) + len(current_input)

        # remove the input:
        sys.stdout.flush()
        for i in range(delete_chars):
            sys.stdout.write("\b \b")
        # end for
        sys.stdout.write("\033[K")
        sys.stdout.flush()

        # actual output
        sys.stdout.write(str(text))
        sys.stdout.write("\n")
        sys.stdout.flush()
        # load back the input
        sys.stdout.write(self.query)
        sys.stdout.flush()
        sys.stdout.write(current_input)
        sys.stdout.flush()
        readline.redisplay()
    # end def 
Example #2
Source File: PupyCmd.py    From backdoorme with MIT License 6 votes vote down vote up
def display(self, msg, modifier=None):
		if not type(msg) is unicode:
			# force output unicode string to output
			# Python will hopefully handle output printing
			msg=str(msg).decode('utf8')
		if msg:
			if modifier=="error":
				self.stdout.write(PupyCmd.format_error(msg))
			elif modifier=="success":
				self.stdout.write(PupyCmd.format_success(msg))
			elif modifier=="info":
				self.stdout.write(PupyCmd.format_info(msg))
			elif modifier=="srvinfo":
				self.stdout.write(PupyCmd.format_srvinfo(msg))
				#readline.redisplay()
			elif modifier=="warning":
				self.stdout.write(PupyCmd.format_warning(msg))
			else:
				self.stdout.write(PupyCmd.format_log(msg)) 
Example #3
Source File: PupyCmd.py    From NoobSec-Toolkit with GNU General Public License v2.0 6 votes vote down vote up
def display(self, msg, modifier=None):
		if not type(msg) is unicode:
			# force output unicode string to output
			# Python will hopefully handle output printing
			msg=str(msg).decode('utf8')
		if msg:
			if modifier=="error":
				self.stdout.write(PupyCmd.format_error(msg))
			elif modifier=="success":
				self.stdout.write(PupyCmd.format_success(msg))
			elif modifier=="info":
				self.stdout.write(PupyCmd.format_info(msg))
			elif modifier=="srvinfo":
				self.stdout.write(PupyCmd.format_srvinfo(msg))
				#readline.redisplay()
			elif modifier=="warning":
				self.stdout.write(PupyCmd.format_warning(msg))
			else:
				self.stdout.write(PupyCmd.format_log(msg)) 
Example #4
Source File: PupyCmd.py    From NoobSec-Toolkit with GNU General Public License v2.0 6 votes vote down vote up
def display(self, msg, modifier=None):
		if not type(msg) is unicode:
			# force output unicode string to output
			# Python will hopefully handle output printing
			msg=str(msg).decode('utf8')
		if msg:
			if modifier=="error":
				self.stdout.write(PupyCmd.format_error(msg))
			elif modifier=="success":
				self.stdout.write(PupyCmd.format_success(msg))
			elif modifier=="info":
				self.stdout.write(PupyCmd.format_info(msg))
			elif modifier=="srvinfo":
				self.stdout.write(PupyCmd.format_srvinfo(msg))
				#readline.redisplay()
			elif modifier=="warning":
				self.stdout.write(PupyCmd.format_warning(msg))
			else:
				self.stdout.write(PupyCmd.format_log(msg)) 
Example #5
Source File: PupyCmd.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def pre_input_hook(self):
		#readline.redisplay()
		pass 
Example #6
Source File: rlcompleter.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        This is called successively with state == 0, 1, 2, ... until it
        returns None.  The completion should begin with 'text'.

        """
        if self.use_main_ns:
            self.namespace = __main__.__dict__

        if not text.strip():
            if state == 0:
                if _readline_available:
                    readline.insert_text('\t')
                    readline.redisplay()
                    return ''
                else:
                    return '\t'
            else:
                return None

        if state == 0:
            if "." in text:
                self.matches = self.attr_matches(text)
            else:
                self.matches = self.global_matches(text)
        try:
            return self.matches[state]
        except IndexError:
            return None 
Example #7
Source File: PupyCmd.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def pre_input_hook(self):
		#readline.redisplay()
		pass 
Example #8
Source File: pythonrc.py    From pythonrc with MIT License 5 votes vote down vote up
def auto_indent_hook(self):
        """Hook called by readline between printing the prompt and
        starting to read input.
        """
        readline.insert_text(self._indent)
        readline.redisplay() 
Example #9
Source File: rlcompleter.py    From Imogen with MIT License 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        This is called successively with state == 0, 1, 2, ... until it
        returns None.  The completion should begin with 'text'.

        """
        if self.use_main_ns:
            self.namespace = __main__.__dict__

        if not text.strip():
            if state == 0:
                if _readline_available:
                    readline.insert_text('\t')
                    readline.redisplay()
                    return ''
                else:
                    return '\t'
            else:
                return None

        if state == 0:
            if "." in text:
                self.matches = self.attr_matches(text)
            else:
                self.matches = self.global_matches(text)
        try:
            return self.matches[state]
        except IndexError:
            return None 
Example #10
Source File: rlcompleter.py    From scylla with Apache License 2.0 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        This is called successively with state == 0, 1, 2, ... until it
        returns None.  The completion should begin with 'text'.

        """
        if self.use_main_ns:
            self.namespace = __main__.__dict__

        if not text.strip():
            if state == 0:
                if _readline_available:
                    readline.insert_text('\t')
                    readline.redisplay()
                    return ''
                else:
                    return '\t'
            else:
                return None

        if state == 0:
            if "." in text:
                self.matches = self.attr_matches(text)
            else:
                self.matches = self.global_matches(text)
        try:
            return self.matches[state]
        except IndexError:
            return None 
Example #11
Source File: passhole.py    From passhole with GNU General Public License v3.0 5 votes vote down vote up
def editable_input(prompt, prefill=None):
    def hook():
        readline.insert_text(prefill)
        readline.redisplay()
    readline.set_pre_input_hook(hook)
    result = input(green(prompt + ': '))
    readline.set_pre_input_hook()
    return result 
Example #12
Source File: sshmenu.py    From sshmenu with MIT License 5 votes vote down vote up
def input_prefill(prompt, text):
    def hook():
        readline.insert_text(text)
        readline.redisplay()

    readline.set_pre_input_hook(hook)
    result = input(prompt)
    readline.set_pre_input_hook()
    return result 
Example #13
Source File: tick.py    From thetick with GNU Lesser General Public License v3.0 5 votes vote down vote up
def notify_new_bot(self, listener, bot):

        # Notifications for reconnecting bots are skipped because they're
        # not very useful except for debugging.
        if bot.uuid not in self.known_bots:

            # Prepare the notification text.
            index = listener.bots.keys().index(bot.uuid)
            text = "Bot %d [%s] connected from %s" % (index, bot.uuid, bot.from_addr[0])
            text = Fore.BLUE + Style.BRIGHT + text + Style.RESET_ALL

            # If the main thread is blocked waiting at the prompt,
            # do some ANSI escape codes magic to insert the notification text on screen.
            # Note that we cannot use this trick if --no-color was specified.
            # (I mean, we could, but what if the reason the colors were turned off
            # was that the C&C was not being run in a console with a proper tty?)
            if self.inside_prompt and ANSI_ENABLED:
                buf_bkp = readline.get_line_buffer()
                sys.stdout.write("\033[s\033[0G\033[2K" + text + "\n")
                sys.stdout.write(self.prompt.replace("\x01", "").replace("\x02", "") + buf_bkp + "\033[u\033[1B")
                readline.redisplay()

            # If we are not blocked at the prompt, better not write now!
            # We would be messing up the output of some command.
            # We'll queue the notification instead to be shown later.
            else:
                self.notifications.append(text)

            # Remember we've seen this bot so we don't notify again.
            self.known_bots.add(bot.uuid)

    # Hook the precmd event to know when we're out of the command prompt. 
Example #14
Source File: rlcompleter.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        This is called successively with state == 0, 1, 2, ... until it
        returns None.  The completion should begin with 'text'.

        """
        if self.use_main_ns:
            self.namespace = __main__.__dict__

        if not text.strip():
            if state == 0:
                if _readline_available:
                    readline.insert_text('\t')
                    readline.redisplay()
                    return ''
                else:
                    return '\t'
            else:
                return None

        if state == 0:
            if "." in text:
                self.matches = self.attr_matches(text)
            else:
                self.matches = self.global_matches(text)
        try:
            return self.matches[state]
        except IndexError:
            return None 
Example #15
Source File: pam.py    From python-pam with MIT License 5 votes vote down vote up
def input_with_prefill(prompt, text):
        def hook():
            readline.insert_text(text)
            readline.redisplay()
        readline.set_pre_input_hook(hook)

        if sys.version_info >= (3,):
            result = input(prompt)
        else:
            result = raw_input(prompt)

        readline.set_pre_input_hook()
        return result 
Example #16
Source File: PupyCmd.py    From backdoorme with MIT License 5 votes vote down vote up
def pre_input_hook(self):
		#readline.redisplay()
		pass 
Example #17
Source File: rlcompleter.py    From kobo-predict with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        This is called successively with state == 0, 1, 2, ... until it
        returns None.  The completion should begin with 'text'.

        """
        if self.use_main_ns:
            self.namespace = __main__.__dict__

        if not text.strip():
            if state == 0:
                if _readline_available:
                    readline.insert_text('\t')
                    readline.redisplay()
                    return ''
                else:
                    return '\t'
            else:
                return None

        if state == 0:
            if "." in text:
                self.matches = self.attr_matches(text)
            else:
                self.matches = self.global_matches(text)
        try:
            return self.matches[state]
        except IndexError:
            return None 
Example #18
Source File: session.py    From mouse with GNU General Public License v3.0 4 votes vote down vote up
def tab_complete(self, text, state):
		try:
			is_double_tab = False
			current_text = readline.get_line_buffer()
			if self.last_tab and self.last_tab == current_text:
				is_double_tab = True
			self.last_tab = current_text

			# if no input do nothing
			if not current_text:
				return
			# get last input
			split_input = current_text.split()[-1]
			
			search_path = os.path.split(split_input)[0]
			search_text = os.path.split(split_input)[1]
			data = self.send_command({"cmd":"tab_complete","args":search_path if search_path else "."})
			results = json.loads(data)

			matched_keys = []
			if results:
				keys = results.keys()
				keys.sort()
				# append / if it is a directory				
				for k in keys:
					# continue if no match
					if k.startswith(search_text):
						matched_keys.append(k)

			# edge cases
			if not matched_keys:
				# don't do anything if we have no matches
				return
			elif len(matched_keys) == 1:
				# if there is only 1 match and that match is a directory, append a '/'
				readline.insert_text(matched_keys[0][len(search_text):])
				if matched_keys[0] in results:
					if results[matched_keys[0]] == 4 or results[matched_keys[0]] == 10:
						readline.insert_text("/")
				readline.redisplay()
				return
			elif not is_double_tab:
				# lcp of multiple matched
				find = h.find_longest_common_prefix(matched_keys)
				readline.insert_text(find[len(search_text):])
				readline.redisplay()
				return

			print("")
			for k in matched_keys:
				if results[k] == 4:
					print(h.COLOR_INFO + k + h.ENDC)
				elif results[k] == 10:
					print(h.COLOR_INFO + k + h.ENDC)
				else:
					print(k)
				# back to where we are
			sys.stdout.write(self.get_handle() + current_text)		
		except Exception as e:
			print("\n error - " + str(e))