blob: 4f6fdee9038f4fe2e5b5c755edc7de397e26bc31 [file] [log] [blame]
Guido van Rossum18468821994-06-20 07:49:28 +00001# This is about all it requires to write a wish shell in Python!
2
Jack Jansen10d0f8f1995-10-23 14:36:05 +00003import _tkinter
Guido van Rossum55618ef1995-09-07 19:44:48 +00004import os
Guido van Rossum18468821994-06-20 07:49:28 +00005
Jack Jansen10d0f8f1995-10-23 14:36:05 +00006tk = _tkinter.create(os.environ['DISPLAY'], 'wish', 'Tk', 1)
Guido van Rossum18468821994-06-20 07:49:28 +00007tk.call('update')
8
9cmd = ''
10
11while 1:
12 if cmd: prompt = ''
13 else: prompt = '% '
14 try:
15 line = raw_input(prompt)
16 except EOFError:
17 break
18 cmd = cmd + (line + '\n')
Guido van Rossum18468821994-06-20 07:49:28 +000019 if tk.getboolean(tk.call('info', 'complete', cmd)):
Guido van Rossum8d1e4391994-06-20 08:13:02 +000020 tk.record(line)
Guido van Rossum18468821994-06-20 07:49:28 +000021 try:
22 result = tk.call('eval', cmd)
Jack Jansen10d0f8f1995-10-23 14:36:05 +000023 except _tkinter.TclError, msg:
Guido van Rossum18468821994-06-20 07:49:28 +000024 print 'TclError:', msg
25 else:
26 if result: print result
27 cmd = ''