sources/interface.cpp

changeset 81
a18aaf460648
parent 73
07dda51a7a8e
child 82
895088452014
equal deleted inserted replaced
77:32ef969adeed 81:a18aaf460648
39 39
40 // ------------------------------------------------------------------------------------------------- 40 // -------------------------------------------------------------------------------------------------
41 // 41 //
42 int Interface::color_pair (Color fg, Color bg) 42 int Interface::color_pair (Color fg, Color bg)
43 { 43 {
44 return COLOR_PAIR ((int (fg) * NUM_COLORS) + int (bg)); 44 return COLOR_PAIR (1 + (int (fg) * NUM_COLORS) + int (bg));
45 } 45 }
46 46
47 // ------------------------------------------------------------------------------------------------- 47 // -------------------------------------------------------------------------------------------------
48 // 48 //
49 const String& Interface::current_input() 49 const String& Interface::current_input()
141 // ------------------------------------------------------------------------------------------------- 141 // -------------------------------------------------------------------------------------------------
142 // 142 //
143 Interface::Interface() : 143 Interface::Interface() :
144 Session (this) 144 Session (this)
145 { 145 {
146 ::initscr(); 146 #ifdef XCURSES
147 ::start_color(); 147 ::Xinitscr(argc, argv);
148 ::raw(); 148 #else
149 ::initscr();
150 #endif
151
152 ::cbreak();
149 ::keypad (stdscr, true); 153 ::keypad (stdscr, true);
150 ::noecho(); 154 ::noecho();
151 ::refresh(); 155 ::refresh();
152 ::timeout (0); 156 ::timeout (0);
153 ::use_default_colors();
154 InputHistory.clear(); 157 InputHistory.clear();
155 InputHistory << ""; 158 InputHistory << "";
156 OutputLines.clear(); 159 OutputLines.clear();
157 OutputLines << ColoredLine(); 160 OutputLines << ColoredLine();
158 Title = format (APPNAME " %1 (%2)", full_version_string(), changeset_date_string()); 161 Title = format (APPNAME " %1 (%2)", full_version_string(), changeset_date_string());
159 162
160 for (int i = 0; i < NUM_COLORS; ++i) 163 if (::has_colors())
161 for (int j = 0; j < NUM_COLORS; ++j) 164 {
162 { 165 ::start_color();
163 init_pair ((i * NUM_COLORS + j), 166 ::use_default_colors();
164 (i == DEFAULT) ? -1 : i, 167
165 (j == DEFAULT) ? -1 : j); 168 int defaultFg = (use_default_colors() == OK) ? -1 : COLOR_WHITE;
169 int defaultBg = (use_default_colors() == OK) ? -1 : COLOR_BLACK;
170
171 // Initialize color pairs
172 for (int i = 0; i < NUM_COLORS; ++i)
173 for (int j = 0; j < NUM_COLORS; ++j)
174 {
175 int pairnum = 1 + (i * NUM_COLORS + j);
176 int fg = (i == DEFAULT) ? defaultFg : i;
177 int bg = (j == DEFAULT) ? defaultBg : j;
178
179 if (::init_pair (pairnum, fg, bg) == ERR)
180 print ("Unable to initialize color pair %1 (%2, %3)\n", pairnum, fg, bg);
181 }
182 }
183 else
184 {
185 print ("This terminal does not appear to support colors.\n");
166 } 186 }
167 187
168 render_full(); 188 render_full();
169 refresh(); 189 refresh();
170 NeedRefresh = false; 190 NeedRefresh = false;
599 // ------------------------------------------------------------------------------------------------- 619 // -------------------------------------------------------------------------------------------------
600 // 620 //
601 void Interface::handle_input() 621 void Interface::handle_input()
602 { 622 {
603 int ch = ::getch(); 623 int ch = ::getch();
624
625 if (ch < 0)
626 return;
604 627
605 if (ch == KEY_RESIZE) 628 if (ch == KEY_RESIZE)
606 { 629 {
607 ::clear(); 630 ::clear();
608 render_full(); 631 render_full();
700 NeedInputRender = true; 723 NeedInputRender = true;
701 } 724 }
702 break; 725 break;
703 726
704 case KEY_BACKSPACE: 727 case KEY_BACKSPACE:
728 case '\b':
705 if (CursorPosition > 0) 729 if (CursorPosition > 0)
706 { 730 {
707 mutable_current_input().remove_at (--CursorPosition); 731 mutable_current_input().remove_at (--CursorPosition);
708 NeedInputRender = true; 732 NeedInputRender = true;
709 } 733 }

mercurial