From 4e68f637300c0e360d49f8f672d0675d42da0d1f Mon Sep 17 00:00:00 2001 From: Louie Shprung Date: Sun, 11 Aug 2024 17:49:28 -0400 Subject: (Currently broken) reimplementation of group and entry --- src/draw.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/draw.c') diff --git a/src/draw.c b/src/draw.c index 15a9289..1775329 100644 --- a/src/draw.c +++ b/src/draw.c @@ -42,7 +42,6 @@ int true_hover = 0; //0 = hovering on groups, 1 = hovering on entries GROUP **g; ENTRY **e; int g_count; -int e_count; int g_offset = 0; int *e_offset; @@ -70,15 +69,18 @@ int main(int argc, char **argv){ //Fill Groups //read the contents of the cfg file; print help message if invalid - if(!cfg_interp(cfg_path)){ + g = cfg_interp(cfg_path, &g_count); + if(g == NULL) { print_help(argv[0]); return 1; } + /* //Remove Empty Groups from the Array clean_groups(); g = get_groups(); //retrieve results of cfg_interp g_count = get_gcount(); //retrieve number of groups in g (only do this after removing empty groups) + */ //check that there are is at least one valid group if(g_count == 0){ @@ -91,7 +93,7 @@ int main(int argc, char **argv){ e_offset = calloc(g_count, sizeof(int)); //load cached data - load_cache(g_count, &g_hover, &e_hover, &e_offset, &true_hover, cfg_path); + //load_cache(g_count, &g_hover, &e_hover, &e_offset, &true_hover, cfg_path); //reopen stdout for drawing menu freopen("/dev/tty", "w", stdout); @@ -125,6 +127,7 @@ int main(int argc, char **argv){ update_display(true); //drawing is done, now run a while loop to receive input (ESC ends this loop) + input = 0; while(input != 27){ input = getch(); @@ -151,12 +154,12 @@ int main(int argc, char **argv){ case KEY_NPAGE: //case KEY_SDOWN: - trav_col((true_hover ? e_count : g_count)-1); + trav_col((true_hover ? get_ecount(g[g_hover]) : g_count)-1); break; case KEY_F(3): //jump to random group/entry - trav_col(rand() % (true_hover ? e_count : g_count)); + trav_col(rand() % (true_hover ? get_ecount(g[g_hover]) : g_count)); break; case KEY_F(5): @@ -333,13 +336,16 @@ void fill_col(int mode){ int i; WINDOW *col = (mode ? entry_win : group_win); - int count = (mode ? e_count : g_count); + int count = (mode ? get_ecount(g[g_hover]) : g_count); int offset = (mode ? e_offset[g_hover] : g_offset); int max_len = getmaxx(col)-2; //longest possible string length that can be displayed in the window int ycoord = 1; int max_y = HEIGHT-(6+GAP_SIZE); char *name; + mvwprintw(col, 0, 0, "i: %d\n", offset); + if(offset < 0) offset = 0; + for(i = 0+offset; i < count; i++){ if(ycoord >= max_y) break; //reached the bottom of the terminal window, stop drawing name = (mode ? get_ename(e[i]) : get_gname(g[i])); @@ -421,8 +427,7 @@ void update_col(int mode, int y_hl, bool resize){ break; case 1: - e_count = get_ecount(g[g_hover]); - e = get_entries(get_ghead(g[g_hover]), e_count); + e = get_gentries(g[g_hover]); fill_col(1); if(!resize) mvwchgat(entry_win, y_hl, 1, getmaxx(entry_win)-2, A_DIM, 1, NULL); else mvwchgat(entry_win, 1+e_hover[g_hover]-e_offset[g_hover], 1, getmaxx(entry_win)-2, A_DIM, (true_hover ? 2 : 1), NULL); @@ -464,7 +469,7 @@ void switch_col(){ void trav_col(int new_i){ int *focus = (true_hover ? &(e_hover[g_hover]) : &g_hover); //make it easy to know which column we are looking at int *offset = (true_hover ? &(e_offset[g_hover]) : &g_offset); - int count = (true_hover ? e_count : g_count); + int count = (true_hover ? get_ecount(g[g_hover]) : g_count); int max_hl = HEIGHT-(3+GAP_SIZE); //for some reason, this works int min_hl = 5; int oob_flag = 0; //0 = none, 1 = bottom, 2 = top @@ -520,7 +525,7 @@ int locateChar(char input){ if(fold_case && input >= 97 && input <= 122) input -= 32; if(true_hover){ //hovering on entries - for(i = location+1; i < e_count; i++){ + for(i = location+1; i < get_ecount(g[g_hover]); i++){ first_char = get_ename(e[i])[0]; if(fold_case && first_char >= 97 && first_char <= 122) first_char -= 32; if(input == first_char){ @@ -548,7 +553,7 @@ char *get_launch(){ char *program = get_gprog(g[g_hover]); char *flags = get_gflags(g[g_hover]); char *path = get_epath(e[e_hover[g_hover]]); - bool quotes = get_gquotes(g[g_hover]); + bool quotes = false; char *full_command = malloc(sizeof(char) * BUF_LEN); full_command[0] = '\0'; -- cgit From b5dd0df1808429a3c0ed1f86256962512b8273f5 Mon Sep 17 00:00:00 2001 From: Louie Shprung Date: Tue, 13 Aug 2024 21:06:03 -0400 Subject: Working implementation for lua config --- src/draw.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/draw.c') diff --git a/src/draw.c b/src/draw.c index 1775329..99b1a74 100644 --- a/src/draw.c +++ b/src/draw.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -40,7 +41,6 @@ int g_hover = 0; int *e_hover; int true_hover = 0; //0 = hovering on groups, 1 = hovering on entries GROUP **g; -ENTRY **e; int g_count; int g_offset = 0; int *e_offset; @@ -74,6 +74,10 @@ int main(int argc, char **argv){ print_help(argv[0]); return 1; } + // DEBUG + //for(i = 0; i < g_count; ++i) { + // group_debug(g[i]); + //} /* //Remove Empty Groups from the Array @@ -335,6 +339,7 @@ void fill_col(int mode){ //mode 1 = entry int i; + ENTRY **entries = get_gentries(g[g_hover]); WINDOW *col = (mode ? entry_win : group_win); int count = (mode ? get_ecount(g[g_hover]) : g_count); int offset = (mode ? e_offset[g_hover] : g_offset); @@ -343,15 +348,12 @@ void fill_col(int mode){ int max_y = HEIGHT-(6+GAP_SIZE); char *name; - mvwprintw(col, 0, 0, "i: %d\n", offset); - if(offset < 0) offset = 0; - for(i = 0+offset; i < count; i++){ if(ycoord >= max_y) break; //reached the bottom of the terminal window, stop drawing - name = (mode ? get_ename(e[i]) : get_gname(g[i])); + name = (mode ? get_ename(entries[i]) : get_gname(g[i])); //the name is too long, take the group to the trimming function - if(strlen(name) > max_len) name = trim_name(name, (mode ? get_epath(e[i]) : get_gname(g[i])), max_len); + if(strlen(name) > max_len) name = trim_name(name, (mode ? get_epath(entries[i]) : get_gname(g[i])), max_len); wmove(col, ycoord, 1); wprintw(col, "%s", name); ycoord++; @@ -427,7 +429,6 @@ void update_col(int mode, int y_hl, bool resize){ break; case 1: - e = get_gentries(g[g_hover]); fill_col(1); if(!resize) mvwchgat(entry_win, y_hl, 1, getmaxx(entry_win)-2, A_DIM, 1, NULL); else mvwchgat(entry_win, 1+e_hover[g_hover]-e_offset[g_hover], 1, getmaxx(entry_win)-2, A_DIM, (true_hover ? 2 : 1), NULL); @@ -483,7 +484,6 @@ void trav_col(int new_i){ mvwchgat(group_win, 1+g_hover-g_offset, 1, getmaxx(group_win)-2, A_NORMAL, 0, NULL); *focus = new_i; - //check offsets relating to new highlight, make sure highlight did not go oob while(*focus-*offset+5 > max_hl){ (*offset)++; @@ -517,6 +517,7 @@ void trav_col(int new_i){ } int locateChar(char input){ + ENTRY **entries = get_gentries(g[g_hover]); int location = (true_hover ? e_hover[g_hover] : g_hover); bool fold_case = get_case_sensitivity(); char first_char; @@ -526,7 +527,7 @@ int locateChar(char input){ if(true_hover){ //hovering on entries for(i = location+1; i < get_ecount(g[g_hover]); i++){ - first_char = get_ename(e[i])[0]; + first_char = get_ename(entries[i])[0]; if(fold_case && first_char >= 97 && first_char <= 122) first_char -= 32; if(input == first_char){ location = i; @@ -550,13 +551,12 @@ int locateChar(char input){ } char *get_launch(){ + ENTRY **entries = get_gentries(g[g_hover]); char *program = get_gprog(g[g_hover]); char *flags = get_gflags(g[g_hover]); - char *path = get_epath(e[e_hover[g_hover]]); + char *path = get_epath(entries[e_hover[g_hover]]); bool quotes = false; - char *full_command = malloc(sizeof(char) * BUF_LEN); - - full_command[0] = '\0'; + char *full_command = calloc(BUF_LEN, sizeof(char)); //if the entry is an executable file (doesn't have a launcher) if(!(strcmp(program, "./"))){ -- cgit From 002e6c5aac88cc931b838884f9ad21348f2f5641 Mon Sep 17 00:00:00 2001 From: Louie Shprung Date: Fri, 16 Aug 2024 16:39:39 -0400 Subject: Fix potential group allocation index incrementation issue --- src/draw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/draw.c') diff --git a/src/draw.c b/src/draw.c index 99b1a74..91476e3 100644 --- a/src/draw.c +++ b/src/draw.c @@ -214,7 +214,7 @@ bool *handle_args(int argc, char **argv, char **cfg_path){ {"version", no_argument, NULL, 'v'}, {0, 0, 0, 0} }; - bool *flags_set = calloc(FLAG_COUNT, sizeof(bool)); + bool *flags_set = calloc(FLAG_COUNT+1, sizeof(bool)); int i = 0; while(opt != -1){ -- cgit From 70a15daa4367e072268f4302a68b6f73f6acf6c5 Mon Sep 17 00:00:00 2001 From: Louie Shprung Date: Fri, 16 Aug 2024 18:43:36 -0400 Subject: Support for sorting entries --- src/draw.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/draw.c') diff --git a/src/draw.c b/src/draw.c index 91476e3..53185cb 100644 --- a/src/draw.c +++ b/src/draw.c @@ -78,6 +78,7 @@ int main(int argc, char **argv){ //for(i = 0; i < g_count; ++i) { // group_debug(g[i]); //} + //return 0; /* //Remove Empty Groups from the Array -- cgit From 996d3097cfa00363f16ff972b6da347b65ead23f Mon Sep 17 00:00:00 2001 From: Louie Shprung Date: Sat, 17 Aug 2024 14:50:07 -0400 Subject: Remove foldcase and hr options --- src/draw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/draw.c') diff --git a/src/draw.c b/src/draw.c index 53185cb..4dd5d75 100644 --- a/src/draw.c +++ b/src/draw.c @@ -520,7 +520,7 @@ void trav_col(int new_i){ int locateChar(char input){ ENTRY **entries = get_gentries(g[g_hover]); int location = (true_hover ? e_hover[g_hover] : g_hover); - bool fold_case = get_case_sensitivity(); + bool fold_case = true; char first_char; int i; -- cgit From a77f5393a584338561f217d3f87832e910bf937a Mon Sep 17 00:00:00 2001 From: Louie Shprung Date: Fri, 30 Aug 2024 14:36:35 -0400 Subject: Reenable caching --- src/draw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/draw.c') diff --git a/src/draw.c b/src/draw.c index 4dd5d75..7303ff6 100644 --- a/src/draw.c +++ b/src/draw.c @@ -97,8 +97,8 @@ int main(int argc, char **argv){ e_hover = calloc(g_count, sizeof(int)); e_offset = calloc(g_count, sizeof(int)); - //load cached data - //load_cache(g_count, &g_hover, &e_hover, &e_offset, &true_hover, cfg_path); + // load cached data + load_cache(g_count, &g_hover, &e_hover, &e_offset, &true_hover, cfg_path); //reopen stdout for drawing menu freopen("/dev/tty", "w", stdout); -- cgit From a3d9eb21789bf3587f176e6d155d610b8bc69dab Mon Sep 17 00:00:00 2001 From: Louie Shprung Date: Fri, 30 Aug 2024 14:49:00 -0400 Subject: Remove quotes from get_launch --- src/draw.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/draw.c') diff --git a/src/draw.c b/src/draw.c index 7303ff6..3412185 100644 --- a/src/draw.c +++ b/src/draw.c @@ -556,28 +556,21 @@ char *get_launch(){ char *program = get_gprog(g[g_hover]); char *flags = get_gflags(g[g_hover]); char *path = get_epath(entries[e_hover[g_hover]]); - bool quotes = false; char *full_command = calloc(BUF_LEN, sizeof(char)); //if the entry is an executable file (doesn't have a launcher) if(!(strcmp(program, "./"))){ - strcat(full_command, "\""); strcat(full_command, path); - strcat(full_command, "\""); } else{ - if(quotes) strcat(full_command, "\""); strcat(full_command, program); - if(quotes) strcat(full_command, "\""); if(flags[0] !='\0'){ strcat(full_command, " "); strcat(full_command, flags); } strcat(full_command, " "); - strcat(full_command, "\""); strcat(full_command, path); - strcat(full_command, "\""); } return full_command; -- cgit