diff --git a/config.h b/config.h index 0e35272..6110ad6 100644 --- a/config.h +++ b/config.h @@ -1,10 +1,12 @@ +#define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */ + +/* {{{ */ #ifndef CONFIG_GUARD #define CONFIG_GUARD #include "defines.h" #include "sorting.h" #include "interactions.h" - -#define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */ +/* }}} */ static const mimetype mimetype_default_cmd[] = { /* mimetype shell command @@ -93,9 +95,17 @@ static const binding key_binding[] = { { "a", toggle_hidden_files, NULL, "toggle hidden files" }, { "\x7F", toggle_hidden_files, NULL, "toggle hidden files" }, /* backspace key */ }; + +static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this defines the maximum size unit, deleting everything except B results in all sizes being displayed in byte */ + +static const char ui_btm_text_storage_left[] = "total free"; +static const char ui_btm_current_dir_size[] = "sum of dir"; + +/* {{{ */ static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding); static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype); static const unsigned long file_extension_default_count = sizeof(file_extension_default_cmd) / sizeof(extension); +static const char size_unit_count = (sizeof(size_unit) / sizeof(size_unit[0])) - 1; #else static const mimetype mimetype_default_cmd[]; static const extension file_extension_default_cmd[]; @@ -103,5 +113,7 @@ static const binding key_binding[]; static const unsigned long binding_count; static const unsigned long mimetype_default_count; static const unsigned long file_extension_default_count; +static const char size_unit[]; +static const char size_unit_count; #endif - +/* }}} */ diff --git a/dir.c b/dir.c index 2342e24..757f859 100644 --- a/dir.c +++ b/dir.c @@ -12,6 +12,8 @@ #include "config.h" +extern file *mid_content; +extern unsigned long mid_file_count; extern unsigned int settings; extern unsigned int file_modifiers; extern unsigned int color_count; @@ -160,7 +162,6 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file float printed_size = 0; char size_char = ' '; char is_selected = 0; - static const char sizes[6] = { 'B', 'K', 'M', 'G', 'T', 'P' }; unsigned long offset_vertical = 0; unsigned long offset_back = 0; @@ -229,16 +230,15 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file if (print_info) { file_size = dir_content[i].file_size; - char size_index = 0; - while (file_size > 1) { + char size_index = -1; + + do { printed_size=file_size; file_size /= 1024; size_index++; - if (size_index >= 6) { - break; - } - } - size_char = sizes[size_index-1]; + } while (file_size > 1 && size_index < size_unit_count); + size_char = size_unit[(unsigned)size_index]; + if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) { offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[i].file_size) + 1); } else if (size_char =='B') { diff --git a/threading.c b/threading.c index bc57770..f295186 100644 --- a/threading.c +++ b/threading.c @@ -6,7 +6,9 @@ #include #include #include +#include +#include "config.h" #include "dir.h" #include "file_previews.h" @@ -246,7 +248,8 @@ void *thread_btm(){ free(btm_buffer); int buffer_width = terminal_width; btm_buffer = malloc(buffer_width); - memset(btm_buffer, 0, buffer_width); + memset(btm_buffer, ' ', buffer_width); + btm_buffer[buffer_width] = '\0'; 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' : '-'; @@ -259,6 +262,32 @@ 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; + + 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); + + memcpy(btm_buffer + (offset_back - strlen(float_str) - 1), float_str, strlen(float_str)); + btm_buffer[offset_back - 2] = size_unit[(unsigned)size_index]; + + pthread_mutex_unlock(&mutex_btm); } pthread_exit(0);