本文整理汇总了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()