From e9a5dbfb21e1c625bed5683b9170d1a76ba75a56 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Mon, 13 Apr 2009 14:59:44 +0200 Subject: [PATCH] Added the ^I keystroke to switch the case-sensitivity. --- REVISION_NUMBER | 2 +- selector.1 | 3 ++- selector.cc | 41 +++++++++++++++++++++++++++++++++++------ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/REVISION_NUMBER b/REVISION_NUMBER index dee261d..b4f334f 100644 --- a/REVISION_NUMBER +++ b/REVISION_NUMBER @@ -1 +1 @@ -140 +141 diff --git a/selector.1 b/selector.1 index 10cf637..c349ace 100644 --- a/selector.1 +++ b/selector.1 @@ -12,7 +12,8 @@ in real time to show only the lines containing all the said strings, or matching the regexp. The ^R key switches between the standard multi-substring mode and the -regexp mode. +regexp mode, and ^I between the case-sensitive and case-insensitive +modes. The main usage of selector is as an efficient search in the shell command history. With the correct option, it will inject the selected diff --git a/selector.cc b/selector.cc index ccc6158..46ff098 100644 --- a/selector.cc +++ b/selector.cc @@ -84,6 +84,26 @@ void check_opt(int argc, char **argv, int n_opt, int n, const char *help) { } } +int string_to_positive_integer(char *string) { + int error = 0; + int result = 0; + + if(*string) { + for(char *s = string; *s; s++) { + if(*s >= '0' && *s <= '9') { + result = result * 10 + int(*s - '0'); + } else error = 1; + } + } else error = 1; + + if(error) { + cerr << "Value `" << string << "' is not a positive integer." << endl; + exit(1); + } + + return result; +} + ////////////////////////////////////////////////////////////////////// // A quick and dirty hash table @@ -483,6 +503,10 @@ void update_screen(int *current_line, int *temporary_line, int motion, addstr(" [regexp]"); } + if(case_sensitive) { + addstr(" [case]"); + } + move(0, cursor_x); if(with_colors) { @@ -667,16 +691,16 @@ int main(int argc, char **argv) { else if(strcmp(argv[i], "-l") == 0) { check_opt(argc, argv, i, 1, ""); - nb_lines_max = atoi(argv[i+1]); + nb_lines_max = string_to_positive_integer(argv[i+1]); i += 2; } else if(strcmp(argv[i], "-c") == 0) { check_opt(argc, argv, i, 4, " "); - color_fg_modeline = atoi(argv[i+1]); - color_bg_modeline = atoi(argv[i+2]); - color_fg_highlight = atoi(argv[i+3]); - color_bg_highlight = atoi(argv[i+4]); + color_fg_modeline = string_to_positive_integer(argv[i + 1]); + color_bg_modeline = string_to_positive_integer(argv[i + 2]); + color_fg_highlight = string_to_positive_integer(argv[i + 3]); + color_bg_highlight = string_to_positive_integer(argv[i + 4]); i += 5; } @@ -891,6 +915,10 @@ int main(int argc, char **argv) { use_regexp = !use_regexp; } + else if(key == '\011') { // ^R + case_sensitive = !case_sensitive; + } + else if(key == '\025') { // ^U kill_before_cursor(pattern, &cursor_position); } @@ -933,7 +961,8 @@ int main(int argc, char **argv) { } out.flush(); } - + } else { + cout << "Aborted." << endl; } for(int l = 0; l < nb_lines; l++) { -- 2.39.5