Changeset 1382

Show
Ignore:
Timestamp:
06/27/06 15:20:12 (2 years ago)
Author:
jstenar
Message:

pyreadline: ANSI color changes were buggy. Changes today adds config support for prompt and input color, defaults to dos-color when python was launched.

Files:

Legend:

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

    r1379 r1382  
     12006-06-27 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
     2    * Changes from yesterday were not correct. Resulted in invisible docstrings 
     3      when using ? in ipython. 
     4    * ANSI sequence Esc[0m in write_color will now result in a white color with no  
     5      attributes (same as in cygwin). But the color of input text is controlled 
     6      set_input_color in config file with default same as dos-color was when 
     7      launching python. set_prompt_color controls prompt and raw_input text 
     8      and also defaults to same as dos-color was when launching python. 
     9      Unfortunately I have not found a way to control color of text that is printed  
     10      with a print statement. 
     11 
    1122006-06-26 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
    213    * Changes to ansi handling to preserve initial consoles color 
  • pyreadline/trunk/pyreadline/configuration/pyreadlineconfig.ini

    r1292 r1382  
    7070history_filename("~/.pythonhistory") 
    7171history_length(200) #value of -1 means no limit 
     72 
     73#set_input_color("yellow") #set color of input text 
     74#set_prompt_color("red")   #set color of prompt and raw_input text 
  • pyreadline/trunk/pyreadline/console.py

    r1379 r1382  
    196196        self.inputHookPtr = c_int.from_address(addressof(self.pythondll.PyOS_InputHook)).value 
    197197        setattr(Console, 'PyMem_Malloc', self.pythondll.PyMem_Malloc) 
     198        def exit(): 
     199            self.SetConsoleTextAttribute(self.hout, self.saveattr) 
     200            self.SetConsoleMode(self.hin, self.inmode) 
     201            self.FreeConsole() 
     202        import atexit 
     203        atexit.register(exit) 
     204             
    198205 
    199206    def __del__(self): 
     
    313320            if m: 
    314321                for part in m.group(1).split(";"): 
    315                     if part == "0": # No text attribute 
    316                         attr = 0 
     322                    if part == "0": # No text attribute but white 
     323                        attr = 7 
    317324                    elif part == "7": # switch on reverse 
    318325                        attr |= 0x4000 
  • pyreadline/trunk/pyreadline/rlmain.py

    r1292 r1382  
    5151        self.console = console.Console() 
    5252        self.size = self.console.size() 
    53         self.prompt_color = None 
    54         self.command_color = None 
     53        self.prompt_color = self.console.saveattr 
     54        self.command_color = self.console.saveattr 
    5555        self.key_dispatch = {} 
    5656        self.exit_dispatch = {} 
     
    12241224            logger.start_log(on,filename) 
    12251225            logger.log("STARTING LOG") 
     1226        def set_prompt_color(color): 
     1227            trtable={"black":0,"darkred":4,"darkgreen":2,"darkyellow":6,"darkblue":1,"darkmagenta":5,"darkcyan":3,"gray":7, 
     1228                     "red":4+8,"green":2+8,"yellow":6+8,"blue":1+8,"magenta":5+8,"cyan":3+8,"white":7+8} 
     1229            self.prompt_color=trtable.get(color.lower(),7)             
     1230             
     1231        def set_input_color(color): 
     1232            trtable={"black":0,"darkred":4,"darkgreen":2,"darkyellow":6,"darkblue":1,"darkmagenta":5,"darkcyan":3,"gray":7, 
     1233                     "red":4+8,"green":2+8,"yellow":6+8,"blue":1+8,"magenta":5+8,"cyan":3+8,"white":7+8} 
     1234            self.command_color=trtable.get(color.lower(),7)             
     1235             
     1236     
    12261237        loc={"branch":release.branch, 
    12271238             "bind_key":bind_key, 
     
    12351246             "debug_output":debug_output, 
    12361247             "history_filename":sethistoryfilename, 
    1237              "history_length":sethistorylength} 
     1248             "history_length":sethistorylength, 
     1249             "set_prompt_color":set_prompt_color, 
     1250             "set_input_color":set_input_color,} 
    12381251        if os.path.isfile(inputrcpath):  
    12391252            try: