def show(self): MenuScreen.set_cursor_at(0, 0) MenuScreen.clear_to_end_of_screen() for submenu in self.get_submenus(): submenu.show() print sys.stdout.write(self.get_prompt()) sys.stdout.write(readline.get_line_buffer()[:readline.get_rl_point()]) MenuScreen.save_position() sys.stdout.write(readline.get_line_buffer()[readline.get_rl_point():]) MenuScreen.restore_position() sys.stdout.flush()
def clear_readline(): # Next line said to be reasonably portable for various Unixes _, cols = unpack('hh', ioctl(stdout, TIOCGWINSZ, '1234')) length = len(readline.get_line_buffer()) + len(prompt) lines = length / cols # ANSI escape sequences (All VT100 except ESC[0G) stdout.write('\x1b[2K') # Clear current line stdout.write('\x1b[1A\x1b[2K' * lines) # Move cursor up and clear line stdout.write('\x1b[0G') # Move to start of line
def complete(self, text): """Return a list of possible completions from the line currently entered at the prompt. If the first word is "help", try to find a help_*() method through _traverse_do, otherwise look for a command through _traverse_do(). :type text: string :param text: line entered at prompt :return: list """ endidx = readline.get_endidx() buf = readline.get_line_buffer() tokens = buf[:endidx].split() if not tokens or buf[endidx - 1] == ' ': tokens.append('') if tokens[0] == "help": return self._traverse_help(tokens[1:], self) else: return self._traverse_do(tokens, self)
def get(self): return readline.get_line_buffer()