From arigo at codespeak.net Sun Apr 6 10:15:40 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sun, 6 Apr 2008 10:15:40 +0200 (CEST) Subject: [pyrepl-checkins] r53416 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20080406081540.623B216A645@codespeak.net> Author: arigo Date: Sun Apr 6 10:15:38 2008 New Revision: 53416 Modified: pyrepl/trunk/pyrepl/pyrepl/reader.py Log: It may be a matter of taste (or an emacs deformation), but I find it far less invasive to display the messages at the bottom of the input area instead of just above the cursor position. (Old behavior still available by setting msg_at_bottom = False). Modified: pyrepl/trunk/pyrepl/pyrepl/reader.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/reader.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/reader.py Sun Apr 6 10:15:38 2008 @@ -221,6 +221,8 @@ Helpful text may appear here at some point in the future when I'm feeling more loquacious than I am now.""" + msg_at_bottom = True + def __init__(self, console): self.buffer = [] self.ps1 = "->> " @@ -264,7 +266,7 @@ for ln, line in zip(range(len(lines)), lines): ll = len(line) if 0 <= p <= ll: - if self.msg: + if self.msg and not self.msg_at_bottom: for mline in self.msg.split("\n"): screen.append(mline) screeninfo.append((0, [])) @@ -287,6 +289,10 @@ screeninfo.append((0, l2[wrapcount*w - lp:]+[1])) self.screeninfo = screeninfo self.cxy = self.pos2xy(self.pos) + if self.msg and self.msg_at_bottom: + for mline in self.msg.split("\n"): + screen.append(mline) + screeninfo.append((0, [])) return screen def bow(self, p=None): From arigo at codespeak.net Sun Apr 6 16:30:46 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sun, 6 Apr 2008 16:30:46 +0200 (CEST) Subject: [pyrepl-checkins] r53453 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20080406143046.172BE16A716@codespeak.net> Author: arigo Date: Sun Apr 6 16:30:45 2008 New Revision: 53453 Modified: pyrepl/trunk/pyrepl/pyrepl/commands.py pyrepl/trunk/pyrepl/pyrepl/reader.py Log: Don't leave a previous error message on the screen when leaving with Ctrl-D. Modified: pyrepl/trunk/pyrepl/pyrepl/commands.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/commands.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/commands.py Sun Apr 6 16:30:45 2008 @@ -333,6 +333,7 @@ b = r.buffer if ( r.pos == 0 and len(b) == 0 # this is something of a hack and self.event[-1] == "\004"): + r.immediately_clear_message() r.console.finish() raise EOFError for i in range(r.get_arg()): Modified: pyrepl/trunk/pyrepl/pyrepl/reader.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/reader.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/reader.py Sun Apr 6 16:30:45 2008 @@ -466,6 +466,13 @@ self.dirty = 1 self.console.beep() + def immediately_clear_message(self): + if self.msg: + self.msg = '' + self.dirty = 1 + if self.dirty: + self.refresh() + def refresh(self): """Recalculate and refresh the screen.""" # this call sets up self.cxy, so call it first. From arigo at codespeak.net Sun Apr 6 16:31:54 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sun, 6 Apr 2008 16:31:54 +0200 (CEST) Subject: [pyrepl-checkins] r53454 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20080406143154.0CE8B16A716@codespeak.net> Author: arigo Date: Sun Apr 6 16:31:53 2008 New Revision: 53454 Modified: pyrepl/trunk/pyrepl/pyrepl/commands.py pyrepl/trunk/pyrepl/pyrepl/reader.py Log: Simplification. Modified: pyrepl/trunk/pyrepl/pyrepl/commands.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/commands.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/commands.py Sun Apr 6 16:31:53 2008 @@ -333,7 +333,7 @@ b = r.buffer if ( r.pos == 0 and len(b) == 0 # this is something of a hack and self.event[-1] == "\004"): - r.immediately_clear_message() + r.update_screen() r.console.finish() raise EOFError for i in range(r.get_arg()): Modified: pyrepl/trunk/pyrepl/pyrepl/reader.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/reader.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/reader.py Sun Apr 6 16:31:53 2008 @@ -466,10 +466,7 @@ self.dirty = 1 self.console.beep() - def immediately_clear_message(self): - if self.msg: - self.msg = '' - self.dirty = 1 + def update_screen(self): if self.dirty: self.refresh() From arigo at codespeak.net Mon Apr 7 10:52:55 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 7 Apr 2008 10:52:55 +0200 (CEST) Subject: [pyrepl-checkins] r53507 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20080407085255.75B5516A3D9@codespeak.net> Author: arigo Date: Mon Apr 7 10:52:53 2008 New Revision: 53507 Added: pyrepl/trunk/pyrepl/pyrepl/curses.py (contents, props changed) Modified: pyrepl/trunk/pyrepl/pyrepl/__init__.py pyrepl/trunk/pyrepl/pyrepl/commands.py pyrepl/trunk/pyrepl/pyrepl/keymap.py pyrepl/trunk/pyrepl/pyrepl/pygame_keymap.py pyrepl/trunk/pyrepl/pyrepl/reader.py pyrepl/trunk/pyrepl/pyrepl/unix_console.py pyrepl/trunk/pyrepl/pyrepl/unix_eventqueue.py Log: mwh please forgive me: some minor hacking to make the situation on top of PyPy saner with respect to _minimal_curses. This removes the dependency on the curses module, provided the _minimal_curses module is importable (either as a PyPy built-in module, or else the pure Python ctypes-based version works too). Modified: pyrepl/trunk/pyrepl/pyrepl/__init__.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/__init__.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/__init__.py Mon Apr 7 10:52:53 2008 @@ -16,6 +16,3 @@ # RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import commands -import reader Modified: pyrepl/trunk/pyrepl/pyrepl/commands.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/commands.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/commands.py Mon Apr 7 10:52:53 2008 @@ -17,7 +17,6 @@ # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -from curses import ascii import sys, os # Catgories of actions: @@ -120,7 +119,7 @@ b = r.buffer eol = r.eol() for c in b[r.pos:eol]: - if not ascii.isspace(c): + if not c.isspace(): self.kill_range(r.pos, eol) return else: Added: pyrepl/trunk/pyrepl/pyrepl/curses.py ============================================================================== --- (empty file) +++ pyrepl/trunk/pyrepl/pyrepl/curses.py Mon Apr 7 10:52:53 2008 @@ -0,0 +1,18 @@ + +# Some try-import logic for two purposes: avoiding to bring in the whole +# pure Python curses package if possible; and, in _curses is not actually +# present, falling back to _minimal_curses (which is either a ctypes-based +# pure Python module or a PyPy built-in module). +try: + import _curses +except ImportError: + try: + import _minimal_curses as _curses + except ImportError: + # Who knows, maybe some environment has "curses" but not "_curses". + # If not, at least the following import gives a clean ImportError. + import _curses + +setupterm = _curses.setupterm +tigetstr = _curses.tigetstr +tparm = _curses.tparm Modified: pyrepl/trunk/pyrepl/pyrepl/keymap.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/keymap.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/keymap.py Mon Apr 7 10:52:53 2008 @@ -52,8 +52,6 @@ - all of these are the tab character. Can you think of any more? """ -from curses import ascii - _escapes = { '\\':'\\', "'":"'", @@ -156,7 +154,7 @@ if ctrl: if len(ret) > 1: raise KeySpecError, "\\C- must be followed by a character" - ret = ascii.ctrl(ret) + ret = chr(ord(ret) & 0x1f) # curses.ascii.ctrl() if meta: ret = ['\033', ret] else: Modified: pyrepl/trunk/pyrepl/pyrepl/pygame_keymap.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/pygame_keymap.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/pygame_keymap.py Mon Apr 7 10:52:53 2008 @@ -35,7 +35,6 @@ # XXX it's actually possible to test this module, so it should have a # XXX test suite. -from curses import ascii from pygame.locals import * _escapes = { @@ -137,7 +136,8 @@ `c`, s + 2, repr(key)) else: if ctrl: - ret = unicode(ascii.ctrl(key[s])) + ret = chr(ord(key[s]) & 0x1f) # curses.ascii.ctrl() + ret = unicode(ret) else: ret = unicode(key[s]) s += 1 Modified: pyrepl/trunk/pyrepl/pyrepl/reader.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/reader.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/reader.py Mon Apr 7 10:52:53 2008 @@ -19,7 +19,6 @@ import types, unicodedata from pyrepl import commands -from curses import ascii from pyrepl import input def _make_unctrl_map(): Modified: pyrepl/trunk/pyrepl/pyrepl/unix_console.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/unix_console.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/unix_console.py Mon Apr 7 10:52:53 2008 @@ -17,9 +17,10 @@ # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -import termios, curses, select, os, struct, errno +import termios, select, os, struct, errno import signal, re, time, sys from fcntl import ioctl +from pyrepl import curses from pyrepl.fancy_termios import tcgetattr, tcsetattr from pyrepl.console import Console, Event from pyrepl import unix_eventqueue Modified: pyrepl/trunk/pyrepl/pyrepl/unix_eventqueue.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/unix_eventqueue.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/unix_eventqueue.py Mon Apr 7 10:52:53 2008 @@ -22,7 +22,7 @@ from pyrepl import keymap from pyrepl.console import Event -import curses +from pyrepl import curses from termios import tcgetattr, VERASE _keynames = { From arigo at codespeak.net Mon Apr 7 18:37:29 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 7 Apr 2008 18:37:29 +0200 (CEST) Subject: [pyrepl-checkins] r53530 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20080407163729.4758416A119@codespeak.net> Author: arigo Date: Mon Apr 7 18:37:27 2008 New Revision: 53530 Modified: pyrepl/trunk/pyrepl/pyrepl/unix_console.py Log: Fix a bug. I think. At least the crash disappears, but I'm not sure about this code so I don't know if this is a proper fix. Modified: pyrepl/trunk/pyrepl/pyrepl/unix_console.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/unix_console.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/unix_console.py Mon Apr 7 18:37:27 2008 @@ -196,7 +196,7 @@ offset = cy - height + 1 elif offset > 0 and len(screen) < offset + height: offset = max(len(screen) - height, 0) - screen.append([]) + screen.append("") oldscr = self.screen[old_offset:old_offset + height] newscr = screen[offset:offset + height] From arigo at codespeak.net Tue Apr 8 12:23:10 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 8 Apr 2008 12:23:10 +0200 (CEST) Subject: [pyrepl-checkins] r53568 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20080408102310.0DDA716A9DB@codespeak.net> Author: arigo Date: Tue Apr 8 12:23:09 2008 New Revision: 53568 Added: pyrepl/trunk/pyrepl/pyrepl/readline.py - copied, changed from r53567, pypy/dist/pypy/lib/readline.py pyrepl/trunk/pyrepl/pyrepl/simple_interact.py (contents, props changed) Log: Add these modules directly into pyrepl, where they can be reused to give the same CPython-like-but-multiline prompt on top of CPython. Copied: pyrepl/trunk/pyrepl/pyrepl/readline.py (from r53567, pypy/dist/pypy/lib/readline.py) ============================================================================== --- pypy/dist/pypy/lib/readline.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/readline.py Tue Apr 8 12:23:09 2008 @@ -1,5 +1,6 @@ """A compatibility wrapper reimplementing the 'readline' standard module -on top of pyrepl. Not all functionalities are supported. +on top of pyrepl. Not all functionalities are supported. Contains +extensions for multiline input. """ import sys, os @@ -29,7 +30,10 @@ 'set_history_length', 'set_pre_input_hook', 'set_startup_hook', - 'write_history_file'] + 'write_history_file', + # ---- multiline extensions ---- + 'multiline_input', + ] # ____________________________________________________________ Added: pyrepl/trunk/pyrepl/pyrepl/simple_interact.py ============================================================================== --- (empty file) +++ pyrepl/trunk/pyrepl/pyrepl/simple_interact.py Tue Apr 8 12:23:09 2008 @@ -0,0 +1,42 @@ +"""This is an alternative to python_reader which tries to emulate +the CPython prompt as closely as possible, with the exception of +allowing multiline input and multiline history entries. +""" + +import sys +from pyrepl.readline import multiline_input + + +def run_multiline_interactive_console(mainmodule): + import code + if mainmodule is None: + import __main__ as mainmodule + console = code.InteractiveConsole(mainmodule.__dict__) + + def more_lines(unicodetext): + # ooh, look at the hack: + src = "#coding:utf-8\n"+unicodetext.encode('utf-8') + try: + code = console.compile(src, '', 'single') + except (OverflowError, SyntaxError, ValueError): + return False + else: + return code is None + + while 1: + try: + ps1 = getattr(sys, 'ps1', '>>> ') + ps2 = getattr(sys, 'ps2', '... ') + try: + statement = multiline_input(more_lines, ps1, ps2) + except EOFError: + break + # XXX with Alt-Enter we can actually enter more than one + # statement, and compile() ignores everything after the + # first statement in 'single' mode... We should either + # find some obscure workaround or tweak PyPy's compiler. + more = console.push(statement) + assert not more + except KeyboardInterrupt: + console.write("\nKeyboardInterrupt\n") + console.resetbuffer() From arigo at codespeak.net Tue Apr 8 13:03:50 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 8 Apr 2008 13:03:50 +0200 (CEST) Subject: [pyrepl-checkins] r53571 - in pyrepl/trunk/pyrepl: . pyrepl Message-ID: <20080408110350.BB03316A9AF@codespeak.net> Author: arigo Date: Tue Apr 8 13:03:49 2008 New Revision: 53571 Added: pyrepl/trunk/pyrepl/pythoni1 (contents, props changed) Modified: pyrepl/trunk/pyrepl/pyrepl/simple_interact.py Log: Add "pythoni1", which tries to look just like the CPython prompt. Modified: pyrepl/trunk/pyrepl/pyrepl/simple_interact.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/simple_interact.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/simple_interact.py Tue Apr 8 13:03:49 2008 @@ -7,7 +7,7 @@ from pyrepl.readline import multiline_input -def run_multiline_interactive_console(mainmodule): +def run_multiline_interactive_console(mainmodule=None): import code if mainmodule is None: import __main__ as mainmodule Added: pyrepl/trunk/pyrepl/pythoni1 ============================================================================== --- (empty file) +++ pyrepl/trunk/pyrepl/pythoni1 Tue Apr 8 13:03:49 2008 @@ -0,0 +1,16 @@ +#!/usr/bin/env python +""" This is an alternative to pythoni which tries to look like the +CPython prompt as much as possible, with the exception of allowing +multiline input and multiline history entries. +""" + +import os, sys +from pyrepl import readline +from pyrepl.simple_interact import run_multiline_interactive_console + +sys.modules['readline'] = readline + +if os.getenv('PYTHONSTARTUP'): + execfile(os.getenv('PYTHONSTARTUP')) + +run_multiline_interactive_console() From arigo at codespeak.net Tue Apr 8 13:07:25 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 8 Apr 2008 13:07:25 +0200 (CEST) Subject: [pyrepl-checkins] r53572 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20080408110725.3F55A16A9DB@codespeak.net> Author: arigo Date: Tue Apr 8 13:07:24 2008 New Revision: 53572 Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py Log: Don't show error messages. I personally find them not very useful and they make the prompt feel too different from CPython's IMHO. Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/readline.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/readline.py Tue Apr 8 13:07:24 2008 @@ -41,6 +41,9 @@ readline_completer = None completer_delims = dict.fromkeys(' \t\n`~!@#$%^&*()-=+[{]}\\|;:\'",<>/?') + def error(self, msg="none"): + pass # don't show error messages by default + def get_stem(self): b = self.buffer p = self.pos - 1 From arigo at codespeak.net Tue Apr 8 13:10:50 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 8 Apr 2008 13:10:50 +0200 (CEST) Subject: [pyrepl-checkins] r53573 - pyrepl/trunk/pyrepl Message-ID: <20080408111050.37CB116A9DC@codespeak.net> Author: arigo Date: Tue Apr 8 13:10:49 2008 New Revision: 53573 Modified: pyrepl/trunk/pyrepl/pythoni1 Log: Print banner. Modified: pyrepl/trunk/pyrepl/pythoni1 ============================================================================== --- pyrepl/trunk/pyrepl/pythoni1 (original) +++ pyrepl/trunk/pyrepl/pythoni1 Tue Apr 8 13:10:49 2008 @@ -13,4 +13,5 @@ if os.getenv('PYTHONSTARTUP'): execfile(os.getenv('PYTHONSTARTUP')) +print 'Python', sys.version run_multiline_interactive_console() From arigo at codespeak.net Tue Apr 8 13:47:18 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 8 Apr 2008 13:47:18 +0200 (CEST) Subject: [pyrepl-checkins] r53575 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20080408114718.39D3F16AA07@codespeak.net> Author: arigo Date: Tue Apr 8 13:47:18 2008 New Revision: 53575 Modified: pyrepl/trunk/pyrepl/pyrepl/simple_interact.py Log: Add early imports to give a clean ImportError if something is missing. Modified: pyrepl/trunk/pyrepl/pyrepl/simple_interact.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/simple_interact.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/simple_interact.py Tue Apr 8 13:47:18 2008 @@ -6,6 +6,12 @@ import sys from pyrepl.readline import multiline_input +# please don't remove the following imports, useful +# to give an early ImportError if something is missing +import pyrepl.unix_console +import pyrepl.historical_reader +import pyrepl.completing_reader + def run_multiline_interactive_console(mainmodule=None): import code From arigo at codespeak.net Tue Apr 8 14:25:39 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 8 Apr 2008 14:25:39 +0200 (CEST) Subject: [pyrepl-checkins] r53579 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20080408122539.2A21916A987@codespeak.net> Author: arigo Date: Tue Apr 8 14:25:38 2008 New Revision: 53579 Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py pyrepl/trunk/pyrepl/pyrepl/simple_interact.py Log: The lazy imports do more harm than good. Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/readline.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/readline.py Tue Apr 8 14:25:38 2008 @@ -4,7 +4,11 @@ """ import sys, os -import pyrepl.curses # check to give an early ImportError +from pyrepl import commands +from pyrepl.historical_reader import HistoricalReader +from pyrepl.completing_reader import CompletingReader +from pyrepl.unix_console import UnixConsole + ENCODING = 'latin1' # XXX hard-coded @@ -37,7 +41,7 @@ # ____________________________________________________________ -class _ReaderMixin(object): +class ReadlineAlikeReader(HistoricalReader, CompletingReader): readline_completer = None completer_delims = dict.fromkeys(' \t\n`~!@#$%^&*()-=+[{]}\\|;:\'",<>/?') @@ -92,27 +96,27 @@ more_lines = None def collect_keymap(self): - return super(_ReaderMixin, self).collect_keymap() + ( + return super(ReadlineAlikeReader, self).collect_keymap() + ( (r'\n', 'maybe-accept'),) def __init__(self, console): - super(_ReaderMixin, self).__init__(console) - from pyrepl import commands - class maybe_accept(commands.Command): - def do(self): - r = self.reader - # if there are already several lines and the cursor - # is not on the last one, always insert a new \n. - text = r.get_unicode() - if "\n" in r.buffer[r.pos:]: - r.insert("\n") - elif r.more_lines is not None and r.more_lines(text): - r.insert("\n") - else: - self.finish = 1 + super(ReadlineAlikeReader, self).__init__(console) self.commands['maybe_accept'] = maybe_accept self.commands['maybe-accept'] = maybe_accept +class maybe_accept(commands.Command): + def do(self): + r = self.reader + # if there are already several lines and the cursor + # is not on the last one, always insert a new \n. + text = r.get_unicode() + if "\n" in r.buffer[r.pos:]: + r.insert("\n") + elif r.more_lines is not None and r.more_lines(text): + r.insert("\n") + else: + self.finish = 1 + # ____________________________________________________________ class _ReadlineWrapper(object): @@ -124,13 +128,8 @@ def get_reader(self): if self.reader is None: - from pyrepl.historical_reader import HistoricalReader - from pyrepl.completing_reader import CompletingReader - from pyrepl.unix_console import UnixConsole - class MyReader(_ReaderMixin, HistoricalReader, CompletingReader): - pass console = UnixConsole(self.f_in, self.f_out, encoding=ENCODING) - self.reader = MyReader(console) + self.reader = ReadlineAlikeReader(console) return self.reader def raw_input(self, prompt=''): Modified: pyrepl/trunk/pyrepl/pyrepl/simple_interact.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/simple_interact.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/simple_interact.py Tue Apr 8 14:25:38 2008 @@ -6,12 +6,6 @@ import sys from pyrepl.readline import multiline_input -# please don't remove the following imports, useful -# to give an early ImportError if something is missing -import pyrepl.unix_console -import pyrepl.historical_reader -import pyrepl.completing_reader - def run_multiline_interactive_console(mainmodule=None): import code From arigo at codespeak.net Tue Apr 8 19:04:38 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 8 Apr 2008 19:04:38 +0200 (CEST) Subject: [pyrepl-checkins] r53590 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20080408170438.2B44316A968@codespeak.net> Author: arigo Date: Tue Apr 8 19:04:36 2008 New Revision: 53590 Modified: pyrepl/trunk/pyrepl/pyrepl/reader.py pyrepl/trunk/pyrepl/pyrepl/simple_interact.py Log: Disable alt-enter forcibly inserting a newline. In a Python prompt it would allow several statements, which are not handled correctly by compile('single'). For singe-line inputs e.g. as by raw_input(), inserting newline characters in the middle will probably just confuse Python programs that don't expect raw_input() to return multiline strings. Modified: pyrepl/trunk/pyrepl/pyrepl/reader.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/reader.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/reader.py Tue Apr 8 19:04:36 2008 @@ -135,7 +135,7 @@ (r'\M-7', 'digit-arg'), (r'\M-8', 'digit-arg'), (r'\M-9', 'digit-arg'), - (r'\M-\n', 'insert-nl'), + #(r'\M-\n', 'insert-nl'), ('\\\\', 'self-insert')] + \ [(c, 'self-insert') for c in map(chr, range(32, 127)) if c <> '\\'] + \ Modified: pyrepl/trunk/pyrepl/pyrepl/simple_interact.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/simple_interact.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/simple_interact.py Tue Apr 8 19:04:36 2008 @@ -31,10 +31,6 @@ statement = multiline_input(more_lines, ps1, ps2) except EOFError: break - # XXX with Alt-Enter we can actually enter more than one - # statement, and compile() ignores everything after the - # first statement in 'single' mode... We should either - # find some obscure workaround or tweak PyPy's compiler. more = console.push(statement) assert not more except KeyboardInterrupt: From arigo at codespeak.net Tue Apr 8 19:13:22 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 8 Apr 2008 19:13:22 +0200 (CEST) Subject: [pyrepl-checkins] r53592 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20080408171322.56F6116A8B9@codespeak.net> Author: arigo Date: Tue Apr 8 19:13:21 2008 New Revision: 53592 Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py Log: Try hard to prevent raw_input() from returning a multiline string. Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/readline.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/readline.py Tue Apr 8 19:13:21 2008 @@ -104,6 +104,22 @@ self.commands['maybe_accept'] = maybe_accept self.commands['maybe-accept'] = maybe_accept + def after_command(self, cmd): + super(ReadlineAlikeReader, self).after_command(cmd) + if self.more_lines is None: + # Force single-line input if we are in raw_input() mode. + # Although there is no direct way to add a \n in this mode, + # multiline buffers can still show up using various + # commands, e.g. navigating the history. + try: + index = self.buffer.index("\n") + except ValueError: + pass + else: + self.buffer = self.buffer[:index] + if self.pos > len(self.buffer): + self.pos = len(self.buffer) + class maybe_accept(commands.Command): def do(self): r = self.reader