當前位置: 首頁>>代碼示例>>Python>>正文


Python readline.set_startup_hook方法代碼示例

本文整理匯總了Python中readline.set_startup_hook方法的典型用法代碼示例。如果您正苦於以下問題:Python readline.set_startup_hook方法的具體用法?Python readline.set_startup_hook怎麽用?Python readline.set_startup_hook使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在readline的用法示例。


在下文中一共展示了readline.set_startup_hook方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ask

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_startup_hook [as 別名]
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 
開發者ID:eggnogdb,項目名稱:eggnog-mapper,代碼行數:19,代碼來源:release.py

示例2: edit_option

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_startup_hook [as 別名]
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 
開發者ID:antlarr,項目名稱:bard,代碼行數:21,代碼來源:terminalkeyboard.py

示例3: rlinput

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_startup_hook [as 別名]
def rlinput(prompt, prefill = ''):
   readline.set_startup_hook(lambda: readline.insert_text(prefill))
   try:
      return input(prompt)
   finally:
      readline.set_startup_hook() 
開發者ID:xypnox,項目名稱:todxpy,代碼行數:8,代碼來源:parse_functions.py

示例4: user_input

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_startup_hook [as 別名]
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 
開發者ID:gluster,項目名稱:gluster-one,代碼行數:8,代碼來源:g1modules.py

示例5: rlinput

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_startup_hook [as 別名]
def rlinput(prompt, prefill=''):
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        return input(prompt)
    finally:
        readline.set_startup_hook() 
開發者ID:IBM,項目名稱:power-up,代碼行數:8,代碼來源:switch_cfg.py

示例6: rlinput

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_startup_hook [as 別名]
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() 
開發者ID:IBM,項目名稱:power-up,代碼行數:12,代碼來源:utilities.py

示例7: rlinput

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_startup_hook [as 別名]
def rlinput(prompt, prefill=''):
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        return raw_input(prompt)
    finally:
        readline.set_startup_hook() 
開發者ID:Juniper,項目名稱:contrail-server-manager,代碼行數:8,代碼來源:smgr_add.py

示例8: getInput

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_startup_hook [as 別名]
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() 
開發者ID:mholgatem,項目名稱:GPIOnext,代碼行數:9,代碼來源:config_manager.py


注:本文中的readline.set_startup_hook方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。