6

I'm working on a project for school right now, and I'm using curses. Although, I am a bit disappointed on the restrict of colors. The colorama module has LOTS more colors, and they work on my Terminal, so I know my terminal is capable of lots of colors. Although, in Curses, we only have

COLOR_BLACK
COLOR_RED
COLOR_GREEN
COLOR_YELLOW
COLOR_BLUE
COLOR_MAGENTA
COLOR_CYAN
COLOR_WHITE

It would be REALLY nice if there where more colors.

Note: Colorama gives ANSI escape codes, and doesn't work with Curses, so no shortcut there.

Nic
  • 6,211
  • 10
  • 46
  • 69
Thor Correia
  • 1,528
  • 3
  • 23
  • 30
  • 1
    That's just the way terminals have been made. Be thankful you don't have to use a monochrome monitor. :) However, some modern terminals do support 256 color, and urxvt has it as a compile-time option. – Keith Oct 25 '12 at 02:15
  • What terminal are you using and what is the TERM environment variable set to? – Craig Oct 25 '12 at 16:57
  • Related: http://stackoverflow.com/questions/18551558/how-to-use-terminal-color-palette-with-curses – chtenb Aug 06 '15 at 09:56

4 Answers4

7

A color in curses is just a number from 0 to curses.COLORS - 1. Those you listed are just the named constants curses provide you.

Curses supports 256 colors just fine, but it only enables that if your terminal identifies itself as a 256-color capable terminal via TERM environmental variable.

While most modern terminals do support 256 colors for years, such as Gnome Terminal and Xterm, many still do not report as such.

If you run your program using env TERM=xterm-256color yourprogram, curses will enable 256 colors, and it will work fine as long as your terminal actually supports it!

If it does work, change your terminal to automatically set its TERM appropriately.

Recommended further reading:

http://blog.sanctum.geek.nz/term-strings/

http://blog.sanctum.geek.nz/256-colour-terminals/

https://unix.stackexchange.com/a/181766/4919

https://askubuntu.com/a/578798/11015

Community
  • 1
  • 1
MestreLion
  • 12,698
  • 8
  • 66
  • 57
  • 3
    Note that there are also restrictions on colour pairs as documented in the [FAQ](http://invisible-island.net/ncurses/ncurses.faq.html#xterm_16MegaColors). In short, you can use up to 256 colour pairs on ncurses 5 and 32767 on ncurses 6. – Peter Brittain Nov 10 '15 at 16:28
5

Urwid supports 256 colour terminals: palette_test.py.

I recommend it as a superior alternative to the curses module (if using the curses module isn't a requirement of the project).

Pedro Romano
  • 10,973
  • 4
  • 46
  • 50
  • 3
    IMHO there is no need to change the module, as `curses` supports 256 colors just fine if your `TERM` is set correctly, and it's available out of the box with Python as part of its Standard Library. – MestreLion Jan 29 '15 at 12:00
  • 2 of the 3 links are dead. – Z4-tier Aug 20 '22 at 14:17
1

On GitHub there is a free to use, study, modify and re-distribute High Level GUI library, at "https://github.com/rigordo959/tsWxGTUI_PyVx_Repository".

It is implemented in Python 2x & 3x using the "curses" Low Level GUI package.

Your application programs can be programmed using a character-mode subset of the pixel-mode "wxPython" High Level GUI API. It supports displays with keyboard and mouse input and various terminal emulators including the color xterms (8-color with 64-color pairs and 16-color with 256-color pairs) and non-color vt100/vt220.

It includes Python modules that can configure up to 256 curses colors. However curses cannot handle more than 256 color-pairs which means no more than 16 colors if the application will need to handle the 256 color pairs to expose or hide text.

-1

The Fabulous package provides 256 colour support but it is not linked to ncurses. Although, I am sure you can mix the two.

Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156