Search code examples
pythoncursesiterm2

Curses background color not working in iTerm2 with TERM=xterm


I have the following code that draws a small window with a message using curses.

import curses
import time

screen = curses.initscr()
curses.start_color()
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
window = curses.newwin(15, 60)
window.bkgd(' ', curses.color_pair(1))
window.addstr(7, 1, 'Hello')
window.refresh()
time.sleep(2)
curses.endwin()

I expect the background color to be blue, but the behavior is not consistent in iTerm2. With TERM=screen, I get the expected output: enter image description here

When TERM=xterm though, spaces are not painted: enter image description here

If I use a different character for the background, it's painted correctly. What could be the issue?

I'm using Python 3 and iTerm2 3.0.


Solution

  • The problem is that tmux does not support the "back color erase" feature assumed in the xterm terminal description.

    Further reading: