mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 18:30:15 -04:00
now printing left storage & related refactoring
This commit is contained in:
31
threading.c
31
threading.c
@@ -6,7 +6,9 @@
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#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);
|
||||
|
Reference in New Issue
Block a user