def __enter__(self):
# we only do something if we have readline
if not haveReadline:
return self
## Set up the new history context
self.historyFile = os.path.join( os.getenv('HOME'), ".{0}.history".format(self.basename))
(h, self.oldhistFile) = tempfile.mkstemp(prefix=self.basename, suffix=".hist", dir="/tmp")
# only need the filename, really
os.close(h)
readline.write_history_file(self.oldhistFile)
readline.clear_history()
# if reading the old history fails, fail silently
# (the file might not exist yet)
try:
readline.read_history_file(self.historyFile)
except:
pass
# store the old completer, install our own one
readline.parse_and_bind("tab: complete")
#readline.parse_and_bind("C-c: backward-kill-line")
self.oldCompleter = readline.get_completer()
readline.set_completer(self.completer)
return self
# clean up the context
评论列表
文章目录