From a7a41d5e8875b6a5e7a8ac23601987aaabedfe92 Mon Sep 17 00:00:00 2001 From: verdant Date: Mon, 27 Jul 2026 20:59:19 +0800 Subject: Fix -Wformat-truncation warning and refactor redraw logic --- main.c | 63 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/main.c b/main.c index e65b52a..0f48ced 100644 --- a/main.c +++ b/main.c @@ -63,37 +63,44 @@ int main(int argc, char **argv) timeout(100); while (1) { - 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); - } else { - snprintf(next_path, sizeof(next_path), "%s/%s", - info->cwd, - info->cur->items[info->cursor].name); - file_list *new_list = info->next; - new_list = fm_getdir(new_list, next_path); - if (new_list) { - info->next = new_list; - int right_height = - info->windows[FM_PANE_RIGHT] - ->height; - fm_draw_entries( - info->windows[FM_PANE_RIGHT], - info->next, -1, 0, right_height); - } + if (!info->need_redraw) + continue; + + fm_draw_entries(info->windows[FM_PANE_LEFT], info->cur, + info->cursor, info->top, info->bottom); + + if (!info->cur->items[info->cursor].is_dir) { + size_t len = snprintf( + next_path, sizeof(next_path), "%s/%s", info->cwd, + info->cur->items[info->cursor].name); + if (len >= sizeof(next_path)) { + die("Length of items error"); + } + fm_preview_file(info->windows[FM_PANE_RIGHT], + next_path); + } else { + size_t len = snprintf( + next_path, sizeof(next_path), "%s/%s", info->cwd, + info->cur->items[info->cursor].name); + + if (len >= sizeof(next_path)) { + die("Length of items error"); + } + file_list *new_list = info->next; + new_list = fm_getdir(new_list, next_path); + if (new_list) { + info->next = new_list; + int right_height = + info->windows[FM_PANE_RIGHT]->height; + fm_draw_entries(info->windows[FM_PANE_RIGHT], + info->next, -1, 0, + right_height); } - - wrefresh(info->windows[FM_PANE_RIGHT]->win); - wrefresh(info->windows[FM_PANE_LEFT]->win); } + wrefresh(info->windows[FM_PANE_RIGHT]->win); + wrefresh(info->windows[FM_PANE_LEFT]->win); + ch = getch(); handling_keys(ch, info); } -- cgit v1.2.3