Curses variables like `enter_italics_mode` are secretly defined to dereference through the `cur_term` variable. Be sure we do not read or write these curses variables if cur_term is NULL. See #8873, #8875. Add a regression test.