ui: fs file list (not finished)

This commit is contained in:
2026-01-06 14:49:37 +02:00
parent 9b44285c56
commit cb79978cdf
10 changed files with 250 additions and 35 deletions
+5 -33
View File
@@ -1,6 +1,7 @@
#include "file_list.h"
#include "../../file_processor.h"
#include "../app.h"
#include "../../fs.h"
#include "progress_bar.h"
#include <ncurses.h>
#include <stdbool.h>
@@ -12,7 +13,6 @@
#include <unistd.h>
void reset_file_list(ui_file_list_t *fl_ui);
void size_to_text(size_t size, char *text);
void file_list_cb(callback_args_t *args) {
app_t *app = args->app;
@@ -79,14 +79,14 @@ void reset_file_list(ui_file_list_t *fl_ui) {
void draw_file_list(ui_file_list_t *fl_ui) {
int32_t sz_y, sz_x;
int32_t p_y, p_x;
getmaxyx(*(fl_ui->w.parent_win), sz_y, sz_x);
int32_t sz_y_f = sz_y - 2; // factual size (without box)
WINDOW *win = *(fl_ui->w.parent_win);
getmaxyx(win, sz_y, sz_x);
int32_t sz_y_f = sz_y - 2; // actual size (without box)
p_y = 1;
p_x = 1;
fl_item_t *el = *(fl_ui->start);
fl_item_t *active_el = *(fl_ui->start);
int32_t cur_el_idx = 0;
WINDOW *win = *(fl_ui->w.parent_win);
curs_set(0);
if (fl_ui->activate_last) {
@@ -144,37 +144,9 @@ void draw_file_list(ui_file_list_t *fl_ui) {
char size_text[64];
size_to_text(active_el->size, size_text);
mvwprintw(i_win, p_y++, p_x, "Size: %s", size_text);
mvwprintw(i_win, p_y++, p_x, "Owner: %s", active_el->owner);
mvwprintw(i_win, p_y++, p_x, "Description: ");
print_multiline_text(i_win, active_el->description, sz_x, p_y, p_x, 0);
}
#define BYTES_IN_GB 1073741824
#define BYTES_IN_MB 1048576
#define BYTES_IN_KB 1024
void size_to_text(size_t size, char *text) {
size_t kb = 0;
size_t mb = 0;
size_t gb = 0;
gb = size / BYTES_IN_GB;
mb = size / BYTES_IN_MB;
kb = size / BYTES_IN_KB;
if (gb > 0) {
size = size % BYTES_IN_GB;
mb = size / BYTES_IN_MB;
sprintf(text, "%zu,%zu GB", gb, mb);
} else if (mb > 0) {
size = size % BYTES_IN_MB;
kb = size / BYTES_IN_KB;
sprintf(text, "%zu,%zu MB", mb, kb);
} else if (kb > 0) {
size = size % BYTES_IN_KB;
sprintf(text, "%zu,%zu KB", kb, size);
} else {
sprintf(text, "%zu B", size);
}
}