X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=selector.cc;h=a22329c6e00fcdf4f91a4ea1005f939ed2f4306f;hb=7320103ce09081bd91399522a4eb003c58289679;hp=27225b9cec383205e5ffa3808c7f85f12bf8681b;hpb=2cb82b02fab268f23ce67cee81438a1a0600f20d;p=selector.git diff --git a/selector.cc b/selector.cc index 27225b9..a22329c 100644 --- a/selector.cc +++ b/selector.cc @@ -23,7 +23,7 @@ */ // To use it as a super-history-search for bash: -// alias h='selector -d -i -b -v -f <(history)' +// selector -q -b -i -d -v -w -l 10000 <(history) #include #include @@ -51,7 +51,8 @@ char label_separator = '\0'; int output_to_vt_buffer = 0; int add_control_qs = 0; int with_colors = 1; -int zsh_history = 0, bash_history = 0; +int zsh_history = 0; +int bash_history = 0; int inverse_order = 0; int remove_duplicates = 0; int use_regexp = 0; @@ -61,6 +62,9 @@ int error_flash = 0; #define COLOR_MODELINE 1 #define COLOR_HIGHLIGHTED_LINE 2 +#define COLOR_ERROR 3 + +int attr_modeline, attr_highlighted_line, attr_error; ////////////////////////////////////////////////////////////////////// @@ -349,12 +353,13 @@ void update_screen(int *current_line, int *temporary_line, int motion, int nb_printed_lines = 0; - clear(); use_default_colors(); addstr("\n"); if(matcher.regexp_error) { - addstr("[regexp error]"); + 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)) { @@ -445,18 +450,14 @@ void update_screen(int *current_line, int *temporary_line, int motion, buffer[k++] = '\n'; buffer[k++] = '\0'; + clrtoeol(); + // 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); } @@ -473,21 +474,23 @@ void update_screen(int *current_line, int *temporary_line, int motion, *temporary_line = new_line; if(nb_printed_lines == 0) { - addnstr("[no selection]\n", console_width); + attron(attr_error); + addnstr("[no selection]", console_width); + attroff(attr_error); } } else { - addnstr("[empty choice]\n", console_width); + attron(attr_error); + addnstr("[empty choice]", console_width); + attroff(attr_error); } + clrtobot(); + // Draw the modeline 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'; @@ -536,11 +539,7 @@ void update_screen(int *current_line, int *temporary_line, int motion, move(0, cursor_x); - if(with_colors) { - attroff(COLOR_PAIR(COLOR_MODELINE)); - } else { - attroff(A_REVERSE); - } + attroff(attr_modeline); // We are done @@ -773,6 +772,7 @@ int main(int argc, char **argv) { << endl << " -h show this help" << endl << " -v inject the selected line in the tty" << endl + << " -w quote control characters with ^Qs when using -v" << endl << " -d remove duplicated lines" << endl << " -b remove the bash history line prefix" << endl << " -z remove the zsh history line prefix" << endl @@ -781,7 +781,7 @@ int main(int argc, char **argv) { << " -a case sensitive" << endl << " -m monochrome mode" << endl << " -q make a flash instead of a beep on an edition error" << endl - << " -- rest of the arguments are filenames" << endl + << " -- all following arguments are filenames" << endl << " -t " << endl << " add a title in the modeline" << endl << " -c <fg modeline> <bg modeline> <fg highlight> <bg highlight>" << endl @@ -883,28 +883,32 @@ int main(int argc, char **argv) { // 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_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; @@ -996,6 +1000,11 @@ int main(int argc, char **argv) { kill_after_cursor(pattern, &cursor_position); } + else if(key == '\014') { // ^L + // I suspect that we may sometime mess up the display + clear(); + } + update_screen(¤t_line, &temporary_line, motion, nb_lines, labels, cursor_position, pattern);