mirror of
https://github.com/wassname/pyreadline.git
synced 2026-07-13 01:00:44 +08:00
pyreadline-refactor: More improvements of ironpython handling, more testcases
This commit is contained in:
@@ -1,3 +1,24 @@
|
||||
2006-11-06 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
* Fixed bug in tab completion when point is not at end of line
|
||||
* Changed clr.AddReference to clr.AddReferenceToFileAndPath (ironpython_console)
|
||||
* Fix points position after tab completion
|
||||
* Fix for difference in handling of multiline input between cpython and ironpython (emacs.py)
|
||||
* added test_complete case to emacs_test.py
|
||||
|
||||
2006-11-03 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
* Improvements in ironpython handling.
|
||||
* Detection of ironpython explicit on sys.version instead of relying on presense of ctypes
|
||||
* Lots of fixes to take care of peculiaritis of System.Console in .NET it does not have
|
||||
the full windows console functionality. Fill a rectangle is missing, writing without
|
||||
affecting cursor is missing, altgr keys show up as alt+ctrl so had to blank alt+ctrl in
|
||||
keyboard event checking, endoffile signal to from readline is not using EOFError in ironpython
|
||||
rather returning None
|
||||
* Set selectioncolor by looking at foregroundcolor at startup
|
||||
* open in ironpython does not ignore unknown letters in mode silently, hade "rt" in history open
|
||||
* Have to print prompt in ironpython since ironpythons readline looks at sys.ps1 and print it instead
|
||||
of passing it into readline explicitly.
|
||||
* Fixed another bug in historysearch
|
||||
|
||||
2006-10-25 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
* port set_text_color and set_prompt_color config file options from trunk
|
||||
* Fix bug in history search and add tests for the case.
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# -*- coding: ISO-8859-1 -*-
|
||||
import re,sys,os,pprint
|
||||
pprint=pprint.pprint
|
||||
import re,sys,os
|
||||
|
||||
terminal_escape = re.compile('(\001?\033\\[[0-9;]*m\002?)')
|
||||
escape_parts = re.compile('\001?\033\\[([0-9;]*)m\002?')
|
||||
@@ -153,7 +152,9 @@ def write_color_old( text, attr=None):
|
||||
#trtable={0:"black",1:"red",2:"green",3:"yellow",4:"blue",5:"magenta",6:"cyan",7:"white"}
|
||||
|
||||
if __name__=="__main__":
|
||||
import startup
|
||||
import pprint
|
||||
pprint=pprint.pprint
|
||||
|
||||
s="\033[0;31mred\033[0;32mgreen\033[0;33myellow\033[0;34mblue\033[0;35mmagenta\033[0;36mcyan\033[0;37mwhite\033[0m"
|
||||
pprint (write_color(s))
|
||||
pprint (write_color_old(s))
|
||||
@@ -177,4 +178,4 @@ if __name__=="__main__":
|
||||
c.write_color("\033[0;32mIn [\033[1;32m1\033[0;32m]:")
|
||||
print
|
||||
pprint (write_color("\033[0;32mIn [\033[1;32m1\033[0;32m]:"))
|
||||
|
||||
|
||||
|
||||
@@ -22,16 +22,13 @@
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
# primitive debug printing that won't interfere with the screen
|
||||
|
||||
import clr
|
||||
clr.AddReference("ipy.exe")
|
||||
import clr,sys
|
||||
clr.AddReferenceToFileAndPath(sys.executable)
|
||||
import IronPythonConsole
|
||||
|
||||
import sys
|
||||
import traceback
|
||||
import re
|
||||
import os
|
||||
|
||||
@@ -401,14 +398,6 @@ def install_readline(hook):
|
||||
IronPythonConsole.PythonCommandLine.MyConsole = IronPythonWrapper()
|
||||
|
||||
|
||||
def getconsole(buffer=1):
|
||||
"""Get a console handle.
|
||||
|
||||
If buffer is non-zero, a new console buffer is allocated and
|
||||
installed. Otherwise, this returns a handle to the current
|
||||
console buffer"""
|
||||
c = Console(buffer)
|
||||
return c
|
||||
|
||||
if __name__ == '__main__':
|
||||
import time, sys
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
import glob
|
||||
import sys
|
||||
|
||||
success=False
|
||||
try:
|
||||
from keysyms import *
|
||||
success=True
|
||||
except ImportError,x:
|
||||
in_ironpython=sys.version.startswith("IronPython")
|
||||
|
||||
if in_ironpython:
|
||||
try:
|
||||
from ironpython_keysyms import *
|
||||
success=True
|
||||
except ImportError,x:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
from keysyms import *
|
||||
success=True
|
||||
except ImportError,x:
|
||||
pass
|
||||
|
||||
if not success:
|
||||
raise ImportError("Could not import keysym for local pythonversion",x)
|
||||
@@ -8,7 +8,7 @@
|
||||
#*****************************************************************************
|
||||
import System
|
||||
from common import validkey,KeyPress,make_KeyPress_from_keydescr
|
||||
from pyreadline.logger import log_sock
|
||||
#from pyreadline.logger import log_sock
|
||||
c32=System.ConsoleKey
|
||||
Shift=System.ConsoleModifiers.Shift
|
||||
Control=System.ConsoleModifiers.Control
|
||||
@@ -196,7 +196,7 @@ def make_KeyPress(char,state,keycode):
|
||||
control=bool(int(state)&int(Control))
|
||||
meta=bool(int(state)&int(Alt))
|
||||
keyname=code2sym_map.get(keycode,"").lower()
|
||||
log_sock("make key %s %s %s %s"%(shift,control,meta,keycode),"keysyms")
|
||||
# log_sock("make key %s %s %s %s"%(shift,control,meta,keycode),"keysyms")
|
||||
if control and meta: #equivalent to altgr so clear flags
|
||||
control=False
|
||||
meta=False
|
||||
|
||||
@@ -142,7 +142,7 @@ class LineHistory(object):
|
||||
pyreadline.rl._clear_after()
|
||||
|
||||
event = c.getkeypress()
|
||||
log_sock(str(event))
|
||||
log_sock(str(event),"history")
|
||||
|
||||
if event.keyinfo.keyname == 'backspace':
|
||||
if len(query) > 0:
|
||||
@@ -155,7 +155,7 @@ class LineHistory(object):
|
||||
break
|
||||
else:
|
||||
pyreadline.rl._bell()
|
||||
log_sock(query)
|
||||
log_sock(query,"history")
|
||||
res=""
|
||||
if query:
|
||||
if direction==-1:
|
||||
@@ -163,7 +163,7 @@ class LineHistory(object):
|
||||
|
||||
else:
|
||||
res=self.forward_search_history(query)
|
||||
log_sock(res)
|
||||
log_sock(res,"history")
|
||||
return lineobj.ReadLineTextBuffer(res,point=0)
|
||||
|
||||
def non_incremental_reverse_search_history(self,current): # (M-p)
|
||||
@@ -184,7 +184,7 @@ class LineHistory(object):
|
||||
self.lastcommand != self.history_search_backward):
|
||||
self.query = ''.join(partial[0:partial.point].get_line_text())
|
||||
hcstart=max(self.history_cursor,0)
|
||||
log_sock("hcstart %s"%hcstart)
|
||||
log_sock("hcstart %s"%hcstart,"history")
|
||||
hc = self.history_cursor + direction
|
||||
while (direction < 0 and hc >= 0) or (direction > 0 and hc < len(self.history)):
|
||||
h = self.history[hc]
|
||||
@@ -209,7 +209,7 @@ class LineHistory(object):
|
||||
return lineobj.ReadLineTextBuffer(partial,point=partial.point)
|
||||
return lineobj.ReadLineTextBuffer(self.query,point=min(len(self.query),partial.point))
|
||||
except IndexError:
|
||||
log_sock("hcstart:%s %s"%(hcstart,len(self.history)))
|
||||
log_sock("hcstart:%s %s"%(hcstart,len(self.history)),"history")
|
||||
raise
|
||||
|
||||
def history_search_forward(self,partial): # ()
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#*****************************************************************************
|
||||
import os,re,math,glob,sys
|
||||
import pyreadline.logger as logger
|
||||
from pyreadline.logger import log
|
||||
from pyreadline.logger import log,log_sock
|
||||
from pyreadline.keysyms.common import make_KeyPress_from_keydescr
|
||||
import pyreadline.lineeditor.lineobj as lineobj
|
||||
import pyreadline.lineeditor.history as history
|
||||
@@ -186,8 +186,9 @@ class BaseMode(object):
|
||||
if completions:
|
||||
cprefix = commonprefix(completions)
|
||||
rep = [ c for c in cprefix ]
|
||||
point=self.l_buffer.point
|
||||
self.l_buffer[self.begidx:self.endidx] = rep
|
||||
self.l_buffer.point += len(rep) - (self.endidx - self.begidx)
|
||||
self.l_buffer.point = point + len(rep) - (self.endidx - self.begidx)
|
||||
if len(completions) > 1:
|
||||
if self.show_all_if_ambiguous == 'on':
|
||||
self._display_completions(completions)
|
||||
|
||||
@@ -62,7 +62,7 @@ class EmacsMode(basemode.BaseMode):
|
||||
dispatch_func = self.key_dispatch.get(keyinfo,default)
|
||||
|
||||
log("readline from keyboard:%s,%s"%(keyinfo,dispatch_func))
|
||||
log_sock("%s|%s"%(format(keyinfo),dispatch_func.__name__))
|
||||
log_sock("%s|%s"%(format(keyinfo),dispatch_func.__name__),"bound_function")
|
||||
r = None
|
||||
if dispatch_func:
|
||||
r = dispatch_func(event)
|
||||
@@ -119,7 +119,10 @@ class EmacsMode(basemode.BaseMode):
|
||||
self.add_history(self.l_buffer.copy())
|
||||
|
||||
log('returning(%s)' % self.l_buffer.get_line_text())
|
||||
return self.l_buffer.get_line_text() + '\n'
|
||||
if in_ironpython:
|
||||
return self.l_buffer.get_line_text()
|
||||
else:
|
||||
return self.l_buffer.get_line_text() + '\n'
|
||||
|
||||
######### History commands
|
||||
def previous_history(self, e): # (C-p)
|
||||
|
||||
+3
-11
@@ -7,16 +7,8 @@
|
||||
# the file COPYING, distributed as part of this software.
|
||||
#*****************************************************************************
|
||||
''' an attempt to implement readline for Python in Python using ctypes'''
|
||||
|
||||
import string
|
||||
import math
|
||||
import sys
|
||||
import sys,os,re
|
||||
from glob import glob
|
||||
import os,pdb
|
||||
import re
|
||||
import traceback
|
||||
import operator
|
||||
import exceptions
|
||||
|
||||
import clipboard,logger,console
|
||||
from logger import log,log_sock
|
||||
@@ -35,6 +27,7 @@ if in_ironpython:#ironpython does not provide a prompt string to readline
|
||||
default_prompt=">>> "
|
||||
else:
|
||||
default_prompt=""
|
||||
import pdb
|
||||
|
||||
|
||||
def quote_char(c):
|
||||
@@ -143,7 +136,6 @@ class Readline(object):
|
||||
self.mode._bind_key(key, func)
|
||||
except:
|
||||
log('error')
|
||||
traceback.print_exc()
|
||||
raise
|
||||
|
||||
def get_line_buffer(self):
|
||||
@@ -268,7 +260,7 @@ class Readline(object):
|
||||
if self.bell_style == 'none':
|
||||
pass
|
||||
elif self.bell_style == 'visible':
|
||||
raise exceptions.NotImplementedError("Bellstyle visible is not implemented yet.")
|
||||
raise NotImplementedError("Bellstyle visible is not implemented yet.")
|
||||
elif self.bell_style == 'audible':
|
||||
self.console.bell()
|
||||
else:
|
||||
|
||||
@@ -15,6 +15,11 @@ from pyreadline import keysyms
|
||||
from pyreadline.lineeditor import lineobj
|
||||
|
||||
from common import *
|
||||
from pyreadline.logger import log_sock
|
||||
import pyreadline.logger as logger
|
||||
logger.sock_silent=True
|
||||
logger.show_event=["debug"]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -28,6 +33,8 @@ class EmacsModeTest (EmacsMode):
|
||||
self.completer = self.mock_completer
|
||||
self.completer_delims = ' '
|
||||
self.tabstop = 4
|
||||
self.mark_directories=False
|
||||
self.show_all_if_ambiguous=False
|
||||
|
||||
def get_mock_console (self):
|
||||
return self.mock_console
|
||||
@@ -53,9 +60,8 @@ class EmacsModeTest (EmacsMode):
|
||||
keyinfo, event = keytext_to_keyinfo_and_event (key)
|
||||
dispatch_func = self.key_dispatch.get(keyinfo.tuple(),self.self_insert)
|
||||
self.tested_commands[dispatch_func.__name__]=dispatch_func
|
||||
# print key,dispatch_func.__name__
|
||||
log_sock("keydisp: %s %s"%( key,dispatch_func.__name__),"debug")
|
||||
dispatch_func (event)
|
||||
log_sock("emacs readline from keyboard:%s->%s"%(keyinfo.tuple(),dispatch_func))
|
||||
self.previous_func=dispatch_func
|
||||
|
||||
def accept_line (self, e):
|
||||
@@ -317,8 +323,33 @@ class TestsHistory (unittest.TestCase):
|
||||
r.input ('Up')
|
||||
self.assert_line(r,'k',1)
|
||||
|
||||
def test_complete (self):
|
||||
import rlcompleter
|
||||
logger.sock_silent=False
|
||||
|
||||
log_sock("-"*50,"debug")
|
||||
r=EmacsModeTest()
|
||||
r.completer=rlcompleter.Completer().complete
|
||||
r._bind_key("tab",r.complete)
|
||||
r.input('"exi(ksdjksjd)"')
|
||||
r.input('Control-a')
|
||||
r.input('Right')
|
||||
r.input('Right')
|
||||
r.input('Right')
|
||||
r.input('Tab')
|
||||
self.assert_line(r,"exit(ksdjksjd)",4)
|
||||
|
||||
r.input('Escape')
|
||||
r.input('"exi"')
|
||||
r.input('Control-a')
|
||||
r.input('Right')
|
||||
r.input('Right')
|
||||
r.input('Right')
|
||||
r.input('Tab')
|
||||
self.assert_line(r,"exit",4)
|
||||
|
||||
|
||||
|
||||
def assert_line(self,r,line,cursor):
|
||||
self.assertEqual (r.line, line)
|
||||
self.assertEqual (r.line_cursor, cursor)
|
||||
@@ -332,9 +363,9 @@ if __name__ == '__main__':
|
||||
Tester()
|
||||
tested=EmacsModeTest.tested_commands.keys()
|
||||
tested.sort()
|
||||
print " Tested functions ".center(60,"-")
|
||||
print "\n".join(tested)
|
||||
print
|
||||
# print " Tested functions ".center(60,"-")
|
||||
# print "\n".join(tested)
|
||||
# print
|
||||
|
||||
all_funcs=dict([(x.__name__,x) for x in EmacsModeTest().key_dispatch.values()])
|
||||
all_funcs=all_funcs.keys()
|
||||
|
||||
Reference in New Issue
Block a user