I've written a cool Python script that uses curses to display colored text. When I SSH to the pi from my Mac, the terminal emulator is xterm-256color and everything looks great. However I can not get the script to run properly on the 5" HDMI display that is connected directly to the pi.

The default raspberry pi terminal emulator is LXTerminal

At the command line:

$ echo $TERM

I have already tried:

sudo update-alternatives –config x-terminal-emulator

...and that menu still shows my selection as xterm however this has no effect, even after restart, on echo $TERM or the actual display behavior.

I have also tried including this in my Python script (against all stackexchange recommendations not to...):

os.environ['TERM'] = 'xterm-256color'

...and in this case a few of the curses commands work, but clearly some escape codes are cross-wired and there are some unexpected results (some text is blinking instead of displaying green, etc)

Finally, I tried just running xterm at the command line:

xterm: Xt error: Can't open display:                                                                                              
xterm: DISPLAY is not set

So how can I permanently set xterm-256color as my terminal application for the connected HDMI monitor? Or, at least upgrade LXTerminal to 256 colors?

  • You're confusing terminal emulator (a program such as lxpanel or xterm) with a terminfo name (such as xterm-256color). You need to tell the program that the terminal (emulator) running it has the abilities of the xterm-256color terminfo entry. Terminal emulators run in X11. You are executing the script in the linux console, which is a terminal but it's not 256 color capable. Start the desktop environment, start lxterminal and try TERM=xterm-256color python my-cool-curses-script.py. – kba Feb 18 '16 at 17:52
  • Start the desktop environment: do you mean the GUI? I boot to the command line. And start LXTerminal? If I'm already at the command line I can just go right to TERM=xterm-256color...? – pinhead Feb 18 '16 at 18:04
  • Yes, you must start X (the GUI). If you're running raspian, Try startx. Programs like lxterminal must run within the GUI because that makes them do fancy stuff like menus, tabs, nice fonts or 256 colors. The standard linux console only supports 8 colors. – kba Feb 18 '16 at 18:07
  • Ahhh ok I get it now thanks. So a colorful application like htop just sticks to those 8 colors to run on the console? If I dumb down my script I should be able to run it straight from the command line at startup, my end goal. – pinhead Feb 18 '16 at 18:16
  • Right. I think you can also check curses.COLORS in python to determine available number of colors and then switch output for 8, 16 and 256 colors. And send me the github link once it's working :-) – kba Feb 18 '16 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.