aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.c90
1 files changed, 31 insertions, 59 deletions
diff --git a/main.c b/main.c
index f698fea..67a2ad9 100644
--- a/main.c
+++ b/main.c
@@ -2,6 +2,7 @@
#include <dirent.h>
#include <limits.h>
#include <linux/limits.h>
+#include <magic.h>
#include <ncurses.h>
#include <stdint.h>
#include <stdio.h>
@@ -11,6 +12,7 @@
#include <sys/types.h>
#include <unistd.h>
+#include "dir.h"
#include "display.h"
#include "err.h"
#include "fm.h"
@@ -25,12 +27,7 @@ static void path_normalize(char *path)
{
if (path == NULL)
return;
-
- size_t len = strlen(path);
- while (len > 1 && path[len - 1] == '/') {
- path[len - 1] = '\0';
- len--;
- }
+ realpath(path, path);
}
int main(int argc, char **argv)
@@ -40,74 +37,49 @@ int main(int argc, char **argv)
version();
int ch;
+ file_list *list;
log_init();
- terminal *t = ncurses_init();
- stat *s = stat_init();
- stat_get_sysver(s);
- stat_get_diskinfo(s);
- stat_get_meminfo(s);
- log_write(LOG_INFO, "Terminal maxx = %d, maxy = %d", t->maxy, t->maxx);
-
- draw_stat_bar(t, s->sysver);
-
- int stat_w_h = 4;
+ terminal *term = ncurses_init();
- window *stat_w = wm_create_new_w(t, "stat", stat_w_h, t->maxx, 0, 0);
-
- fm_info *f = fm_init(t);
+ fm_info *info = fm_init(term);
if (argc == 2) {
- snprintf(f->cwd, sizeof(f->cwd), "%s", argv[1]);
- path_normalize(f->cwd);
+ snprintf(info->cwd, sizeof(info->cwd), "%s", argv[1]);
+ path_normalize(info->cwd);
} else {
- fm_getcwd(f);
+ fm_getcwd(info);
}
- log_write(LOG_INFO, "cwd = %s", f->cwd);
- fm_getdir(f, f->cur, f->cwd);
+ info->cur = fm_getdir(info->cur, info->cwd);
+ magic_init();
+ char next_path[PATH_MAX];
timeout(100);
- int i;
- int sw_y, sw_x;
while (1) {
- ch = getch();
- handling_keys(ch, t, f);
- stat_get_meminfo(s);
- stat_get_diskinfo(s);
- stat_get_cpuinfo(s);
- getmaxyx(stat_w->win, sw_y, sw_x);
- wclear(stat_w->win);
-
- wborder(stat_w->win, ' ', ' ', ' ', '-', ' ', ' ', '-', '-');
-
- stat_draw_cpu_bar(stat_w->win, sw_x, 0, 0, s);
- stat_print_cpu_info(stat_w->win, 0, sw_x, s);
- stat_draw_bar(stat_w->win, "Mem", sw_x, 1, 0,
- s->meminfo.mem_total, s->meminfo.mem_available);
- stat_print_info(stat_w->win, 1, sw_x, "Mem",
- s->meminfo.mem_total, s->meminfo.mem_available);
-
- stat_draw_bar(stat_w->win, "Disk", sw_x, 2, 0,
- s->diskinfo.disk_total,
- s->diskinfo.disk_available);
- stat_print_info(stat_w->win, 2, sw_x, "Disk",
- s->diskinfo.disk_total,
- s->diskinfo.disk_available);
-
- if (f->needs_redraw) {
- wclear(f->fm_l->win);
- i = 0;
- for (int j = f->top; j < f->bottom; j++) {
- fm_draw_entries(f, j, i);
- i++;
+ if (info->need_redraw) {
+ fm_draw_entries(info->windows[FM_PANE_LEFT], info->cur,
+ info->cursor, info->top, info->bottom);
+
+ if (!info->cur->items[info->cursor].is_dir) {
+ snprintf(next_path, sizeof(next_path), "%s/%s",
+ info->cwd,
+ info->cur->items[info->cursor].name);
+ fm_preview_file(info->windows[FM_PANE_RIGHT],
+ next_path);
}
- f->needs_redraw = 0;
+ wrefresh(info->windows[FM_PANE_RIGHT]->win);
+ wrefresh(info->windows[FM_PANE_LEFT]->win);
+ refresh();
}
- fm_draw_right_window(f);
- wm_refresh_all(t);
+ ch = getch();
+ handling_keys(ch, info);
}
+
+ magic_cleanup();
+ endwin();
+
return 0;
}