Skip to content

fix: makefile, add: case insensitivity #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
9 changes: 8 additions & 1 deletion menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _POSIX_C_SOURCE 200809L
#define _GNU_SOURCE
#include "menu.h"

#include "util.h"
Expand All @@ -41,6 +42,7 @@ struct menu {
size_t matchbuf_len;
BUFFER input;
int status_line_enabled;
int case_insenstive;
};

static MENU menunew(void) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -355,4 +361,5 @@ struct menu_interface Menu = {
.buffer = menubuffer,
.set_max_width = menusetmaxwidth,
.set_max_height = menusetmaxheight,
.set_insensitive = menusetinsensitive,
};
1 change: 1 addition & 0 deletions menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down