Added selection count in statusbar

pull/31/head
mananapr 5 years ago
parent bab476e9a7
commit eaa29ac664

71
cf.c

@ -44,6 +44,9 @@ int len_bookmarks=0;
// To store number of scripts
int len_scripts=0;
// To store number of selected files
int selectedFiles = 0;
// Counter variable
int i = 0;
@ -146,6 +149,40 @@ int startx, starty, maxx, maxy;
// HELPER FUNCTIONS //
//////////////////////
/*
Checks if `path` is a file or directory
*/
int is_regular_file(const char *path)
{
struct stat path_stat;
stat(path, &path_stat);
return S_ISREG(path_stat.st_mode);
}
/*
Sets value of `selectedFiles`
*/
void setSelectionCount()
{
FILE *fp = fopen(clipboard_path, "r");
if( fp == NULL )
{
selectedFiles = 0;
return;
}
char buf[PATH_MAX];
int num = 0;
while(fgets(buf, PATH_MAX, (FILE*) fp))
{
num++;
}
selectedFiles = num;
fclose(fp);
}
/*
Initializes the program
Sets the relevant file paths
@ -331,6 +368,12 @@ void init(int argc, char* argv[])
printf("Incorrect Usage!\n");
exit(1);
}
// Set value of selectedFiles
if( SHOW_SELECTION_COUNT == 1 )
{
setSelectionCount();
}
}
@ -349,17 +392,6 @@ void curses_init()
}
/*
Checks if `path` is a file or directory
*/
int is_regular_file(const char *path)
{
struct stat path_stat;
stat(path, &path_stat);
return S_ISREG(path_stat.st_mode);
}
/*
Checks if a file exists or not
*/
@ -1512,6 +1544,10 @@ void displayStatus()
{
wmove(status_win,1,0);
wattron(status_win, COLOR_PAIR(2));
if( SHOW_SELECTION_COUNT == 1 )
{
wprintw(status_win,"[%d] ", selectedFiles);
}
wprintw(status_win, "(%d/%d)", selection+1, len);
wprintw(status_win, " %s", dir);
wattroff(status_win, COLOR_PAIR(2));
@ -2385,6 +2421,7 @@ int main(int argc, char* argv[])
free(temp);
}
renameFiles();
selectedFiles = 0;
break;
// Write to clipboard
@ -2408,9 +2445,15 @@ int main(int argc, char* argv[])
exit(1);
}
if (checkClipboard(temp_dir) == 1)
{
removeClipboard(replace(temp,"\n","//"));
selectedFiles--;
}
else
{
writeClipboard(replace(temp,"\n","//"));
selectedFiles++;
}
free(temp);
scrollDown();
break;
@ -2418,6 +2461,7 @@ int main(int argc, char* argv[])
// Empty Clipboard
case KEY_EMPTYSEL:
emptyClipboard();
selectedFiles = 0;
break;
// Copy clipboard contents to present directory
@ -2428,6 +2472,7 @@ int main(int argc, char* argv[])
// Moves clipboard contents to present directory
case KEY_MV:
moveFiles(dir);
selectedFiles = 0;
break;
// Moves clipboard contents to trash
@ -2449,7 +2494,10 @@ int main(int argc, char* argv[])
displayAlert("Confirm (y/n): ");
confirm = wgetch(status_win);
if(confirm == 'y')
{
removeFiles();
selectedFiles = 0;
}
else
{
displayAlert("ABORTED");
@ -2546,6 +2594,7 @@ int main(int argc, char* argv[])
{
int status;
waitpid(pid, &status, 0);
setSelectionCount();
}
refresh();
}

@ -12,6 +12,9 @@
// Set to 0 if you want to disable borders
#define SHOW_BORDERS 1
// Set to 0 if you don't want to see number of selected files in the statusbar
#define SHOW_SELECTION_COUNT 1
// Program used to open non-text file (Eg: `xdg-open` or `thunar`)
#define FILE_OPENER "xdg-open"

Loading…
Cancel
Save