From: Francois Fleuret Date: Fri, 13 Mar 2009 07:10:06 +0000 (+0100) Subject: Deal properly with no selection, just output nothing. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=5bd24e9e4be33163b1c8b1137e2e22005160dd0f;p=selector.git Deal properly with no selection, just output nothing. --- diff --git a/selector.cc b/selector.cc index 0f71d64..56b5b2a 100644 --- a/selector.cc +++ b/selector.cc @@ -279,12 +279,13 @@ void update_screen(int *current_line, int *temporary_line, int motion, } } - *temporary_line = new_line; if(motion != 0) { *current_line = new_line; } } + *temporary_line = new_line; + if(nb_printed_lines == 1) { addnstr("[no selection]\n", console_width); nb_printed_lines++; @@ -527,16 +528,22 @@ int main(int argc, char **argv) { curs_set(1); endwin(); - if((key == KEY_ENTER || key == '\n') && temporary_line >= 0 && temporary_line < nb_lines) { + if((key == KEY_ENTER || key == '\n')) { if(output_to_vt_buffer) { - inject_into_tty_buffer(lines[temporary_line]); + if(temporary_line >= 0 && temporary_line < nb_lines) { + inject_into_tty_buffer(lines[temporary_line]); + } } else { ofstream out(output_filename); if(out.fail()) { cerr << "Can not open " << output_filename << " for writing." << endl; exit(1); } else { - out << lines[temporary_line] << endl; + if(temporary_line >= 0 && temporary_line < nb_lines) { + out << lines[temporary_line] << endl; + } else { + out << endl; + } } out.flush(); }