def buf_to_color_str(buf):
 space = ' '
 pix = '{{bg#{0:02x}{1:02x}{2:02x}}} '
 pixels = []
 for h in range(buf.shape[0]):
  last = None
  for w in range(buf.shape[1]):
   rgb = buf[(h, w)]
   if ((last is not None) and (last == rgb).all()):
    pixels.append(space)
   else:
    pixels.append(pix.format(*rgb))
   last = rgb
  pixels.append('{NO_COLOR}\n')
 pixels[(-1)] = pixels[(-1)].rstrip()
 return ''.join(pixels)

def buf_to_color_str ( buf ) : space = ' ' pix = '{{bg#{0:02x}{1:02x}{2:02x}}} ' pixels = [ ] for h in range ( buf . shape [ 0 ] ) : last = None for w in range ( buf . shape [ 1 ] ) : rgb = buf [ ( h , w ) ] if ( ( last is not None ) and ( last == rgb ) . all ( ) ) : pixels . append ( space ) else : pixels . append ( pix . format ( * rgb ) ) last = rgb pixels . append ( '{NO_COLOR}\n' ) pixels [ ( - 1 ) ] = pixels [ ( - 1 ) ] . rstrip ( ) return '' . join ( pixels )
converts an rgb array to a xonsh color string .