#define COLOR_HIGHLIGHTED_LINE 2
#define COLOR_ERROR 3
+int attr_modeline, attr_highlighted_line, attr_error;
+
//////////////////////////////////////////////////////////////////////
void inject_into_tty_buffer(char *string) {
}
}
-void print_error_message(const char *message, int width) {
- if(with_colors) {
- attron(COLOR_PAIR(COLOR_ERROR));
- addnstr(message, width);
- attroff(COLOR_PAIR(COLOR_ERROR));
- } else {
- attron(A_STANDOUT);
- addnstr(message, width);
- attroff(A_STANDOUT);
- }
-}
-
//////////////////////////////////////////////////////////////////////
// A quick and dirty hash table
addstr("\n");
if(matcher.regexp_error) {
- print_error_message("[regexp error]", console_width);
+ attron(attr_error);
+ addnstr("[regexp error]", console_width);
+ attroff(attr_error);
} else if(nb_lines > 0) {
int new_line;
if(match(lines[*current_line], &matcher)) {
// Highlight the highlighted line ...
if(l == new_line) {
- if(with_colors) {
- attron(COLOR_PAIR(COLOR_HIGHLIGHTED_LINE));
- addnstr(buffer, console_width);
- attroff(COLOR_PAIR(COLOR_HIGHLIGHTED_LINE));
- } else {
- attron(A_STANDOUT);
- addnstr(buffer, console_width);
- attroff(A_STANDOUT);
- }
+ attron(attr_highlighted_line);
+ addnstr(buffer, console_width);
+ attroff(attr_highlighted_line);
} else {
addnstr(buffer, console_width);
}
*temporary_line = new_line;
if(nb_printed_lines == 0) {
- print_error_message("[no selection]\n", console_width);
+ attron(attr_error);
+ addnstr("[no selection]", console_width);
+ attroff(attr_error);
}
} else {
- print_error_message("[empty choice]\n", console_width);
+ attron(attr_error);
+ addnstr("[empty choice]", console_width);
+ attroff(attr_error);
}
clrtobot();
move(0, 0);
- if(with_colors) {
- attron(COLOR_PAIR(COLOR_MODELINE));
- } else {
- attron(A_REVERSE);
- }
+ attron(attr_modeline);
for(int k = 0; k < console_width; k++) buffer[k] = ' ';
buffer[console_width] = '\0';
move(0, cursor_x);
- if(with_colors) {
- attroff(COLOR_PAIR(COLOR_MODELINE));
- } else {
- attroff(A_REVERSE);
- }
+ attroff(attr_modeline);
// We are done
// So that the arrow keys work
keypad(stdscr, TRUE);
- if(with_colors) {
+ attr_error = A_STANDOUT;
+ attr_modeline = A_REVERSE;
+ attr_highlighted_line = A_STANDOUT;
- if(has_colors()) {
+ if(with_colors && has_colors()) {
- start_color();
+ start_color();
- if(color_fg_modeline < 0 || color_fg_modeline >= COLORS ||
- color_bg_modeline < 0 || color_bg_modeline >= COLORS ||
- color_fg_highlight < 0 || color_bg_highlight >= COLORS ||
- color_bg_highlight < 0 || color_bg_highlight >= COLORS) {
- echo();
- endwin();
- cerr << "Color numbers have to be between 0 and " << COLORS - 1 << "." << endl;
- exit(1);
- }
+ if(color_fg_modeline < 0 || color_fg_modeline >= COLORS ||
+ color_bg_modeline < 0 || color_bg_modeline >= COLORS ||
+ color_fg_highlight < 0 || color_bg_highlight >= COLORS ||
+ color_bg_highlight < 0 || color_bg_highlight >= COLORS) {
+ echo();
+ endwin();
+ cerr << "Color numbers have to be between 0 and " << COLORS - 1 << "." << endl;
+ exit(1);
+ }
- init_pair(COLOR_MODELINE, color_fg_modeline, color_bg_modeline);
- init_pair(COLOR_HIGHLIGHTED_LINE, color_fg_highlight, color_bg_highlight);
- init_pair(COLOR_ERROR, COLOR_WHITE, COLOR_RED);
+ init_pair(COLOR_MODELINE, color_fg_modeline, color_bg_modeline);
+ init_pair(COLOR_HIGHLIGHTED_LINE, color_fg_highlight, color_bg_highlight);
+ init_pair(COLOR_ERROR, COLOR_WHITE, COLOR_RED);
+
+ attr_modeline = COLOR_PAIR(COLOR_MODELINE);
+ attr_highlighted_line = COLOR_PAIR(COLOR_HIGHLIGHTED_LINE);
+ attr_error = COLOR_PAIR(COLOR_ERROR);
- } else {
- with_colors = 0;
- }
}
int key;