parameters: ( text, attr=None)
return_statement: return res
docstring: write text at current cursor position and interpret color escapes.
  
      return the number of characters written.
docstring_summary: write text at current cursor position and interpret color escapes.
docstring_tokens: write text at current cursor position and interpret color escapes .
function: def write_color_old( text, attr=None):
      '''write text at current cursor position and interpret color escapes.
  
      return the number of characters written.
      '''
      res=[]
      chunks = terminal_escape.split(text)
      n = 0 # count the characters we actually write, omitting the escapes
      if attr is None:#use attribute from initial console
          attr = 15
      for chunk in chunks:
          m = escape_parts.match(chunk)
          if m:
              for part in m.group(1).split(";"):
                  if part == "0": # No text attribute
                      attr = 0
                  elif part == "7": # switch on reverse
                      attr |= 0x4000
                  if part == "1": # switch on bold (i.e. intensify foreground color)
                      attr |= 0x08
                  elif len(part) == 2 and "30" <= part <= "37": # set foreground color
                      part = int(part)-30
                      # we have to mirror bits
                      attr = (attr & ~0x07) | ((part & 0x1) << 2) | (part & 0x2) | ((part & 0x4) >> 2)
                  elif len(part) == 2 and "40" <= part <= "47": # set background color
                      part = int(part)-40
                      # we have to mirror bits
                      attr = (attr & ~0x70) | ((part & 0x1) << 6) | ((part & 0x2) << 4) | ((part & 0x4) << 2)
                  # ignore blink, underline and anything we don't understand
              continue
          n += len(chunk)
          if chunk:
              res.append(("0x%x"%attr,chunk))
      return res
function_tokens: def write_color_old ( text , attr = None ) : res = [ ] chunks = terminal_escape . split ( text ) n = 0 # count the characters we actually write, omitting the escapes if attr is None : #use attribute from initial console attr = 15 for chunk in chunks : m = escape_parts . match ( chunk ) if m : for part in m . group ( 1 ) . split ( ";" ) : if part == "0" : # No text attribute attr = 0 elif part == "7" : # switch on reverse attr |= 0x4000 if part == "1" : # switch on bold (i.e. intensify foreground color) attr |= 0x08 elif len ( part ) == 2 and "30" <= part <= "37" : # set foreground color part = int ( part ) - 30 # we have to mirror bits attr = ( attr & ~ 0x07 ) | ( ( part & 0x1 ) << 2 ) | ( part & 0x2 ) | ( ( part & 0x4 ) >> 2 ) elif len ( part ) == 2 and "40" <= part <= "47" : # set background color part = int ( part ) - 40 # we have to mirror bits attr = ( attr & ~ 0x70 ) | ( ( part & 0x1 ) << 6 ) | ( ( part & 0x2 ) << 4 ) | ( ( part & 0x4 ) << 2 ) # ignore blink, underline and anything we don't understand continue n += len ( chunk ) if chunk : res . append ( ( "0x%x" % attr , chunk ) ) return res