Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1 | # This is about all it requires to write a wish shell in Python! |
| 2 | |
Jack Jansen | 10d0f8f | 1995-10-23 14:36:05 +0000 | [diff] [blame] | 3 | import _tkinter |
Guido van Rossum | 55618ef | 1995-09-07 19:44:48 +0000 | [diff] [blame] | 4 | import os |
Neal Norwitz | ce96f69 | 2006-03-17 06:49:51 +0000 | [diff] [blame] | 5 | import sys |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 6 | |
Jack Jansen | 10d0f8f | 1995-10-23 14:36:05 +0000 | [diff] [blame] | 7 | tk = _tkinter.create(os.environ['DISPLAY'], 'wish', 'Tk', 1) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 8 | tk.call('update') |
| 9 | |
| 10 | cmd = '' |
| 11 | |
| 12 | while 1: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 13 | if cmd: prompt = '' |
| 14 | else: prompt = '% ' |
| 15 | try: |
Neal Norwitz | ce96f69 | 2006-03-17 06:49:51 +0000 | [diff] [blame] | 16 | sys.stdout.write(prompt) |
| 17 | sys.stdout.flush() |
| 18 | line = sys.stdin.readline() |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 19 | 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 Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 26 | except _tkinter.TclError as msg: |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 27 | print('TclError:', msg) |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 28 | else: |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 29 | if result: print(result) |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 30 | cmd = '' |