本文整理汇总了Python中readline.remove_history_item函数的典型用法代码示例。如果您正苦于以下问题:Python remove_history_item函数的具体用法?Python remove_history_item怎么用?Python remove_history_item使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remove_history_item函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: silent_invariant_raw_input
def silent_invariant_raw_input(prompt,comp=None,wipe=False, echo = True,color = Colors.NONE,completion=None):
prompt = color+prompt+Colors.ENDC
if not Control.silent:
readline.set_startup_hook(lambda: readline.insert_text(comp))
if completion=="Files":
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
readline.set_completer(fileCompleter)
elif not completion is None:
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
readline.set_completer(lambda a,b:listCompleter(a,b,completion))
try:
if Control.silent:
prompt = ""
if echo:
ret = raw_input(prompt)
else:
ret = getpass.getpass(prompt)
wipe = False
if wipe:
l = readline.get_current_history_length()
if l > 0:
readline.remove_history_item(l-1)
return ret
finally:
if not Control.silent:
readline.set_startup_hook()
if not completion is None:
readline.parse_and_bind("set disable-completion On")
readline.set_completer(None)
#readline.parse_and_bind("tab: \t")
readline.set_completer_delims("")
示例2: __delitem__
def __delitem__(self, index):
'''
Delete a history event at ``index``.
'''
if hasattr(readline, 'remove_history_item'):
index = self.normalize_index(index)
readline.remove_history_item(index) # pylint: disable=no-member
示例3: lookupCb
def lookupCb(thing):
if not thing:
self.stdout.write('No thing found for %s\n' %
shortid.encode('utf-8'))
return
self.getRootCommand()._stdio.teardown()
def pre_input_hook():
readline.insert_text(display.display(
thing, shortid=False, colored=False))
readline.redisplay()
# Unset the hook again
readline.set_pre_input_hook(None)
readline.set_pre_input_hook(pre_input_hook)
line = raw_input("GTD edit> ").decode('utf-8')
# Remove edited line from history:
# oddly, get_history_item is 1-based,
# but remove_history_item is 0-based
readline.remove_history_item(readline.get_current_history_length() - 1)
self.getRootCommand()._stdio.setup()
try:
d = parse.parse(line)
except ValueError, e:
self.stderr.write('Could not parse line: %s\n' %
log.getExceptionMessage(e))
return 3
示例4: ask_question
def ask_question(question, allowed=None):
''' Asks a yes/no question to the user '''
if allowed is None:
allowed = {
'y': True,
'Y': True,
'yes': True,
'n': False,
'N': False,
'no': False
}
while True:
line = raw_input(question)
line = line.strip()
# we don't want these to go into the history
if use_readline:
try:
L = readline.get_current_history_length() # @UndefinedVariable
if L:
readline.remove_history_item(L - 1) # @UndefinedVariable
except:
pass
if line in allowed:
return allowed[line]
示例5: _SaveHistory
def _SaveHistory(self):
"""Save readline history then clear history."""
self._saved_history = []
for idx in xrange(1, readline.get_current_history_length()+1):
self._saved_history.append(readline.get_history_item(idx))
for idx in xrange(readline.get_current_history_length()):
readline.remove_history_item(0)
示例6: raw_input_no_history
def raw_input_no_history(prompt):
"""Removes user input from readline history."""
import readline
input = raw_input(prompt)
if input != '':
readline.remove_history_item(readline.get_current_history_length()-1)
return input
示例7: raw_input_no_history
def raw_input_no_history(output=None):
input = raw_input(output)
readline.remove_history_item(readline.get_current_history_length()-1)
return input
示例8: multiline
def multiline(self, firstline=''):
full_input = []
# keep a list of the entries that we've made in history
old_hist = []
if firstline:
print ' ' + firstline
full_input.append(firstline)
while True:
if hasReadline:
# add the current readline position
old_hist.append(readline.get_current_history_length())
if self.use_rawinput:
try:
line = raw_input(self.multiline_prompt)
except EOFError:
line = 'EOF'
else:
self.stdout.write(self.multiline_prompt)
self.stdout.flush()
line = self.stdin.readline()
if not len(line):
line = 'EOF'
else:
line = line[:-1] # chop \n
if line == 'EOF':
break
full_input.append(line)
# add the final readline history position
if hasReadline:
old_hist.append(readline.get_current_history_length())
cmd = '\n'.join(full_input) + '\n'
if hasReadline:
# remove the old, individual readline history entries.
# first remove any duplicate entries
old_hist = sorted(set(old_hist))
# Make sure you do this in reversed order so you move from
# the end of the history up.
for pos in reversed(old_hist):
# get_current_history_length returns pos + 1
readline.remove_history_item(pos - 1)
# now add the full line
readline.add_history(cmd)
locals = self.curframe.f_locals
globals = self.curframe.f_globals
print
self.save_history()
try:
try:
code = compile(cmd, '<stdin>', 'single')
exec code in globals, locals
except:
print self._reprExc()
finally:
self.read_history()
示例9: prompt_user
def prompt_user(prompt, noblank=False, multiline=False):
try:
while True:
if multiline:
print(prompt)
userinput = sys.stdin.read()
else:
try:
# python 2 must call raw_input() because input()
# also evaluates the user input and that causes
# problems.
userinput = raw_input('%s ' % prompt)
except NameError:
# python 3 replaced raw_input() with input()...
# it no longer evaulates the user input.
userinput = input('%s ' % prompt)
if noblank:
if userinput != '':
break
else:
break
except EOFError:
print()
return ''
if userinput != '':
last = readline.get_current_history_length() - 1
if last >= 0:
readline.remove_history_item(last)
return userinput
示例10: raw_input_no_history
def raw_input_no_history(self, prompt):
if self.filelines:
return self.filelines.pop(0)
else:
input = raw_input(prompt)
readline.remove_history_item(readline.get_current_history_length() - 1)
return input
示例11: editLine
def editLine(line, prompt="edit> ", echo=True):
"""Edit a line using readline
@param prompt: change prompt
@param echo: whether to echo user text or not"""
if line:
reinjectInRawInput(line)
if len(_answers) > 0:
line = _answers.pop(0)
else:
try:
if echo:
line = input(prompt)
else:
line = getpass(prompt)
except EOFError:
line = ""
# Remove edited line from history:
# oddly, get_history_item is 1-based,
# but remove_history_item is 0-based
if sys.platform != 'win32':
length = readline.get_current_history_length()
if length > 0:
readline.remove_history_item(length - 1)
return line
示例12: textInput
def textInput(title, insert=None):
if insert:
title = "%s [%s]:" % (title, insert,)
result = raw_input(title)
if readline.get_current_history_length():
readline.remove_history_item(readline.get_current_history_length() - 1)
if not result:
result = insert
return result
示例13: clean_and_save_history
def clean_and_save_history(history):
import readline
commands = set()
for commandId in xrange(readline.get_current_history_length(), 0, -1):
command = readline.get_history_item(commandId)
if command in commands:
readline.remove_history_item(commandId - 1)
else:
commands.add(command)
readline.write_history_file(history)
示例14: write_history
def write_history(self, trim_last=False):
if not HAS_READLINE or history_file is None:
return
try:
readline.set_history_length(self.maxhist)
if trim_last:
n = readline.get_current_history_length()
readline.remove_history_item(n-1)
readline.write_history_file(history_file)
except:
print("Warning: could not write history file")
示例15: __cmd_login__
def __cmd_login__(self, username = u"", exchange = u"mtgox"):
u"Set login credentials. Exchange can be either mtgox or exchb."
if not username:
while not username:
username = raw_input(u"Username: ").decode(self.__encoding)
readline.remove_history_item(readline.get_current_history_length() - 1)
password = u""
while not password:
password = getpass.getpass()
self.__mtgox.set_credentials(exchange, username, password)
self.__mtgox_commission = self.__mtgox.get_commission()