diff --git a/Makefile b/Makefile index 05a9990..d7880c3 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ PREFIX=/usr/local -.c.o: script/compile +.o: script/compile script/compile $< $@ tmenu: main.o terminal.o textbuffer.o buffer.o menu.o util.o diff --git a/main.c b/main.c index c220140..c3c08d8 100644 --- a/main.c +++ b/main.c @@ -213,7 +213,7 @@ int main(int argc, char** argv) { fd_in = Terminal.fd(CURRENT_TERMINAL); - while ( (opt = getopt(argc, argv, "p:l:q")) != -1 ) { + while ( (opt = getopt(argc, argv, "p:l:qi")) != -1 ) { switch (opt) { case 'p': Menu.set_prompt(CURRENT_MENU, optarg); @@ -224,6 +224,9 @@ int main(int argc, char** argv) { case 'q': Menu.enable_status_line(CURRENT_MENU, 0); break; + case 'i': + Menu.set_insensitive(CURRENT_MENU, 1); + break; default: exit(EXIT_FAILURE); } diff --git a/menu.c b/menu.c index 00d9b01..67b4ec8 100644 --- a/menu.c +++ b/menu.c @@ -15,6 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ #define _POSIX_C_SOURCE 200809L +#define _GNU_SOURCE #include "menu.h" #include "util.h" @@ -41,6 +42,7 @@ struct menu { size_t matchbuf_len; BUFFER input; int status_line_enabled; + int case_insenstive; }; static MENU menunew(void) { @@ -64,6 +66,7 @@ static MENU menunew(void) { menu->input = TextBuffer.new(0); menu->status_line_enabled = MENU_DEFAULT_STATUS_LINE; + menu->case_insenstive=0; return menu; } @@ -201,7 +204,7 @@ static void menumatch(MENU self) { prepare_matches(self); char* searchpattern = pattern(self); for (i = 0; i < self->len; i++) { - if ( strstr(self->items[i], self->matchbuf) != NULL ) { + if ( (self->case_insenstive == 1 ? strcasestr(self->items[i], self->matchbuf) : strstr(self->items[i], self->matchbuf)) != NULL ) { addmatch(self, i); } else if ( fnmatch(searchpattern, self->items[i], 0) == 0 ) { addmatch(self, i); @@ -335,6 +338,9 @@ static void menusetmaxwidth(MENU self, int width) { static void menusetmaxheight(MENU self, int height) { self->max_height = height; } +static void menusetinsensitive(MENU self, int b) { + self->case_insenstive = b; +} static void menuenablestatusline(MENU self, int enabled) { self->status_line_enabled = enabled; @@ -355,4 +361,5 @@ struct menu_interface Menu = { .buffer = menubuffer, .set_max_width = menusetmaxwidth, .set_max_height = menusetmaxheight, + .set_insensitive = menusetinsensitive, }; diff --git a/menu.h b/menu.h index f0ce376..cff1254 100644 --- a/menu.h +++ b/menu.h @@ -32,6 +32,7 @@ extern struct menu_interface { void (*set_height)(MENU, int); void (*set_max_width)(MENU, int); void (*set_max_height)(MENU, int); + void (*set_insensitive)(MENU, int); void (*enable_status_line)(MENU, int); void (*add_item)(MENU, const char*); void (*select_next)(MENU);