blob: bebab1e5e38ee06e7369e30328839d184a47c90b [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)
Guido van Rossumb940e112007-01-10 16:19:56 +000026 except _tkinter.TclError as msg:
Collin Winter6f2df4d2007-07-17 20:59:35 +000027 print('TclError:', msg)
Tim Peters182b5ac2004-07-18 06:16:08 +000028 else:
Collin Winter6f2df4d2007-07-17 20:59:35 +000029 if result: print(result)
Tim Peters182b5ac2004-07-18 06:16:08 +000030 cmd = ''