blob: 35e012c7dffc6fc038af35f8511d1bdb91225664 [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
Neal Norwitzce96f692006-03-17 06:49:51 +00005import sys
Guido van Rossum18468821994-06-20 07:49:28 +00006
Jack Jansen10d0f8f1995-10-23 14:36:05 +00007tk = _tkinter.create(os.environ['DISPLAY'], 'wish', 'Tk', 1)
Guido van Rossum18468821994-06-20 07:49:28 +00008tk.call('update')
9
10cmd = ''
11
12while 1:
Tim Peters182b5ac2004-07-18 06:16:08 +000013 if cmd: prompt = ''
14 else: prompt = '% '
15 try:
Neal Norwitzce96f692006-03-17 06:49:51 +000016 sys.stdout.write(prompt)
17 sys.stdout.flush()
18 line = sys.stdin.readline()
Tim Peters182b5ac2004-07-18 06:16:08 +000019 except EOFError:
20 break
21 cmd = cmd + (line + '\n')
22 if tk.getboolean(tk.call('info', 'complete', cmd)):
23 tk.record(line)
24 try:
25 result = tk.call('eval', cmd)
26 except _tkinter.TclError, msg:
27 print 'TclError:', msg
28 else:
29 if result: print result
30 cmd = ''