Changeset 1843

Show
Ignore:
Timestamp:
10/25/06 15:40:17 (2 years ago)
Author:
jstenar
Message:

pyreadline-refactor: set_text_color, set_prompt_color added, bug fix history search, ansi color patch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pyreadline/branches/refactor/doc/ChangeLog

    r1836 r1843  
     12006-10-25 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
     2    * port set_text_color and set_prompt_color config file options from trunk 
     3    * Fix bug in history search and add tests for the case. 
     4    * port ansi color changes from trunk 
     5     
    162006-10-19 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
    27    * Fixed bug in history_search_* 
    38    * Fixed bug in beginning_of_line_extend_selection and end_of_line_extend_selection 
    49    * Fixd bugs to make vi_test work again, one test failure remains 
    5     * 
    6      
    710     
    8112006-10-19 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
  • pyreadline/branches/refactor/pyreadline/console/ansi.py

    r1775 r1843  
    8585            m = escape_parts.match(chunk) 
    8686            if m: 
    87                 for part in m.group(1).split(";"): 
     87                parts=m.group(1).split(";") 
     88                if len(parts)==1 and parts[0]=="0": 
     89                    attr = self.defaultstate.copy() 
     90                    continue 
     91                for part in parts: 
    8892                    if part == "0": # No text attribute 
    8993                        attr = self.defaultstate.copy() 
     94                        attr.bold=False 
    9095                    elif part == "7": # switch on reverse 
    9196                        attr.inverse=True 
  • pyreadline/branches/refactor/pyreadline/console/console.py

    r1775 r1843  
    189189        self.defaultstate.winattr=info.wAttributes 
    190190        self.ansiwriter=AnsiWriter(self.defaultstate) 
    191  
     191#        self.ansiwriter.defaultstate.bold=False 
     192         
    192193        background = self.attr & 0xf0 
    193194        for escape in self.escape_to_color: 
     
    344345 
    345346    def write_color(self, text, attr=None): 
     347        log_sock(text) 
     348        log_sock("%s"%attr) 
    346349        n,res= self.ansiwriter.write_color(text,attr) 
    347350        junk = c_int(0) 
    348351        for attr,chunk in res: 
     352            log_sock("%s:%s"%(attr,chunk)) 
    349353            log(str(attr)) 
    350354            log(str(chunk)) 
  • pyreadline/branches/refactor/pyreadline/lineeditor/history.py

    r1836 r1843  
    2727    def __init__(self): 
    2828        self.history=[] 
    29         self.history_length=100 
    30         self.history_cursor=0 
     29        self._history_length=100 
     30        self._history_cursor=0 
    3131        self.history_filename=os.path.expanduser('~/.history') 
    3232        self.lastcommand=None 
     
    3434 
    3535    def get_history_length(self): 
    36         return self.history_length 
     36        value=self._history_length 
     37        log_sock("get_history_length:%d"%value,"history") 
     38        return value 
    3739 
    3840    def set_history_length(self,value): 
    39         self.history_length=value 
     41        log_sock("set_history_length: old:%d new:%d"%(self._history_length,value),"history") 
     42        self._history_length=value 
     43 
     44    def get_history_cursor(self): 
     45        value=self._history_cursor 
     46        log_sock("get_history_cursor:%d"%value,"history") 
     47        return value 
     48 
     49    def set_history_cursor(self,value): 
     50        log_sock("set_history_cursor: old:%d new:%d"%(self._history_cursor,value),"history") 
     51        self._history_cursor=value 
     52         
     53    history_length=property(get_history_length,set_history_length) 
     54    history_cursor=property(get_history_cursor,set_history_cursor) 
    4055 
    4156    def read_history_file(self, filename=None):  
     
    185200                pass  
    186201            elif hc>=len(self.history) and not self.query: 
     202                self.history_cursor=len(self.history) 
    187203                return lineobj.ReadLineTextBuffer("",point=0) 
    188204            elif self.history[hcstart].get_line_text().startswith(self.query) and self.query: 
  • pyreadline/branches/refactor/pyreadline/modes/basemode.py

    r1836 r1843  
    364364    def self_insert(self, e): # (a, b, A, 1, !, ...) 
    365365        '''Insert yourself. ''' 
    366         if ord(e.char)!=0: #don't insert null character in buffer, can happen with dead keys. 
     366         
     367        if e.char and ord(e.char)!=0: #don't insert null character in buffer, can happen with dead keys. 
    367368            self.insert_text(e.char) 
    368369 
  • pyreadline/branches/refactor/pyreadline/rlmain.py

    r1832 r1843  
    367367            logger.log("STARTING LOG") 
    368368#            print release.branch 
     369        def set_prompt_color(color): 
     370            trtable={"black":0,"darkred":4,"darkgreen":2,"darkyellow":6,"darkblue":1,"darkmagenta":5,"darkcyan":3,"gray":7, 
     371                     "red":4+8,"green":2+8,"yellow":6+8,"blue":1+8,"magenta":5+8,"cyan":3+8,"white":7+8} 
     372            self.prompt_color=trtable.get(color.lower(),7)             
     373             
     374        def set_input_color(color): 
     375            trtable={"black":0,"darkred":4,"darkgreen":2,"darkyellow":6,"darkblue":1,"darkmagenta":5,"darkcyan":3,"gray":7, 
     376                     "red":4+8,"green":2+8,"yellow":6+8,"blue":1+8,"magenta":5+8,"cyan":3+8,"white":7+8} 
     377            self.command_color=trtable.get(color.lower(),7)             
    369378        loc={"branch":release.branch, 
     379             "version":release.version, 
    370380             "mode":mode, 
    371381             "modes":modes, 
     
    381391             "debug_output":debug_output, 
    382392             "history_filename":sethistoryfilename, 
    383              "history_length":sethistorylength} 
     393             "history_length":sethistorylength, 
     394             "set_prompt_color":set_prompt_color, 
     395             "set_input_color":set_input_color, 
     396             } 
    384397        if os.path.isfile(inputrcpath):  
    385398            try: 
  • pyreadline/branches/refactor/pyreadline/test/emacs_test.py

    r1836 r1843  
    4646 
    4747    def input (self, keytext): 
    48         if keytext[0] == '"' and keytext[-1] == '"': 
     48        if keytext[0:1] == '"' and keytext[-1:] == '"': 
    4949            lst_key = ['"%s"' % c for c in keytext[1:-1]] 
    5050        else: 
     
    255255        r.add_history ('bbb') 
    256256        r.add_history ('ako') 
    257         self.assertEqual (r.line, ''
     257        self.assert_line(r,'',0
    258258        r.input ('"a"') 
    259259        r.input ('Up') 
    260         self.assertEqual (r.line, 'ako') 
    261         self.assertEqual (r.line_cursor, 1) 
    262         r.input ('Up') 
    263         self.assertEqual (r.line, 'akca') 
    264         self.assertEqual (r.line_cursor, 1) 
    265         r.input ('Up') 
    266         self.assertEqual (r.line, 'aaca') 
    267         self.assertEqual (r.line_cursor, 1) 
    268         r.input ('Up') 
    269         self.assertEqual (r.line, 'aaba') 
    270         self.assertEqual (r.line_cursor, 1) 
    271         r.input ('Up') 
    272         self.assertEqual (r.line, 'aaaa') 
    273         self.assertEqual (r.line_cursor, 1) 
     260        self.assert_line(r,'ako',1) 
     261        r.input ('Up') 
     262        self.assert_line(r,'akca',1) 
     263        r.input ('Up') 
     264        self.assert_line(r,'aaca',1) 
     265        r.input ('Up') 
     266        self.assert_line(r,'aaba',1) 
     267        r.input ('Up') 
     268        self.assert_line(r,'aaaa',1) 
    274269        r.input ('Right') 
    275         self.assertEqual (r.line, 'aaaa') 
    276         self.assertEqual (r.line_cursor, 2) 
    277         r.input ('Down') 
    278         self.assertEqual (r.line, 'aaba') 
    279         self.assertEqual (r.line_cursor, 2) 
    280         r.input ('Down') 
    281         self.assertEqual (r.line, 'aaca') 
    282         self.assertEqual (r.line_cursor, 2) 
    283         r.input ('Down') 
    284         self.assertEqual (r.line, 'aaca') 
    285         self.assertEqual (r.line_cursor, 2) 
     270        self.assert_line(r,'aaaa',2) 
     271        r.input ('Down') 
     272        self.assert_line(r,'aaba',2) 
     273        r.input ('Down') 
     274        self.assert_line(r,'aaca',2) 
     275        r.input ('Down') 
     276        self.assert_line(r,'aaca',2) 
    286277        r.input ('Left') 
    287278        r.input ('Left') 
    288279        r.input ('Down') 
    289280        r.input ('Down') 
    290         self.assertEqual (r.line, 'bbb') 
    291         self.assertEqual (r.line_cursor, 3) 
     281        self.assert_line(r,'bbb',3) 
    292282        r.input ('Left') 
    293         self.assertEqual (r.line, 'bbb') 
    294         self.assertEqual (r.line_cursor, 2) 
    295         r.input ('Down') 
    296         self.assertEqual (r.line, 'bbb') 
    297         self.assertEqual (r.line_cursor, 2) 
    298         r.input ('Up') 
    299         self.assertEqual (r.line, 'bbb') 
    300         self.assertEqual (r.line_cursor, 2) 
    301  
     283        self.assert_line(r,'bbb',2) 
     284        r.input ('Down') 
     285        self.assert_line(r,'bbb',2) 
     286        r.input ('Up') 
     287        self.assert_line(r,'bbb',2) 
     288 
     289 
     290    def test_history_3 (self): 
     291        r = EmacsModeTest () 
     292        r.add_history ('aaaa') 
     293        r.add_history ('aaba') 
     294        r.add_history ('aaca') 
     295        r.add_history ('akca') 
     296        r.add_history ('bbb') 
     297        r.add_history ('ako') 
     298        self.assert_line(r,'',0) 
     299        r.input ('') 
     300        r.input ('Up') 
     301        self.assert_line(r,'ako',3) 
     302        r.input ('Down') 
     303        self.assert_line(r,'',0) 
     304        r.input ('Up') 
     305        self.assert_line(r,'ako',3) 
     306 
     307 
     308 
     309    def assert_line(self,r,line,cursor): 
     310        self.assertEqual (r.line, line) 
     311        self.assertEqual (r.line_cursor, cursor) 
     312         
    302313#---------------------------------------------------------------------- 
    303314# utility functions