+ SCREEN *s;
+#ifndef __MINGW32__
+ const char *cap;
+#endif
+ const char *interp;
+
+ /* If the top level interpreter is not the console/tui (e.g.,
+ MI), enabling curses will certainly lose. */
+ interp = top_level_interpreter ()->name ();
+ if (strcmp (interp, INTERP_TUI) != 0)
+ error (_("Cannot enable the TUI when the interpreter is '%s'"), interp);
+
+ /* Don't try to setup curses (and print funny control
+ characters) if we're not outputting to a terminal. */
+ if (!ui_file_isatty (gdb_stdout))
+ error (_("Cannot enable the TUI when output is not a terminal"));
+
+ s = newterm (NULL, stdout, stdin);
+#ifdef __MINGW32__
+ /* The MinGW port of ncurses requires $TERM to be unset in order
+ to activate the Windows console driver. */
+ if (s == NULL)
+ s = newterm ((char *) "unknown", stdout, stdin);
+#endif
+ if (s == NULL)
+ {
+ error (_("Cannot enable the TUI: error opening terminal [TERM=%s]"),
+ gdb_getenv_term ());
+ }
+ w = stdscr;
+ if (has_colors ())
+ {
+#ifdef HAVE_USE_DEFAULT_COLORS
+ /* Ncurses extension to help with resetting to the default
+ color. */
+ use_default_colors ();
+#endif
+ start_color ();
+ }
+
+ /* Check required terminal capabilities. The MinGW port of
+ ncurses does have them, but doesn't expose them through "cup". */
+#ifndef __MINGW32__
+ cap = tigetstr ((char *) "cup");
+ if (cap == NULL || cap == (char *) -1 || *cap == '\0')
+ {
+ endwin ();
+ delscreen (s);
+ error (_("Cannot enable the TUI: "
+ "terminal doesn't support cursor addressing [TERM=%s]"),
+ gdb_getenv_term ());
+ }
+#endif