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; |