本文整理汇总了Python中readline.remove_history_item方法的典型用法代码示例。如果您正苦于以下问题:Python readline.remove_history_item方法的具体用法?Python readline.remove_history_item怎么用?Python readline.remove_history_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类readline
的用法示例。
在下文中一共展示了readline.remove_history_item方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testHistoryUpdates
# 需要导入模块: import readline [as 别名]
# 或者: from readline import remove_history_item [as 别名]
def testHistoryUpdates(self):
readline.clear_history()
readline.add_history("first line")
readline.add_history("second line")
self.assertEqual(readline.get_history_item(0), None)
self.assertEqual(readline.get_history_item(1), "first line")
self.assertEqual(readline.get_history_item(2), "second line")
readline.replace_history_item(0, "replaced line")
self.assertEqual(readline.get_history_item(0), None)
self.assertEqual(readline.get_history_item(1), "replaced line")
self.assertEqual(readline.get_history_item(2), "second line")
self.assertEqual(readline.get_current_history_length(), 2)
readline.remove_history_item(0)
self.assertEqual(readline.get_history_item(0), None)
self.assertEqual(readline.get_history_item(1), "second line")
self.assertEqual(readline.get_current_history_length(), 1)
示例2: do_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import remove_history_item [as 别名]
def do_history(self, argv):
"""Command line history
SYNOPSIS:
history [<COUNT>]
DESCRIPTION:
Returns a formatted string giving the event number and
contents for each of the events in the history list
except for current event.
If [COUNT] is specified, only the [COUNT] most recent
events are displayed.
> history
- Display the full history of events.
> history 10
- Display last 10 commands of the history.
"""
import readline
argv.append('9999999999')
try:
count = int(argv[1])
except ValueError:
return self.interpret("help history")
last = readline.get_current_history_length()
while last > session.Hist.MAX_SIZE:
readline.remove_history_item(0)
last -= 1
first = last - count
if first < 1:
first = 1
for i in range(first, last):
cmd = readline.get_history_item(i)
print("{:4d} {:s}".format(i, cmd))
####################
# COMMAND: exploit #
示例3: pyreadline_remove_history_item
# 需要导入模块: import readline [as 别名]
# 或者: from readline import remove_history_item [as 别名]
def pyreadline_remove_history_item(pos: int) -> None:
"""
An implementation of remove_history_item() for pyreadline
:param pos: The 0-based position in history to remove
"""
# Save of the current location of the history cursor
saved_cursor = readline.rl.mode._history.history_cursor
# Delete the history item
del(readline.rl.mode._history.history[pos])
# Update the cursor if needed
if saved_cursor > pos:
readline.rl.mode._history.history_cursor -= 1
示例4: remove_last_history_item
# 需要导入模块: import readline [as 别名]
# 或者: from readline import remove_history_item [as 别名]
def remove_last_history_item() -> None:
"""The user just typed a password..."""
last = readline.get_current_history_length() - 1
readline.remove_history_item(last)
示例5: multiline
# 需要导入模块: import readline [as 别名]
# 或者: from readline import remove_history_item [as 别名]
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