From b68638f97027607253ed4d2b5a1a1b40436a61ad Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Wed, 8 Apr 2009 08:42:48 +0200 Subject: [PATCH] Fix a up-down arrow bug added recently. Use the native cursor instead of trying to build one by hand. --- selector.cc | 49 +++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/selector.cc b/selector.cc index 31a73e5..a58e2bb 100644 --- a/selector.cc +++ b/selector.cc @@ -442,6 +442,7 @@ void update_screen(int *current_line, int *temporary_line, int motion, // Draw the modeline move(0, 0); + if(with_colors) { attron(COLOR_PAIR(1)); } else { @@ -454,48 +455,36 @@ void update_screen(int *current_line, int *temporary_line, int motion, move(0, 0); + // There must be a more elegant way of moving the cursor at a + // location met during display + + int cursor_x = 0; + if(title) { addstr(title); addstr(" "); + cursor_x += strlen(title) + 1; } - printw("%d/%d ", nb_printed_lines, nb_lines); + sprintf(buffer, "%d/%d ", nb_printed_lines, nb_lines); + addstr(buffer); + cursor_x += strlen(buffer); addnstr(pattern, cursor_position); - - // Now we print the cursor. All that mess to have reverse video with - // and without color. - - if(with_colors) { - attroff(COLOR_PAIR(1)); - attron(COLOR_PAIR(3)); - } else { - attroff(A_REVERSE); - } + cursor_x += cursor_position; if(pattern[cursor_position]) { - addnstr(&pattern[cursor_position], 1); + addstr(pattern + cursor_position); } else { addstr(" "); } - if(with_colors) { - attroff(COLOR_PAIR(3)); - attron(COLOR_PAIR(1)); - } else { - attron(A_REVERSE); - } - - if(pattern[cursor_position]) { - addstr(pattern + cursor_position + 1); - } - - // Finished printing the cursor - if(use_regexp) { addstr(" [regexp]"); } + move(0, cursor_x); + if(with_colors) { attroff(COLOR_PAIR(1)); } else { @@ -775,7 +764,7 @@ int main(int argc, char **argv) { noecho(); // Hide the cursor - curs_set(0); + // curs_set(0); // So that the arrow keys work keypad(stdscr, TRUE); @@ -788,7 +777,7 @@ int main(int argc, char **argv) { color_fg_highlight < 0 || color_bg_highlight >= COLORS || color_bg_highlight < 0 || color_bg_highlight >= COLORS) { echo(); - curs_set(1); + // curs_set(1); endwin(); cerr << "Color numbers have to be between 0 and " << COLORS - 1 << "." << endl; exit(1); @@ -844,12 +833,12 @@ int main(int argc, char **argv) { } else if(key == KEY_DOWN || - key == '\014') { // ^N + key == '\016') { // ^N motion = 1; } else if(key == KEY_UP || - key == '\016') { // ^P + key == '\020') { // ^P motion = -1; } @@ -889,7 +878,7 @@ int main(int argc, char **argv) { } while(key != '\n' && key != KEY_ENTER && key != '\007'); // ^G echo(); - curs_set(1); + // curs_set(1); endwin(); ////////////////////////////////////////////////////////////////////// -- 2.39.5