def _load_history(self): """Load history file and register dump on exit.""" # Create a file without truncating it in case it exists. open(config.history_path, 'a').close() readline.set_history_length(100) try: readline.read_history_file(config.history_path) except IOError: pass atexit.register(readline.write_history_file, config.history_path)
def setup(self): """ Initialization of third-party libraries Setting interpreter history. Setting appropriate completer function. :return: """ if not os.path.exists(self.history_file): open(self.history_file, 'a+').close() readline.read_history_file(self.history_file) readline.set_history_length(self.history_length) atexit.register(readline.write_history_file, self.history_file) readline.parse_and_bind('set enable-keypad on') readline.set_completer(self.complete) readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete")
except ImportError: import readline ## ===== Interactive shell history ====================== ## # History file located in ~/.config dir _HISTFILE = os.path.join(os.getenv('HOME'), '.config/.python_history') # Read history file if os.path.exists(_HISTFILE): readline.read_history_file(_HISTFILE) # Set history file location def save_hist(): readline.write_history_file(_HISTFILE) readline.set_history_length(1000) atexit.register(save_hist) del save_hist ## ===== Prompt ========================================= ## def ascii_escape(body): return '\001\033[%sm\002' % body class Prompt(object): cCyan = ascii_escape('0;36') cReset = ascii_escape('0') def __str__(self): now = datetime.datetime.now() clock = '%02d:%02d:%02d' % (now.hour, now.minute, now.second) return self.cCyan + clock + ' >>> ' + self.cReset
if text: matches = [s for s in options if s.startswith(text)] else: matches = options[:] try: res = matches[state] except: res = None return res readline.set_completer(complete) readline.parse_and_bind("tab: complete") readline.set_history_length(-1) hfn = os.path.expanduser("~/.dnash_history") if not os.path.isfile(hfn): os.mknod(hfn) readline.read_history_file(hfn) def save_history(): readline.write_history_file(hfn) atexit.register(save_history) print("Try 'help' to get started")
## ===== Interactive shell history ====================== ## if 1: # History file located in ~/.config dir _HISTFILE = os.path.join(os.getenv('HOME'), '.config/.python_history') # Read history file if os.path.exists(_HISTFILE): readline.read_history_file(_HISTFILE) # Set history file location def save_hist(): readline.write_history_file(_HISTFILE) readline.set_history_length(1000) atexit.register(save_hist) del save_hist ## ===== Prompt ========================================= ## def ascii_escape(body): return '\001\033[%sm\002' % body class Prompt(object): cCyan = ascii_escape('0;36') cReset = ascii_escape('0') def __str__(self):