|
| 1 | +pyrepl |
| 2 | +====== |
| 3 | + |
| 4 | +For ages now, I've been working on and off on a replacement for |
| 5 | +readline for use from Python. readline is undoubtedly great, but a |
| 6 | +couple of things irritate me about it. One is the inability to do |
| 7 | +sane multi-line editing. Have you ever typed something like:: |
| 8 | + |
| 9 | + >>> for i in range(10): |
| 10 | + ... for i in range(10): |
| 11 | + ... print i*j |
| 12 | + |
| 13 | +into a Python top-level? Grr, that "i" on the second line should have |
| 14 | +been a "j". Wouldn't it be nice if you could just press "up" on your |
| 15 | +keyboard and fix it? This was one of the aims I kept in mind when |
| 16 | +writing pyrepl (or pyrl as I used to call it, but that name's |
| 17 | +`taken <http://www.algonet.se/~jsjogren/oscar/cython/>`_). |
| 18 | + |
| 19 | +Another irritation of readline is the GPL. I'm not even nearly as |
| 20 | +anti-GPL as some, but I don't want to have to GPL my program just so I |
| 21 | +can use readline. |
| 22 | + |
| 23 | +0.7 adds to the version that runs an a terminal an experimental |
| 24 | +version that runs in a pygame surface. A long term goal is |
| 25 | +Mathematica-like notebooks, but that's a loong way off... |
| 26 | + |
| 27 | +Anyway, after many months of intermittent toil I present: |
| 28 | + |
| 29 | + |
| 30 | +Dependencies: Python 2.7 with the termios and curses modules built (I |
| 31 | +don't really use curses, but I need the terminfo functions that live |
| 32 | +in the curses module), or pygame installed (if you want to live on the |
| 33 | +bleeding edge). |
| 34 | + |
| 35 | +There are probably portability gremlins in some of the ioctl using |
| 36 | +code. Fixes gratefully received! |
| 37 | + |
| 38 | +Features: |
| 39 | + * sane multi-line editing |
| 40 | + * history, with incremental search |
| 41 | + * completion, including displaying of available options |
| 42 | + * a fairly large subset of the readline emacs-mode key bindings (adding |
| 43 | + more is mostly just a matter of typing) |
| 44 | + * Deliberately liberal, Python-style license |
| 45 | + * a new python top-level that I really like; possibly my favourite |
| 46 | + feature I've yet added is the ability to type:: |
| 47 | + |
| 48 | + ->> from __f |
| 49 | + |
| 50 | + and hit TAB to get:: |
| 51 | + |
| 52 | + ->> from __future__ |
| 53 | + |
| 54 | + then you type " import n" and hit tab again to get:: |
| 55 | + |
| 56 | + ->> from __future__ import nested_scopes |
| 57 | + |
| 58 | + (this is very addictive!). |
| 59 | + |
| 60 | + * no global variables, so you can run two independent |
| 61 | + readers without having their histories interfering. |
| 62 | + * An experimental version that runs in a pygame surface. |
| 63 | + |
| 64 | +pyrepl currently consists of four major classes:: |
| 65 | + |
| 66 | + Reader - HistoricalReader - CompletingReader - PythonReader |
| 67 | + |
| 68 | + |
| 69 | +There's also a **UnixConsole** class that handles the low-level |
| 70 | +details. |
| 71 | + |
| 72 | +Each of these lives in it's own file, and there are a bunch of support |
| 73 | +files (including a C module that just provides a bit of a speed up - |
| 74 | +building it is strictly optional). |
| 75 | + |
| 76 | +IMHO, the best way to get a feel for how it works is to type:: |
| 77 | + |
| 78 | + $ python pythoni |
| 79 | + |
| 80 | +and just play around. If you're used to readline's emacs-mode, you |
| 81 | +should feel right at home. One point that might confuse: because the |
| 82 | +arrow keys are used to move up and down in the command currently being |
| 83 | +edited, you need to use ^P and ^N to move through the history. |
| 84 | + |
0 commit comments