2 # -*- coding: iso-8859-15 -*-
11 class irlcompleter(rlcompleter.Completer):
12 def complete(self, text, state):
14 # you could replace \t to 4 or 8 spaces if you prefer indent via spaces
15 return ['\t', None][state]
17 return rlcompleter.Completer.complete(self, text, state)
20 class HistoryConsole(code.InteractiveConsole):
21 def __init__(self, locales=None, filename="<console>", histfile=os.path.expanduser("~/.console-history"), custom_interpreter=None):
22 code.InteractiveConsole.__init__(self, locales, filename)
23 self.init_history(histfile)
24 self.custom_interpreter = custom_interpreter
26 def init_history(self, histfile):
27 readline.parse_and_bind("tab: complete")
28 readline.set_completer(irlcompleter().complete)
30 if hasattr(readline, "read_history_file"):
32 readline.read_history_file(histfile)
35 atexit.register(self.save_history, histfile)
37 def save_history(self, histfile):
38 readline.write_history_file(histfile)
41 line = line.encode("iso-8859-15", "replace")
42 if self.custom_interpreter:
43 if self.custom_interpreter(line):
45 return code.InteractiveConsole.push(self, line)
48 if __name__ == "__main__":
49 con = HistoryConsole(locales=locals())
50 con.interact(banner="")