Changeset 2864

Show
Ignore:
Timestamp:
11/09/07 18:13:26 (1 year ago)
Author:
jstenar
Message:

pyreadline: more fixes to unicode

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pyreadline/trunk/doc/ChangeLog

    r2863 r2864  
     12007-11-09 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
     2    * More fixes to unicode handling. 
     3 
    142007-11-09 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
    25    * Fixes to make clipboard play nice with unicode. Quick that treats the clipboard as 
  • pyreadline/trunk/pyreadline/console/console.py

    r2861 r2864  
    433433    def rectangle(self, rect, attr=None, fill=' '): 
    434434        '''Fill Rectangle.''' 
    435         log_sock("rect:%s"%[rect]) 
    436435        x0, y0, x1, y1 = rect 
    437436        n = c_int(0) 
     
    496495            if status and count.value == 1: 
    497496                e = event(self, Cevent) 
    498                 log_sock(unicode(e.keyinfo),"keypress") 
     497                log_sock(ensure_unicode(e.keyinfo),"keypress") 
    499498                return e 
    500499 
     
    534533        count = c_int(0) 
    535534        status = self.PeekConsoleInputW(self.hin, byref(Cevent), 1, byref(count)) 
    536         log_sock("%s %s %s"%(status,count,Cevent)) 
    537535        if status and count == 1: 
    538536            return event(self, Cevent) 
     
    754752    print 'some printed output' 
    755753    for i in range(10): 
    756         c.getkeypress() 
     754        q=c.getkeypress() 
     755        print q 
    757756    del c 
  • pyreadline/trunk/pyreadline/console/event.py

    r1419 r2864  
    66        '''Display an event for debugging.''' 
    77        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, 
    1013                     self.state, self.keyinfo) 
    1114        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) 
    1316        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) 
    1518        elif self.type in ['FocusIn', 'FocusOut']: 
    1619            s = self.type 
    1720        elif self.type == 'Menu': 
    18             s = '%s state=%x' % (self.type, self.state) 
     21            s = u'%s state=%x' % (self.type, self.state) 
    1922        else: 
    20             s = 'unknown event type' 
     23            s = u'unknown event type' 
    2124        return s 
    2225 
  • pyreadline/trunk/pyreadline/keysyms/common.py

    r2325 r2864  
    1414    from sets import Set as set 
    1515     
    16  
     16from pyreadline.unicode_helper import ensure_unicode 
    1717 
    1818validkey =set(['cancel',     'backspace',    'tab',          'clear', 
     
    6262         
    6363    def __repr__(self): 
    64         return "(%s,%s,%s,%s)"%self.tuple(
     64        return u"(%s,%s,%s,%s)"%tuple(map(ensure_unicode,self.tuple())
    6565 
    6666    def tuple(self): 
  • pyreadline/trunk/pyreadline/lineeditor/history.py

    r2852 r2864  
    126126        if _ignore_leading_spaces: 
    127127            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) 
    129128        else: 
    130129            res=[(idx,line)  for idx,line in enumerate(self.history[startpos:0:-1]) if line.startswith(searchfor)] 
     
    157156 
    158157            event = c.getkeypress() 
    159             log_sock(str(event),"history") 
    160158             
    161159            if event.keyinfo.keyname == 'backspace': 
     
    170168            else: 
    171169                pyreadline.rl._bell() 
    172         log_sock(query,"history") 
    173170        res="" 
    174171        if query: 
     
    178175            else: 
    179176                res=self.forward_search_history(query) 
    180             log_sock(res,"history") 
    181177        return lineobj.ReadLineTextBuffer(res,point=0) 
    182178         
     
    199195                self.query = ''.join(partial[0:partial.point].get_line_text()) 
    200196            hcstart=max(self.history_cursor,0)  
    201             log_sock("hcstart %s"%hcstart,"history") 
    202197            hc = self.history_cursor + direction 
    203198            while (direction < 0 and hc >= 0) or (direction > 0 and hc < len(self.history)): 
     
    224219                return lineobj.ReadLineTextBuffer(self.query,point=min(len(self.query),partial.point)) 
    225220        except IndexError: 
    226             log_sock("hcstart:%s %s"%(hcstart,len(self.history)),"history") 
    227221            raise 
    228222 
  • pyreadline/trunk/pyreadline/lineeditor/lineobj.py

    r2863 r2864  
    1212from pyreadline.logger import  log,log_sock 
    1313from pyreadline.unicode_helper import ensure_unicode 
     14 
     15kill_ring_to_clipboard=False #set to true to copy every addition to kill ring to clipboard 
     16 
     17 
    1418class NotAWordError(IndexError): 
    1519    pass 
     
    398402        self.enable_selection=True 
    399403        self.kill_ring=[] 
     404 
    400405    def __repr__(self): 
    401406        return 'ReadLineTextBuffer("%s",point=%s,mark=%s,selection_mark=%s)'%(self.line_buffer,self.point,self.mark,self.selection_mark) 
     
    742747    def add_to_kill_ring(self,txt): 
    743748        self.kill_ring=[txt] 
    744          
     749        if kill_ring_to_clipboard: 
     750            clipboard.SetClipboardText(txt.get_line_text()) 
     751 
    745752 
    746753    def paste_from_kill_ring(self): 
  • pyreadline/trunk/pyreadline/logger.py

    r2853 r2864  
    88 
    99import socket 
     10from pyreadline.unicode_helper import ensure_text 
    1011_logfile=False 
    1112 
     
    3738    else: 
    3839        if event_type is None: 
    39             logsocket.sendto(str(s),(host,port)) 
     40            logsocket.sendto(ensure_text(s),(host,port)) 
    4041        elif event_type in show_event: 
    41             logsocket.sendto(str(s),(host,port)) 
     42            logsocket.sendto(ensure_text(s),(host,port)) 
    4243        else: 
    4344            pass 
  • pyreadline/trunk/pyreadline/modes/emacs.py

    r2853 r2864  
    1515import basemode 
    1616import string 
     17from pyreadline.unicode_helper import ensure_unicode 
     18 
    1719def format(keyinfo): 
    1820    if len(keyinfo[-1])!=1: 
     
    4648            self._update_line() 
    4749            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)) 
    4951            try: 
    5052                event = c.getkeypress() 
     53                log_sock(u">>%s"%event) 
    5154            except KeyboardInterrupt: 
    5255                from pyreadline.keysyms.common import KeyPress 
     
    8285             
    8386            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") 
    8588            r = None 
    8689            if dispatch_func: 
     
    158161        c = self.console 
    159162        line = self.l_buffer.get_line_text() 
    160         log_sock(str(line)) 
    161163        query = '' 
    162164        if (self.previous_func != self.history_search_forward and 
     
    406408                    default=self.self_insert 
    407409                dispatch_func = self.key_dispatch.get(keyinfo,default) 
    408                 log_sock("%s|%s"%(dispatch_func,str(keyinfo))) 
    409410                dispatch_func(event) 
    410411                break 
    411         log_sock("END arg=%s"%(self.argument)) 
    412412        self.prompt=oldprompt 
    413413        x, y = self.prompt_end_pos 
  • pyreadline/trunk/pyreadline/rlmain.py

    r2514 r2864  
    353353                del modes[mode].exit_dispatch[keyinfo] 
    354354 
     355 
     356 
     357        def setkill_ring_to_clipboard(killring): 
     358            import pyreadline.lineeditor.lineobj  
     359            pyreadline.lineeditor.lineobj.kill_ring_to_clipboard=killring 
     360             
    355361        def sethistoryfilename(filename): 
    356362            self._history.history_filename=os.path.expanduser(filename) 
     
    405411             "allow_ctrl_c":allow_ctrl_c, 
    406412             "ctrl_c_tap_time_interval":ctrl_c_tap_time_interval, 
     413             "kill_ring_to_clipboard":setkill_ring_to_clipboard, 
    407414             } 
    408415        if os.path.isfile(inputrcpath):  
  • pyreadline/trunk/pyreadline/unicode_helper.py

    r2863 r2864  
    2323def ensure_text(text): 
    2424    """Convert unicode to str using pyreadline_codepage""" 
    25     if isinstance(text, str): 
     25    if isinstance(text, unicode): 
    2626        return text.encode(pyreadline_codepage, "replace") 
    2727    return text