本文整理汇总了Python中readline.remove_history_item函数的典型用法代码示例。如果您正苦于以下问题:Python remove_history_item函数的具体用法?Python remove_history_item怎么用?Python remove_history_item使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remove_history_item函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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("")
开发者ID:bentheiii,项目名称:SecretService,代码行数:33,代码来源:ControlService.py
示例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
开发者ID:ameily,项目名称:pypsi,代码行数:7,代码来源:history.py
示例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
开发者ID:thomasvs,项目名称:mushin,代码行数:30,代码来源:main.py
示例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]
开发者ID:pombredanne,项目名称:compmake,代码行数:27,代码来源:console.py
示例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)
开发者ID:google,项目名称:squires,代码行数:7,代码来源:squires.py
示例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
开发者ID:jjdmol,项目名称:LOFAR,代码行数:7,代码来源:interface.py
示例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
开发者ID:georgedorn,项目名称:d20_shell,代码行数:4,代码来源:utils.py
示例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()
开发者ID:eucalyptus-qa,项目名称:shared,代码行数:60,代码来源:epdb.py
示例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
开发者ID:mcalmer,项目名称:spacewalk,代码行数:32,代码来源:utils.py
示例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
开发者ID:pombredanne,项目名称:steelscript,代码行数:7,代码来源:rest.py
示例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
开发者ID:fabaff,项目名称:yokadi,代码行数:28,代码来源:tui.py
示例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
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:9,代码来源:utils.py
示例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)
开发者ID:alexvanacker,项目名称:Arkonf,代码行数:10,代码来源:.pythonrc.py
示例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")
开发者ID:bruceravel,项目名称:xraylarch,代码行数:11,代码来源:shell.py
示例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()
开发者ID:weex,项目名称:goxsh,代码行数:11,代码来源:goxsh.py
示例16: input
def input(self, prompt=''):
"Prompts and reads input from the user"
lines = self.wrap(prompt, newline=False).split('\n')
prompt = lines[-1]
s = ''.join(line + '\n' for line in lines[:-1])
self.stdout.write(s)
result = input(prompt).strip()
# Strip the history from readline (we only want commands in the
# history)
readline.remove_history_item(readline.get_current_history_length() - 1)
return result
开发者ID:waveform80,项目名称:tvrip,代码行数:11,代码来源:cmdline.py
示例17: compact_history
def compact_history():
if hasattr(readline, "replace_history_item"):
unique_history = utils.unique_list()
for index in reversed(list(range(1, readline.get_current_history_length()))):
hist_item = readline.get_history_item(index)
if hist_item: # some history items are None (usually at index 0)
unique_history.append(readline.get_history_item(index))
unique_history.reverse()
for index in range(len(unique_history)):
readline.replace_history_item(index + 1, unique_history[index])
for index in reversed(list(range(len(unique_history) + 1, readline.get_current_history_length()))):
readline.remove_history_item(index)
开发者ID:wavesaudio,项目名称:instl,代码行数:12,代码来源:instlInstanceBase_interactive.py
示例18: _check_history_duplicates
def _check_history_duplicates(value):
# prevent duplicates in histtory the last ten lines
# of the history - if the item is already there -
# remove it again
histlen = readline.get_current_history_length()
if histlen > 1:
for i in range(max(histlen - 10, 0), histlen):
previtem = readline.get_history_item(i)
if previtem == value:
lg.debug("removing duplicate %s" % value)
readline.remove_history_item(histlen - 1)
break
开发者ID:mfiers,项目名称:toMaKe,代码行数:12,代码来源:ui.py
示例19: multiline
def multiline(self, firstline=''):
full_input = []
# keep a list of the entries that we've made in history
old_hist = []
if 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':
print
break
full_input.append(line)
if ';' in line:
break
# add the final readline history position
if hasReadline:
old_hist.append(readline.get_current_history_length())
cmd = ' '.join(full_input)
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)
return cmd
开发者ID:fedora-conary,项目名称:conary,代码行数:50,代码来源:shell.py
示例20: __cmd_login__
def __cmd_login__(self, username=u""):
u"Set login credentials."
if not username:
while not username:
username = raw_input(u"Username: ").decode(self.__encoding)
try:
readline.remove_history_item(readline.get_current_history_length() - 1)
except AttributeError:
# Some systems lack remove_history_item
pass
password = u""
while not password:
password = getpass.getpass()
self.__mtgox.set_credentials(username, password)
开发者ID:BTC-Bear,项目名称:goxsh,代码行数:14,代码来源:goxsh.py
注:本文中的readline.remove_history_item函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论