Python readline.set_startup_hook() Examples

The following are 11 code examples of readline.set_startup_hook(). 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: parse_functions.py    From todxpy with GNU General Public License v2.0 5 votes vote down vote up
def rlinput(prompt, prefill = ''):
   readline.set_startup_hook(lambda: readline.insert_text(prefill))
   try:
      return input(prompt)
   finally:
      readline.set_startup_hook() 
Example #2
Source File: release.py    From eggnog-mapper with GNU Affero General Public License v3.0 5 votes vote down vote up
def ask(string, valid_values, default=-1, case_sensitive=False):
    """ Asks for a keyborad answer """

    v = None
    if not case_sensitive:
        valid_values = [value.lower() for value in valid_values]
    while v not in valid_values:
        readline.set_startup_hook(lambda: readline.insert_text(default))
        try:
            v = raw_input("%s [%s] " % (string, ', '.join(valid_values))).strip()
            if v == '' and default>=0:
                v = valid_values[default]
            if not case_sensitive:
                v = v.lower()
        finally:
            readline.set_startup_hook()
    return v 
Example #3
Source File: terminalkeyboard.py    From bard with GNU General Public License v3.0 5 votes vote down vote up
def edit_option(self, idx):
        # Go up
        sys.stdout.write('\033[1A' * (len(self.options) - idx))
        # Go left to the beginning of the line
        sys.stdout.write('\033[1D' * (max([len(x) for x in self.options]) + 3))
        sys.stdout.flush()
        prev_value = self.options[idx]
        readline.set_startup_hook(lambda: readline.insert_text(prev_value))
        try:
            new_value = input('E: ')
        finally:
            readline.set_startup_hook()

        self.options[idx] = new_value
        sys.stdout.write('\033[1A' * (idx + 1))
        sys.stdout.write('\033[1D' * (max([len(x) for x in self.options]) + 3))
        sys.stdout.flush()
        self.print_options()
        return prev_value, new_value 
Example #4
Source File: g1modules.py    From gluster-one with GNU General Public License v3.0 4 votes vote down vote up
def user_input(msg, initial=''):
    # Function to capture raw_input w/ key buffer flush
    tcflush(sys.stdin, TCIOFLUSH)
    readline.set_startup_hook(lambda: readline.insert_text(initial))
    keyin = raw_input(msg)
    return keyin 
Example #5
Source File: switch_cfg.py    From power-up with Apache License 2.0 4 votes vote down vote up
def rlinput(prompt, prefill=''):
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        return input(prompt)
    finally:
        readline.set_startup_hook() 
Example #6
Source File: show_status.py    From power-up with Apache License 2.0 4 votes vote down vote up
def rlinput(prompt, prefill=''):
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        return input(prompt)
    finally:
        readline.set_startup_hook() 
Example #7
Source File: utilities.py    From power-up with Apache License 2.0 4 votes vote down vote up
def rlinput(prompt, prefill=''):
    log = logger.getlogger()
    log.debug(f"prompt='{repr(prompt)}' prefill='{prefill}'")
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        user_input = input(prompt)
        log.debug(f"user_input='{user_input}'")
        return user_input
    finally:
        readline.set_startup_hook() 
Example #8
Source File: show_mgmt_switches.py    From power-up with Apache License 2.0 4 votes vote down vote up
def rlinput(prompt, prefill=''):
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        return input(prompt)
    finally:
        readline.set_startup_hook() 
Example #9
Source File: configure_mgmt_switches.py    From power-up with Apache License 2.0 4 votes vote down vote up
def rlinput(prompt, prefill=''):
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        return input(prompt)
    finally:
        readline.set_startup_hook() 
Example #10
Source File: smgr_add.py    From contrail-server-manager with Apache License 2.0 4 votes vote down vote up
def rlinput(prompt, prefill=''):
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        return raw_input(prompt)
    finally:
        readline.set_startup_hook() 
Example #11
Source File: config_manager.py    From GPIOnext with MIT License 4 votes vote down vote up
def getInput( self, prompt, prefill='' ):

		readline.set_startup_hook(lambda: readline.insert_text('\n' + prefill))
		try:
			return input(prompt).replace('\n','')
		finally:
			readline.set_startup_hook()