OILS / demo / cpython / readline_mod.py View on Github | oilshell.org

35 lines, 20 significant
1#!/usr/bin/env python2
2"""
3pyreadline.py
4
5TODO: Set up history/completion, and then strace. Where is the canonical example?
6
7NOTE: InteractiveLineReader does use raw_input(). Should it use something
8else?
9
10"""
11from __future__ import print_function
12
13import sys
14import readline
15
16
17def main(argv):
18 try:
19 prompt_str = argv[1]
20 except IndexError:
21 prompt_str = '! '
22 import os
23 readline.parse_and_bind("tab: complete")
24 print('PID %d' % os.getpid())
25 while True:
26 x = raw_input(prompt_str)
27 print(x)
28
29
30if __name__ == '__main__':
31 try:
32 main(sys.argv)
33 except RuntimeError as e:
34 print('FATAL: %s' % e, file=sys.stderr)
35 sys.exit(1)