diff options
| author | verdant <im@verdant.ee> | 2026-07-22 22:49:03 +0800 |
|---|---|---|
| committer | verdant <im@verdant.ee> | 2026-07-22 22:49:03 +0800 |
| commit | 85be5dc9852c403ec4f3e7e6f81023cbbe51f755 (patch) | |
| tree | 1b02a02d741ad17da6af6f1c7e6c54cd74788305 /main.c | |
| parent | 69edb73d08534216120324328b0b8ffc8e573400 (diff) | |
| download | sf-85be5dc9852c403ec4f3e7e6f81023cbbe51f755.tar.gz sf-85be5dc9852c403ec4f3e7e6f81023cbbe51f755.zip | |
Reformat main.c and remove redundant comments
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 228 |
1 files changed, 80 insertions, 148 deletions
@@ -13,158 +13,90 @@ #include "display.h" #include "err.h" +#include "fm.h" +#include "keys.h" #include "log.h" #include "mem.h" #include "stat.h" #include "version.h" #include "wm.h" -/* #define PROC_PATH_VERSION "/proc/version" */ -/* #define PROC_PATH_MEMINFO "/proc/meminfo" */ - -/* typedef struct { */ -/* WINDOW* w; */ -/* char name[32]; */ -/* int starty; */ -/* int startx; */ -/* int height; */ -/* int width; */ -/* } win_info; */ - -/* int w_count = 0; */ - -/* int find_w_by_name(const char* name) { */ -/* for (int i = 0; i < w_count; i++) { */ -/* if (strcmp(windows[i].name, name) != 0) continue; */ -/* return i; */ -/* } */ - -/* return -1; */ -/* } */ -/* void draw_bar(WINDOW* w, const char* label, int maxx, int y, int x, */ -/* unsigned long total, unsigned long ava) { */ -/* int ava_to_draw_x = maxx - STAT_INFO_WIDTH - BAR_LABEL_WIDTH; */ -/* int total_hashes = get_bar_ticks(ava_to_draw_x, total, ava); */ -/* char hashes[2048] = {0}; */ - -/* init_pair(COLOR_PAIR_PROGRESS, COLOR_GREEN, COLOR_BLACK); */ - -/* if (total_hashes > ava_to_draw_x) total_hashes = ava_to_draw_x; */ -/* memset(hashes, '#', total_hashes); */ -/* hashes[total_hashes] = '\0'; */ - -/* mvwprintw(w, y, x, "%-*s [", 4, label); */ -/* wprintw_colorful(w, COLOR_PAIR_PROGRESS, "%.*s", total_hashes, hashes); - */ - -/* int remaining_spaces = ava_to_draw_x - total_hashes; */ -/* if (remaining_spaces > 0) { */ -/* wprintw(w, "%*s", remaining_spaces, ""); */ -/* } */ - -/* waddch(w, ']'); */ - -/* wrefresh(w); */ -/* } */ - -/* WINDOW* fm_w_init(WINDOW* root_win, int maxy, int maxx) { */ -/* int stat_w_w, stat_w_h, fm_w, fm_h, fm_l_startx, fm_starty, fm_r_startx; - */ - -/* int i = find_w_by_name("stat"); */ -/* if (i == -1) { */ -/* die("Cannot find window \"stat\""); */ -/* } */ -/* stat_w_w = windows[i].width; */ -/* stat_w_h = windows[i].height; */ - -/* fm_w = maxx / 2; */ -/* fm_h = maxy - stat_w_h; */ -/* fm_starty = stat_w_h - STAT_BAR_HEIGHT; */ - -/* fm_l_startx = 0; */ -/* fm_r_startx = maxx / 2; */ -/* WINDOW* fm_l = derwin(root_win, fm_h, fm_w, fm_starty, 0); */ -/* return fm_l; */ -/* } */ - -/* void fm_load_dir(const char* path) { */ -/* DIR* dir = opendir(path); */ -/* log_write(LOG_INFO, "fm_load_dir: dir = %s", dir); */ -/* struct dirent* entry; */ - -/* if (!dir) die("Cannot open dir"); */ - -/* while ((entry = readdir(dir)) != NULL) { */ -/* log_write(LOG_INFO, "%s", entry->d_name); */ -/* } */ - -/* closedir(dir); */ -/* } */ - -/* char* get_cwd() { */ -/* static char cwd[PATH_MAX]; */ -/* if (getcwd(cwd, sizeof(cwd)) != NULL) { */ -/* return cwd; */ -/* } */ - -/* die("Cannot get current working directory"); */ -/* return NULL; */ -/* } */ - -int main() { - /* char* cwd; */ - int ch; - log_init(); - - terminal* t = ncurses_init(); - stat* s = stat_init(); - stat_get_sysver(s); - stat_get_diskinfo(s); - stat_get_meminfo(s); - stat_get_cpuinfo(s); - log_write(LOG_INFO, "Terminal maxx = %d, maxy = %d", t->maxy, t->maxx); - - draw_stat_bar(t, s->sysver); - - keypad(ROOT_WIN, TRUE); - - int stat_w_h = t->maxy / 8 < 4 ? 4 : t->maxy / 8; - - window* stat_w = wm_create_new_w(t, "stat", stat_w_h, t->maxx, 0, 0); - - /* cwd = get_cwd(); */ - - timeout(100); - while ((ch = getch()) != 'q') { - stat_get_meminfo(s); - stat_get_diskinfo(s); - - int sw_y, sw_x; - getmaxyx(stat_w->win, sw_y, sw_x); - wclear(stat_w->win); - wborder(stat_w->win, ' ', ' ', ' ', '-', ' ', ' ', '-', '-'); - stat_calc_cpuocc(s); - 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 (ch == KEY_RESIZE) { - wclear(t->windows[wm_fd_w_by_name(t, "stat_bar")]->win); - getmaxyx(stdscr, t->maxy, t->maxx); - draw_stat_bar(t, s->sysver); - } - - wm_refresh_all(t); - } - - endwin(); - return 0; +int main(int argc, char **argv) +{ + int ch; + 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); + + keypad(ROOT_WIN, TRUE); + + /* int stat_w_h = t->maxy / 8 < 4 ? 4 : t->maxy / 8; */ + int stat_w_h = 4; + + window *stat_w = wm_create_new_w(t, "stat", stat_w_h, t->maxx, 0, 0); + + fm_info *f = fm_init(t); + + if (argc == 2) { + snprintf(f->cwd, sizeof(f->cwd), "%s", argv[1]); + log_write(LOG_INFO, "f->cwd = %s", f->cwd); + log_write(LOG_INFO, "argv[1] = %s", argv[1]); + } else { + fm_getcwd(f); + } + + log_write(LOG_INFO, "cwd = %s", f->cwd); + fm_getdir(f, f->cur, f->cwd); + + timeout(100); + int i; + int sw_y, sw_x; + while (1) { + ch = getch(); + handing_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 (ch == KEY_RESIZE) { + wclear(t->windows[wm_fd_w_by_name(t, "stat_bar")]->win); + wclear(t->windows[wm_fd_w_by_name(t, "fm_l")]->win); + getmaxyx(stdscr, t->maxy, t->maxx); + draw_stat_bar(t, s->sysver); + /* wborder(f->fm_l->win, ' ', ACS_VLINE, ' ', ' ', ' ', + */ + /* ' ', ' ', ' '); */ + } + + for (i = 0; i < f->cur->count; i++) { + fm_draw_entries(f, i); + } + wm_refresh_all(t); + } + + return 0; } |
