1

I am working on a python program with a text-mode GUI based on urwid. urwid is a library to create ncurses-style programs with python.

Operating System is CentOS 7.

Everything works fine under 'normal' conditions (X-Server, terminal window). However, on a linux console without X-Server, urwid switches to a low-color mode. (With wrong color codes on certain machines, I get annoyingly blinking text than)

The funny point is, still using linux console, I just need to start screen as a workaround. Inside screen everything is fine again. Without having any special configuration for screen.

I already tried to compare a lot of environment information between pure text shell and screen shell, but that didn't help. For example, locale is identical, pythons sys.stdout.encoding is the same, doing ":runtime syntax/colortest.vim" in vim looks correct and colorful in both cases.

1 Answer 1

2

This is normal. It happens simply because the Linux kernel console does not support the 256-color mode. It wasn't written to use 256 colors, as in VGA text mode there's simply no way to do that. (In framebuffer mode it could, but the code still has the exact same constraints.) GNU Screen knows this and automatically translates from the 256-color palette to the nearest 16-color one.

Only very recent Linux versions (3.13 and later) started recognizing the 256-color escape codes, but even then it still maps them to the 16-color palette just like Screen would.

There are framebuffer-based terminal emulators like kmscon or fbterm which implement their own rendering, and draw everything via KMS. Use those if you want a capable terminal avoiding X11.


Blinking text happens because the 256-color codes are very easily confused the 16-color ones. For example, ESC [38;5;35m can be interpreted as the 256-color code, or three ANSI (16-color) codes.

  • The Linux console doesn't know what 38 means, so it just interprets 5 as "enable blink" and 35 as "foreground – color #5 (magenta)" in the usual way.
    (See for example this table, under "SGR".)

  • Meanwhile, your X11 terminals recognize the 38 as the magic "foreground – extra colors" code, so they interpret 5 as "use 256-color palette" and 35 as "use color #35 (cyan)".
    (There's a 24-bit RGB mode too, as ESC [38;2;<r>;<g>;<b>m.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .