diff -r 32ef969adeed -r a18aaf460648 sources/interface.cpp --- a/sources/interface.cpp Fri May 15 21:43:21 2015 +0300 +++ b/sources/interface.cpp Tue May 26 11:41:58 2015 +0300 @@ -41,7 +41,7 @@ // int Interface::color_pair (Color fg, Color bg) { - return COLOR_PAIR ((int (fg) * NUM_COLORS) + int (bg)); + return COLOR_PAIR (1 + (int (fg) * NUM_COLORS) + int (bg)); } // ------------------------------------------------------------------------------------------------- @@ -143,26 +143,46 @@ Interface::Interface() : Session (this) { - ::initscr(); - ::start_color(); - ::raw(); +#ifdef XCURSES + ::Xinitscr(argc, argv); +#else + ::initscr(); +#endif + + ::cbreak(); ::keypad (stdscr, true); ::noecho(); ::refresh(); ::timeout (0); - ::use_default_colors(); InputHistory.clear(); InputHistory << ""; OutputLines.clear(); OutputLines << ColoredLine(); Title = format (APPNAME " %1 (%2)", full_version_string(), changeset_date_string()); - for (int i = 0; i < NUM_COLORS; ++i) - for (int j = 0; j < NUM_COLORS; ++j) + if (::has_colors()) { - init_pair ((i * NUM_COLORS + j), - (i == DEFAULT) ? -1 : i, - (j == DEFAULT) ? -1 : j); + ::start_color(); + ::use_default_colors(); + + int defaultFg = (use_default_colors() == OK) ? -1 : COLOR_WHITE; + int defaultBg = (use_default_colors() == OK) ? -1 : COLOR_BLACK; + + // Initialize color pairs + for (int i = 0; i < NUM_COLORS; ++i) + for (int j = 0; j < NUM_COLORS; ++j) + { + int pairnum = 1 + (i * NUM_COLORS + j); + int fg = (i == DEFAULT) ? defaultFg : i; + int bg = (j == DEFAULT) ? defaultBg : j; + + if (::init_pair (pairnum, fg, bg) == ERR) + print ("Unable to initialize color pair %1 (%2, %3)\n", pairnum, fg, bg); + } + } + else + { + print ("This terminal does not appear to support colors.\n"); } render_full(); @@ -602,6 +622,9 @@ { int ch = ::getch(); + if (ch < 0) + return; + if (ch == KEY_RESIZE) { ::clear(); @@ -702,6 +725,7 @@ break; case KEY_BACKSPACE: + case '\b': if (CursorPosition > 0) { mutable_current_input().remove_at (--CursorPosition);