selectel / pyte

Simple VTXXX-compatible linux terminal emulator
http://pyte.readthedocs.org/
GNU Lesser General Public License v3.0
649 stars 101 forks source link

How is the color encoded in screen? #150

Open kovkev opened 2 years ago

kovkev commented 2 years ago

When I print(str.encode(screen.display[0])), it seems like color is not encoded.

kovkev commented 2 years ago

Color is encoded in Char_s inside of Screen and are not returned by Screen.display

eldipa commented 2 years ago

Nope, Screen.display returns a plain styleless text. To get the details of each characters, including their colors you have to query each character:

for y in range(screen.lines):
   line = screen.buffer[y]
   for x in range(screen.columns):
        char = line[x]
        print(char.fg, char.bg) # foreground/background colors