Changeset 2864
- Timestamp:
- 11/09/07 18:13:26 (1 year ago)
- Files:
-
- pyreadline/trunk/doc/ChangeLog (modified) (1 diff)
- pyreadline/trunk/pyreadline/console/console.py (modified) (4 diffs)
- pyreadline/trunk/pyreadline/console/event.py (modified) (1 diff)
- pyreadline/trunk/pyreadline/keysyms/common.py (modified) (2 diffs)
- pyreadline/trunk/pyreadline/lineeditor/history.py (modified) (6 diffs)
- pyreadline/trunk/pyreadline/lineeditor/lineobj.py (modified) (3 diffs)
- pyreadline/trunk/pyreadline/logger.py (modified) (2 diffs)
- pyreadline/trunk/pyreadline/modes/emacs.py (modified) (5 diffs)
- pyreadline/trunk/pyreadline/rlmain.py (modified) (2 diffs)
- pyreadline/trunk/pyreadline/unicode_helper.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pyreadline/trunk/doc/ChangeLog
r2863 r2864 1 2007-11-09 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu> 2 * More fixes to unicode handling. 3 1 4 2007-11-09 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu> 2 5 * Fixes to make clipboard play nice with unicode. Quick that treats the clipboard as pyreadline/trunk/pyreadline/console/console.py
r2861 r2864 433 433 def rectangle(self, rect, attr=None, fill=' '): 434 434 '''Fill Rectangle.''' 435 log_sock("rect:%s"%[rect])436 435 x0, y0, x1, y1 = rect 437 436 n = c_int(0) … … 496 495 if status and count.value == 1: 497 496 e = event(self, Cevent) 498 log_sock( unicode(e.keyinfo),"keypress")497 log_sock(ensure_unicode(e.keyinfo),"keypress") 499 498 return e 500 499 … … 534 533 count = c_int(0) 535 534 status = self.PeekConsoleInputW(self.hin, byref(Cevent), 1, byref(count)) 536 log_sock("%s %s %s"%(status,count,Cevent))537 535 if status and count == 1: 538 536 return event(self, Cevent) … … 754 752 print 'some printed output' 755 753 for i in range(10): 756 c.getkeypress() 754 q=c.getkeypress() 755 print q 757 756 del c pyreadline/trunk/pyreadline/console/event.py
r1419 r2864 6 6 '''Display an event for debugging.''' 7 7 if self.type in ['KeyPress', 'KeyRelease']: 8 s = "%s char='%s'%d keysym='%s' keycode=%d:%x state=%x keyinfo=%s" % \ 9 (self.type, self.char, ord(self.char), self.keysym, self.keycode, self.keycode, 8 chr=self.char 9 if ord(chr)<ord("A"): 10 chr="?" 11 s = u"%s char='%s'%d keysym='%s' keycode=%d:%x state=%x keyinfo=%s" % \ 12 (self.type, chr, ord(self.char), self.keysym, self.keycode, self.keycode, 10 13 self.state, self.keyinfo) 11 14 elif self.type in ['Motion', 'Button']: 12 s = '%s x=%d y=%d state=%x' % (self.type, self.x, self.y, self.state)15 s = u'%s x=%d y=%d state=%x' % (self.type, self.x, self.y, self.state) 13 16 elif self.type == 'Configure': 14 s = '%s w=%d h=%d' % (self.type, self.width, self.height)17 s = u'%s w=%d h=%d' % (self.type, self.width, self.height) 15 18 elif self.type in ['FocusIn', 'FocusOut']: 16 19 s = self.type 17 20 elif self.type == 'Menu': 18 s = '%s state=%x' % (self.type, self.state)21 s = u'%s state=%x' % (self.type, self.state) 19 22 else: 20 s = 'unknown event type'23 s = u'unknown event type' 21 24 return s 22 25 pyreadline/trunk/pyreadline/keysyms/common.py
r2325 r2864 14 14 from sets import Set as set 15 15 16 16 from pyreadline.unicode_helper import ensure_unicode 17 17 18 18 validkey =set(['cancel', 'backspace', 'tab', 'clear', … … 62 62 63 63 def __repr__(self): 64 return "(%s,%s,%s,%s)"%self.tuple()64 return u"(%s,%s,%s,%s)"%tuple(map(ensure_unicode,self.tuple())) 65 65 66 66 def tuple(self): pyreadline/trunk/pyreadline/lineeditor/history.py
r2852 r2864 126 126 if _ignore_leading_spaces: 127 127 res=[(idx,line.lstrip()) for idx,line in enumerate(self.history[startpos:0:-1]) if line.lstrip().startswith(searchfor.lstrip())] 128 logger.log_sock(res)129 128 else: 130 129 res=[(idx,line) for idx,line in enumerate(self.history[startpos:0:-1]) if line.startswith(searchfor)] … … 157 156 158 157 event = c.getkeypress() 159 log_sock(str(event),"history")160 158 161 159 if event.keyinfo.keyname == 'backspace': … … 170 168 else: 171 169 pyreadline.rl._bell() 172 log_sock(query,"history")173 170 res="" 174 171 if query: … … 178 175 else: 179 176 res=self.forward_search_history(query) 180 log_sock(res,"history")181 177 return lineobj.ReadLineTextBuffer(res,point=0) 182 178 … … 199 195 self.query = ''.join(partial[0:partial.point].get_line_text()) 200 196 hcstart=max(self.history_cursor,0) 201 log_sock("hcstart %s"%hcstart,"history")202 197 hc = self.history_cursor + direction 203 198 while (direction < 0 and hc >= 0) or (direction > 0 and hc < len(self.history)): … … 224 219 return lineobj.ReadLineTextBuffer(self.query,point=min(len(self.query),partial.point)) 225 220 except IndexError: 226 log_sock("hcstart:%s %s"%(hcstart,len(self.history)),"history")227 221 raise 228 222 pyreadline/trunk/pyreadline/lineeditor/lineobj.py
r2863 r2864 12 12 from pyreadline.logger import log,log_sock 13 13 from pyreadline.unicode_helper import ensure_unicode 14 15 kill_ring_to_clipboard=False #set to true to copy every addition to kill ring to clipboard 16 17 14 18 class NotAWordError(IndexError): 15 19 pass … … 398 402 self.enable_selection=True 399 403 self.kill_ring=[] 404 400 405 def __repr__(self): 401 406 return 'ReadLineTextBuffer("%s",point=%s,mark=%s,selection_mark=%s)'%(self.line_buffer,self.point,self.mark,self.selection_mark) … … 742 747 def add_to_kill_ring(self,txt): 743 748 self.kill_ring=[txt] 744 749 if kill_ring_to_clipboard: 750 clipboard.SetClipboardText(txt.get_line_text()) 751 745 752 746 753 def paste_from_kill_ring(self): pyreadline/trunk/pyreadline/logger.py
r2853 r2864 8 8 9 9 import socket 10 from pyreadline.unicode_helper import ensure_text 10 11 _logfile=False 11 12 … … 37 38 else: 38 39 if event_type is None: 39 logsocket.sendto( str(s),(host,port))40 logsocket.sendto(ensure_text(s),(host,port)) 40 41 elif event_type in show_event: 41 logsocket.sendto( str(s),(host,port))42 logsocket.sendto(ensure_text(s),(host,port)) 42 43 else: 43 44 pass pyreadline/trunk/pyreadline/modes/emacs.py
r2853 r2864 15 15 import basemode 16 16 import string 17 from pyreadline.unicode_helper import ensure_unicode 18 17 19 def format(keyinfo): 18 20 if len(keyinfo[-1])!=1: … … 46 48 self._update_line() 47 49 lbuf=self.l_buffer 48 log_sock("point:% s mark:%s selection_mark:%s"%(lbuf.point,lbuf.mark,lbuf.selection_mark))50 log_sock("point:%d mark:%d selection_mark:%d"%(lbuf.point,lbuf.mark,lbuf.selection_mark)) 49 51 try: 50 52 event = c.getkeypress() 53 log_sock(u">>%s"%event) 51 54 except KeyboardInterrupt: 52 55 from pyreadline.keysyms.common import KeyPress … … 82 85 83 86 log("readline from keyboard:%s,%s"%(keyinfo,dispatch_func)) 84 log_sock(( "%s|%s"%(format(keyinfo),dispatch_func.__name__)).encode(sys.stdout.encoding),"bound_function")87 log_sock((u"%s|%s"%(ensure_unicode(format(keyinfo)),dispatch_func.__name__)),"bound_function") 85 88 r = None 86 89 if dispatch_func: … … 158 161 c = self.console 159 162 line = self.l_buffer.get_line_text() 160 log_sock(str(line))161 163 query = '' 162 164 if (self.previous_func != self.history_search_forward and … … 406 408 default=self.self_insert 407 409 dispatch_func = self.key_dispatch.get(keyinfo,default) 408 log_sock("%s|%s"%(dispatch_func,str(keyinfo)))409 410 dispatch_func(event) 410 411 break 411 log_sock("END arg=%s"%(self.argument))412 412 self.prompt=oldprompt 413 413 x, y = self.prompt_end_pos pyreadline/trunk/pyreadline/rlmain.py
r2514 r2864 353 353 del modes[mode].exit_dispatch[keyinfo] 354 354 355 356 357 def setkill_ring_to_clipboard(killring): 358 import pyreadline.lineeditor.lineobj 359 pyreadline.lineeditor.lineobj.kill_ring_to_clipboard=killring 360 355 361 def sethistoryfilename(filename): 356 362 self._history.history_filename=os.path.expanduser(filename) … … 405 411 "allow_ctrl_c":allow_ctrl_c, 406 412 "ctrl_c_tap_time_interval":ctrl_c_tap_time_interval, 413 "kill_ring_to_clipboard":setkill_ring_to_clipboard, 407 414 } 408 415 if os.path.isfile(inputrcpath): pyreadline/trunk/pyreadline/unicode_helper.py
r2863 r2864 23 23 def ensure_text(text): 24 24 """Convert unicode to str using pyreadline_codepage""" 25 if isinstance(text, str):25 if isinstance(text, unicode): 26 26 return text.encode(pyreadline_codepage, "replace") 27 27 return text
