blob: eec4b695307686e11ab960615fb218efcd37c154 [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
3import tkinter
Guido van Rossum55618ef1995-09-07 19:44:48 +00004import os
Guido van Rossum18468821994-06-20 07:49:28 +00005
Guido van Rossum55618ef1995-09-07 19:44:48 +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)
23 except tkinter.TclError, msg:
24 print 'TclError:', msg
25 else:
26 if result: print result
27 cmd = ''