本文整理汇总了Python中readline.get_current_history_length函数的典型用法代码示例。如果您正苦于以下问题:Python get_current_history_length函数的具体用法?Python get_current_history_length怎么用?Python get_current_history_length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_current_history_length函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setup_readline_history
def setup_readline_history(histfile=None):
"""Handle readline / history."""
if not histfile:
histfile = "./.python_history"
# histfile = os.path.join(os.path.expanduser("~"), ".python_history")
if sys.version_info.major >= 3:
# python3
try:
readline.read_history_file(histfile)
h_len = readline.get_current_history_length()
except os.FileNotFoundError:
open(histfile, 'wb').close()
h_len = 0
elif sys.version_info.major == 2:
# python2
try:
readline.read_history_file(histfile)
h_len = readline.get_current_history_length()
except IOError:
open(histfile, 'wb').close()
h_len = 0
else:
h_len = 0
print("readline history length: {}".format(
readline.get_current_history_length()
))
atexit.register(save, h_len, histfile)
开发者ID:s-light,项目名称:OLA_test_pattern_generator,代码行数:30,代码来源:readline_history.py
示例2: 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
示例3: __str__
def __str__(self):
global h
h = History()
for x in range(0,readline.get_current_history_length()-1):
#print "length %d %s" % (x,readline.get_history_item(x))
h.append(readline.get_history_item(x))
return self.str % readline.get_current_history_length()
开发者ID:hubt,项目名称:dotfiles,代码行数:7,代码来源:pythonrc.py
示例4: _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
示例5: h
def h(recent=25):
"""show command history
recent: number of recent command lines to show.
"""
length = readline.get_current_history_length()
start = 0 if length <= recent else (length - recent)
for x in xrange(start, readline.get_current_history_length()):
print(readline.get_history_item(x + 1))
开发者ID:dongshengmu,项目名称:interact,代码行数:8,代码来源:util.py
示例6: write_to_log
def write_to_log(self):
if not os.path.isfile(log_file_name):
with open(log_file_name, 'w') as fp:
pass
with open(log_file_name, 'a') as fp:
if readline.get_current_history_length():
fp.write(str(datetime.now()) + '\t' + readline.get_history_item(readline.get_current_history_length()) + '\n')
开发者ID:raghrv,项目名称:django_home,代码行数:8,代码来源:cmd_inf.py
示例7: execute
def execute(limit=10):
import readline
if limit <= 0:
limit = 1000 # Some big number
if readline.get_current_history_length() < limit:
limit = readline.get_current_history_length()
for index in range(readline.get_current_history_length()-limit, readline.get_current_history_length()):
s = readline.get_history_item(index+1)
print " %d: %s" % (index+1, s)
开发者ID:afeset,项目名称:miner2-tools,代码行数:9,代码来源:statements.py
示例8: last_history
def last_history(line):
if line == "":
return False
if (readline.get_current_history_length() == 0
or readline.get_history_item(
readline.get_current_history_length()) != line.encode("utf-8")):
readline.add_history(line.encode("utf-8"))
return True
return False
开发者ID:lp0,项目名称:rlmutag,代码行数:9,代码来源:flactag.py
示例9: 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
示例10: __repr__
def __repr__(self):
"""print out current history information"""
command = get_history_item(get_current_history_length())
if command == 'history':
length = get_current_history_length()
if length > 1:
return reduce(lambda x, y: '%s\n%s' % (x, y),
imap(get_history_item, xrange(1, length)))
else:
return ''
else:
return '<%s instance>' % __name__
开发者ID:rchenmit,项目名称:python-startup,代码行数:12,代码来源:History.py
示例11: 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
示例12: 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
示例13: history
def history(start=None, end=None, lines=30,
number=False):
"""
Display the history starting from entry 'start' to
entry 'end'. Only available on platforms where the
readline module can be imported.
History starts from 0 and goes to a large number.
The history file is $ZENHOME/.pyhistory by default.
@parameter start: Line number to start printing
@type start: integer
@parameter end: Line number to finish printing
@type end: integer
@parameter lines: number of lines to show if no end
@type lines: integer
@parameter number: show the line numbers?
@type number: boolean
"""
if readline is not None:
maxHistLength = readline.get_current_history_length()
if start is None:
start = maxHistLength
if end is None:
end = maxHistLength - lines
if start < end:
end, start = start, end
for i in range(end, start):
if number:
print i, readline.get_history_item(i)
else:
print readline.get_history_item(i)
开发者ID:zenoss,项目名称:zenoss-prodbin,代码行数:32,代码来源:zendmd.py
示例14: _t_add
def _t_add(self, cmd, line):
"""Code shared by t_add, bug_add and n_add."""
parser = self._parser_t_add(cmd)
args = parser.parse_args(line)
line = " ".join(args.cmd)
if not line:
raise BadUsageException("Missing parameters")
projectName, title, keywordDict = parseutils.parseLine(line)
projectName = self._realProjectName(projectName)
if not title:
raise BadUsageException("Missing title")
if args.crypt:
# Obfuscate line in history
length = readline.get_current_history_length()
if length > 0: # Ensure history is positive to avoid crash with bad readline setup
readline.replace_history_item(length - 1, "%s %s " % (cmd,
line.replace(title, "<...encrypted...>")))
# Encrypt title
title = self.cryptoMgr.encrypt(title)
task = dbutils.addTask(projectName, title, keywordDict)
if not task:
tui.reinjectInRawInput("%s %s" % (cmd, line))
return None
self.lastTaskId = task.id
if args.describe:
self.do_t_describe(self.lastTaskId)
return task
开发者ID:fabaff,项目名称:yokadi,代码行数:31,代码来源:taskcmd.py
示例15: operate_and_get_next
def operate_and_get_next(count, char):
current_line = readline.where_history()
offset = readline.get_current_history_length() - current_line
# Accept the current line and set the hook to rewind history
result = readline.accept_line(1, char)
readline.set_pre_input_hook(pre_input_hook_factory(offset, char))
return result
开发者ID:0xf4,项目名称:pythonrc,代码行数:7,代码来源:pythonrc.py
示例16: 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
示例17: hist
def hist():
"""Fetches command line history. Returns dict of all lines."""
history_dict = {}
# create history_list
for i in range(readline.get_current_history_length()):
history_dict[i+1] = (readline.get_history_item(i+1))
return history_dict
开发者ID:ztaira14,项目名称:myhistory,代码行数:7,代码来源:myhistory.py
示例18: 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
示例19: __history_try_search
def __history_try_search(cls, text):
history_range = range(readline.get_current_history_length(), 1, -1)
for i in history_range:
item = readline.get_history_item(i)
if item.startswith(text):
return item
return ''
开发者ID:gstoeckel,项目名称:katello,代码行数:7,代码来源:shell.py
示例20: run
def run(self):
# Preserve existing history
if self.preserve_history:
old_history = [readline.get_history_item(index) for index in xrange(readline.get_current_history_length())]
readline.clear_history()
map(readline.add_history, self.history)
readline.set_completer(self.complete)
readline.parse_and_bind("bind ^I rl_complete")
while True:
cmdline = raw_input("%s > " % (self.prefix,))
self.last_wd_complete = ("", ())
if not cmdline:
continue
# Try to dispatch command
try:
self.execute(cmdline)
except SystemExit, e:
print "Exiting shell: %s" % (e.code,)
break
except UnknownCommand, e:
print "Command '%s' unknown." % (e,)
开发者ID:muelli,项目名称:CalDAVClientLibrary,代码行数:25,代码来源:baseshell.py
注:本文中的readline.get_current_history_length函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论