+
+ /*
+ * We should always check the screensize, just in case.
+ */
+ _nc_set_screen(sp);
+ sp->_term = cur_term;
+#ifdef USE_TERM_DRIVER
+ TCBOf(sp)->csp = sp;
+ _nc_get_screensize(sp, sp->_term, &slines, &scolumns);
+#else
+ _nc_get_screensize(sp, &slines, &scolumns);
+#endif
+ SET_LINES(slines);
+ SET_COLS(scolumns);
+
+ T((T_CREATE("screen %s %dx%d"),
+ NCURSES_SP_NAME(termname) (NCURSES_SP_ARG), slines, scolumns));
+
+ sp->_filtered = filtered;
+
+ /* implement filter mode */
+ if (filtered) {
+ slines = 1;
+ SET_LINES(slines);
+#ifdef USE_TERM_DRIVER
+ CallDriver(sp, td_setfilter);
+#else
+ /* *INDENT-EQLS* */
+ clear_screen = ABSENT_STRING;
+ cursor_address = ABSENT_STRING;
+ cursor_down = ABSENT_STRING;
+ cursor_up = ABSENT_STRING;
+ parm_down_cursor = ABSENT_STRING;
+ parm_up_cursor = ABSENT_STRING;
+ row_address = ABSENT_STRING;
+ cursor_home = carriage_return;
+
+ if (back_color_erase)
+ clr_eos = ABSENT_STRING;
+
+#endif
+ T(("filter screensize %dx%d", slines, scolumns));
+ }
+#ifdef __DJGPP__
+ T(("setting output mode to binary"));
+ fflush(output);
+ setmode(output, O_BINARY);
+#endif
+ NCURSES_SP_NAME(_nc_set_buffer) (NCURSES_SP_ARGx output, TRUE);
+ sp->_lines = (NCURSES_SIZE_T) slines;
+ sp->_lines_avail = (NCURSES_SIZE_T) slines;
+ sp->_columns = (NCURSES_SIZE_T) scolumns;
+
+ fflush(output);
+ sp->_ofd = output ? fileno(output) : -1;
+ sp->_ofp = output;
+ sp->out_limit = (size_t) ((2 + slines) * (6 + scolumns));
+ if ((sp->out_buffer = malloc(sp->out_limit)) == 0)
+ sp->out_limit = 0;
+ sp->out_inuse = 0;
+
+ SP_PRE_INIT(sp);
+ SetNoPadding(sp);
+
+#if NCURSES_EXT_FUNCS
+ sp->_default_color = FALSE;
+ sp->_has_sgr_39_49 = FALSE;
+
+ /*
+ * Set our assumption of the terminal's default foreground and background
+ * colors. The curs_color man-page states that we can assume that the
+ * background is black. The origin of this assumption appears to be
+ * terminals that displayed colored text, but no colored backgrounds, e.g.,
+ * the first colored terminals around 1980. More recent ones with better
+ * technology can display not only colored backgrounds, but all
+ * combinations. So a terminal might be something other than "white" on
+ * black (green/black looks monochrome too), but black on white or even
+ * on ivory.
+ *
+ * White-on-black is the simplest thing to use for monochrome. Almost
+ * all applications that use color paint both text and background, so
+ * the distinction is moot. But a few do not - which is why we leave this
+ * configurable (a better solution is to use assume_default_colors() for
+ * the rare applications that do require that sort of appearance, since
+ * is appears that more users expect to be able to make a white-on-black
+ * or black-on-white display under control of the application than not).
+ */
+#ifdef USE_ASSUMED_COLOR
+ sp->_default_fg = COLOR_WHITE;
+ sp->_default_bg = COLOR_BLACK;
+#else
+ sp->_default_fg = COLOR_DEFAULT;
+ sp->_default_bg = COLOR_DEFAULT;
+#endif
+
+ /*
+ * Allow those assumed/default color assumptions to be overridden at
+ * runtime:
+ */
+ if ((env = getenv("NCURSES_ASSUMED_COLORS")) != 0) {
+ int fg, bg;
+ char sep1, sep2;
+ int count = sscanf(env, "%d%c%d%c", &fg, &sep1, &bg, &sep2);
+ if (count >= 1) {
+ sp->_default_fg = ((fg >= 0 && fg < MaxColors) ? fg : COLOR_DEFAULT);
+ if (count >= 3) {
+ sp->_default_bg = ((bg >= 0 && bg < MaxColors) ? bg : COLOR_DEFAULT);
+ }
+ TR(TRACE_CHARPUT | TRACE_MOVE,
+ ("from environment assumed fg=%d, bg=%d",
+ sp->_default_fg,
+ sp->_default_bg));
+ }
+ }
+#if USE_COLORFGBG