1
0
mirror of https://gittea.dev/nova/th.git synced 2025-10-21 18:30:15 -04:00

Compare commits

...

4 Commits

5 changed files with 120 additions and 79 deletions

View File

@@ -69,8 +69,11 @@ static const binding key_binding[] = {
{ "G", jump_bottom, NULL, "jump to last file in dir" },
{ "gg", jump_top, NULL, "jump to first file in dir" },
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" }, /* the path you started th in */
{ "gD", jump_to_dir, "$HOME/Downloads", "jump to $HOME/Downloads" },
{ "gC", jump_to_dir, "$HOME/Documents", "jump to $HOME/Documents" },
{ "gP", jump_to_dir, "$HOME/Pictures", "jump to $HOME/Pictures" },
{ "gM", jump_to_dir, "$HOME/Music", "jump to $HOME/Music" },
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
{ "gp", jump_to_dir, "/etc/portage", "jump to /etc/portage" },
@@ -87,11 +90,10 @@ static const binding key_binding[] = {
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
{ "on", order_by, sort_natural, "order natural" },
{ "or", not_implemented, "", "order reverse" },
{ "oe", not_implemented, "", "order extension" },
{ "oe", not_implemented, NULL, "order extension" },
{ "os", order_by, sort_size, "order size" },
{ "ot", order_by, sort_type, "order type" },
{ "oz", order_by, sort_random, "order random" },
{ "or", order_by, sort_random, "order random" },
{ "oa", order_by, sort_alpha, "order alphabetically" },
{ "mk", makedir, NULL, "create directory" },
@@ -105,7 +107,7 @@ static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this define
static const char clipboard_cmd[] = "xsel -ib --trim"; /* assembles the following shell cmd: echo "hovered_file" | clipboard_cmd */
static const char ui_btm_text_storage_left[] = "total free";
static const char ui_btm_current_dir_size[] = "sum of dir";
static const char ui_btm_current_dir_size[] = "sum of dir,";
/* {{{ */
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);

View File

@@ -258,6 +258,7 @@ void move_right(){
char match = 0;
char *mime = get_mimetype(mid_content[selected_file_current].file_name);
char *extension = strrchr(mid_content[selected_file_current].file_name, '.');
if (extension != NULL) {
for (i = 0; i < file_extension_default_count; i++) {
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
char *cmd = concat(file_extension_default_cmd[i].command, " ./\"");
@@ -274,6 +275,7 @@ void move_right(){
break;
}
}
}
if (match == 0) {
for (i = 0; i < mimetype_default_count; i++) {
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
@@ -640,6 +642,7 @@ void order_by(int passes, int index){
(void)passes;
free(seed);
seed = NULL;
seed = malloc(sizeof(time_t));
*seed = time(NULL);

2
main.c
View File

@@ -112,6 +112,7 @@ int main(){
threading_free();
free(start_path);
/*
if (threading) {
pthread_join(thread_l, NULL);
pthread_join(thread_r, NULL);
@@ -119,6 +120,7 @@ int main(){
pthread_join(thread_t, NULL);
pthread_join(thread_b, NULL);
}
*/
delwin(win_l);
delwin(win_m);

View File

@@ -119,15 +119,15 @@ int sort_random(const void *file0, const void *file1){
return 1;
}
time_t num = (time_t)&seed;
unsigned long i;
for (i = 0; i < 6; i++){
time_t i;
for (i = num%2; i < 6+(((time_t)&seed)%2); i++){
num ^= *seed;
if (num%2) {
num ^= (time_t)&num;
num ^= num << i;
num ^= num << (i + (((time_t)&seed)%5));
} else {
num ^= (time_t)&seed;
num ^= num >> i;
num ^= num >> (i + (((time_t)&num)%5));
}
}
num ^= getpid();

View File

@@ -48,12 +48,15 @@ volatile unsigned long selected_file_last = 0;
extern unsigned int terminal_width;
extern unsigned int status;
unsigned int btm_status;
void *thread_mid(){
while(!(status & STATUS_QUIT_PROGRAM)){
pthread_mutex_lock(&mutex_mid);
pthread_cond_wait(&cond_mid, &mutex_mid);
unsigned int local_status = status;
char *path;
if((path=getcwd(NULL, 0)) == NULL) {
@@ -63,7 +66,7 @@ void *thread_mid(){
} else {
if (status & STATUS_RELOAD_DIRECTORY) {
if (local_status & STATUS_RELOAD_DIRECTORY) {
unsigned long i = 0;
for (i = 0; i < mid_file_count; i++) {
free(mid_content[i].file_name);
@@ -92,6 +95,7 @@ void *thread_mid(){
pthread_mutex_unlock(&mutex_selection);
}
btm_status = local_status;
pthread_cond_signal(&cond_rgt);
pthread_cond_signal(&cond_btm);
@@ -106,6 +110,7 @@ void *thread_lft(){
while(!(status & STATUS_QUIT_PROGRAM)){
pthread_mutex_lock(&mutex_lft);
pthread_cond_wait(&cond_lft, &mutex_lft);
unsigned int local_status = status;
char *path;
if((path=getcwd(NULL, 0)) == NULL) {
@@ -117,7 +122,7 @@ void *thread_lft(){
path[strrchr(path, '/')-path] = '\0';
path[0] = '/';
if (status & STATUS_RELOAD_DIRECTORY) {
if (local_status & STATUS_RELOAD_DIRECTORY) {
lft_file_count = get_dir_size(path);
free(lft_content);
lft_content = malloc(lft_file_count * sizeof(file));
@@ -231,7 +236,8 @@ void *thread_top(){
top_width = sizeof("cannot open directory");
top_buffer = "cannot open directory";
} else {
top_buffer = getcwd(NULL, 0);
top_buffer = malloc(strlen(path)+1);
memcpy(top_buffer, path, strlen(path)+1);
top_width = strlen(top_buffer);
}
@@ -241,17 +247,97 @@ void *thread_top(){
pthread_exit(0);
}
void *thread_btm(){
char *path = malloc(sizeof(char));
char *ui_btm_right_block = malloc(sizeof(char));
unsigned int ui_btm_right_block_size = 0;
unsigned int buffer_width = 0;
while(!(status & STATUS_QUIT_PROGRAM)){
pthread_mutex_lock(&mutex_btm);
pthread_cond_wait(&cond_btm, &mutex_btm);
unsigned int local_status = btm_status;
if (local_status & (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY)) {
/*{{{ parse storage info; the fold of shame*/
pthread_mutex_lock(&mutex_mid);
unsigned long i;
float total_dir_size = 0;
for(i = 0; i < mid_file_count; i++) {
if ((mid_content[i].file_type & (FILE_TYPE_DIR)) != FILE_TYPE_DIR) {
total_dir_size += mid_content[i].file_size;
}
}
pthread_mutex_unlock(&mutex_mid);
free(path);
free(ui_btm_right_block);
path = getcwd(NULL, 0);
struct statvfs fs;
statvfs(path, &fs);
float disk_size_free = fs.f_bsize * fs.f_bavail;
float parsed_number[2] = { 0 };
char size_index[2] = { 0 };
if (total_dir_size > 1) {
size_index[0] = -1;
while (total_dir_size > 1 && size_index[0] < size_unit_count) {
parsed_number[0]=total_dir_size;
size_index[0]++;
total_dir_size /= 1024;
}
} else {
size_index[0] = 0;
parsed_number[0] = 0;
}
if (disk_size_free > 1) {
size_index[1] = -1;
while (disk_size_free > 1 && size_index[1] < size_unit_count) {
parsed_number[1]=disk_size_free;
size_index[1]++;
disk_size_free /= 1024;
}
} else {
size_index[1] = 0;
}
if (size_index[0] > 0 && size_index[1] > 0) {
ui_btm_right_block_size = snprintf(NULL, 0, "%0.2lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
ui_btm_right_block = malloc(ui_btm_right_block_size);
sprintf(ui_btm_right_block, "%0.2lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
} else if (size_index[0] <= 0 && size_index[1] > 0) {
ui_btm_right_block_size = snprintf(NULL, 0, "%0.0lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
ui_btm_right_block = malloc(ui_btm_right_block_size);
sprintf(ui_btm_right_block, "%0.0lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
} else if (size_index[0] > 0 && size_index[1] <= 0) {
ui_btm_right_block_size = snprintf(NULL, 0, "%0.2lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
ui_btm_right_block = malloc(ui_btm_right_block_size);
sprintf(ui_btm_right_block, "%0.2lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
} else {
ui_btm_right_block_size = snprintf(NULL, 0, "%0.0lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
ui_btm_right_block = malloc(ui_btm_right_block_size);
sprintf(ui_btm_right_block, "%0.0lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
}
/*}}}*/
}
if (buffer_width != terminal_width) {
buffer_width = terminal_width;
free(btm_buffer);
int buffer_width = terminal_width;
btm_buffer = malloc(buffer_width);
memset(btm_buffer, ' ', buffer_width);
memset(btm_buffer, ' ', buffer_width/2);
}
memset(btm_buffer + (buffer_width/2), ' ', buffer_width/2);
btm_buffer[buffer_width] = '\0';
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
btm_buffer[0] = (S_ISDIR(mid_content[selected_file_current].permissions)) ? 'd' : '-';
btm_buffer[1] = (mid_content[selected_file_current].permissions & S_IRUSR) ? 'r' : '-';
btm_buffer[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-';
@@ -264,58 +350,6 @@ void *thread_btm(){
btm_buffer[9] = (mid_content[selected_file_current].permissions & S_IXOTH) ? 'x' : '-';
char *path;
path=getcwd(NULL, 0);
struct statvfs fs;
statvfs(path, &fs);
float disk_size_free = fs.f_bsize * fs.f_bavail;
float parsed_number = 0;
int offset_back = buffer_width - strlen(ui_btm_text_storage_left);
strcpy(btm_buffer + offset_back, ui_btm_text_storage_left);
char *float_str = malloc(buffer_width / 4);
char size_index = -1;
pthread_mutex_lock(&mutex_mid);
unsigned long i;
unsigned long total_dir_size = 0;
for(i = 0; i < mid_file_count; i++) {
if (!(mid_content[i].file_type & (FILE_TYPE_DIR))) {
total_dir_size += mid_content[i].file_size;
}
}
pthread_mutex_unlock(&mutex_mid);
do {
parsed_number=disk_size_free;
disk_size_free /= 1024;
size_index++;
} while (disk_size_free > 1 && size_index < size_unit_count);
snprintf(float_str, 10, "%0.2lf", parsed_number);
btm_buffer[offset_back - 2] = size_unit[(unsigned)size_index];
offset_back -= strlen(float_str) + 2;
memcpy(btm_buffer + offset_back, float_str, strlen(float_str));
parsed_number = 0;
size_index = -1;
do {
parsed_number=total_dir_size;
total_dir_size /= 1024;
size_index++;
} while (total_dir_size > 1 && size_index < size_unit_count);
offset_back -= strlen(ui_btm_current_dir_size) + 5;
memcpy(btm_buffer + offset_back, ui_btm_current_dir_size, strlen(ui_btm_current_dir_size));
snprintf(float_str, 10, "%0.2lf", parsed_number);
btm_buffer[offset_back - 2] = size_unit[(unsigned)size_index];
offset_back -= strlen(float_str) + 2;
memcpy(btm_buffer + offset_back, float_str, strlen(float_str));
free(path);
pthread_mutex_unlock(&mutex_btm);
}