Changeset 2921

Show
Ignore:
Timestamp:
01/04/08 10:57:27 (1 year ago)
Author:
jstenar
Message:

pyreadline: chunking calls to WriteConsoleW to ensure not exceeding 64k limit

Files:

Legend:

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

    r2876 r2921  
     12008-01-04 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
     2    * Chunking calls to WriteConsoleW to ensure not exceeding 64k limit 
     3 
    142007-11-28 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
    25    * Warning messages for failed calls to parse_and_bind now disabled by default  
  • pyreadline/trunk/pyreadline/console/console.py

    r2868 r2921  
    154154                  0x5b:1, # windows key 
    155155                 } 
     156 
     157def split_block(text,size=1000): 
     158    return [text[start:start+size] for start in range(0, len(text), size)] 
     159 
     160 
    156161 
    157162class Console(object): 
     
    330335 
    331336    def write_color(self, text, attr=None): 
    332         '''write text at current cursor position and interpret color escapes. 
    333  
    334         return the number of characters written. 
    335         ''' 
    336         log('write_color("%s", %s)' % (text, attr)) 
    337         chunks = self.terminal_escape.split(text) 
    338         log('chunks=%s' % repr(chunks)) 
    339         junk = c_int(0) 
    340         n = 0 # count the characters we actually write, omitting the escapes 
    341         for chunk in chunks: 
    342             m = self.escape_parts.match(chunk) 
    343             if m: 
    344                 attr = self.escape_to_color[m.group(1)] 
    345                 continue 
    346             n += len(chunk) 
    347             log('attr=%s' % attr) 
    348             if attr is None: 
    349                 attr = self.attr 
    350             self.SetConsoleTextAttribute(self.hout, attr) 
    351             #self.WriteConsoleW(self.hout, ensure_str(chunk), len(chunk), byref(junk), None) 
    352         return n 
    353  
    354     def write_color(self, text, attr=None): 
    355337        text = ensure_unicode(text) 
    356338        n,res= self.ansiwriter.write_color(text,attr) 
     
    360342            log(unicode(chunk)) 
    361343            self.SetConsoleTextAttribute(self.hout, attr.winattr) 
    362             self.WriteConsoleW(self.hout, chunk, len(chunk), byref(junk), None) 
     344            for short_chunk in split_block(chunk): 
     345                self.WriteConsoleW(self.hout, short_chunk, len(short_chunk), byref(junk), None) 
    363346        return n 
    364347 
     
    371354        n = c_int(0) 
    372355        self.SetConsoleTextAttribute(self.hout, attr) 
    373         self.WriteConsoleW(self.hout, ensure_unicode(chunk), len(chunk), byref(junk), None) 
     356        for short_chunk in split_block(chunk): 
     357            self.WriteConsoleW(self.hout, ensure_unicode(short_chunk), len(short_chunk), byref(junk), None) 
    374358        return len(text) 
    375359