本文整理匯總了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
示例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
示例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()
示例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
示例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()
示例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()
示例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()
示例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()