aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorverdant <im@verdant.ee>2026-08-03 15:50:33 +0800
committerverdant <im@verdant.ee>2026-08-03 15:50:33 +0800
commitb1a3208e940f5fa5c4693c04ca2a423efbda2917 (patch)
tree19dd11491007d8862a9c56c487a86040fde6e68e
parent71518966c2910745830bf55539e78070a0057b13 (diff)
downloadsf-b1a3208e940f5fa5c4693c04ca2a423efbda2917.tar.gz
sf-b1a3208e940f5fa5c4693c04ca2a423efbda2917.zip
Refactor main loop to reduce unnecessary redraw operations
-rw-r--r--src/main.c62
1 files changed, 32 insertions, 30 deletions
diff --git a/src/main.c b/src/main.c
index c1b327a..f58d464 100644
--- a/src/main.c
+++ b/src/main.c
@@ -68,39 +68,41 @@ main(int argc, char **argv)
char next_path[PATH_MAX];
timeout(100);
while (1) {
- if (!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");
+ if (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) {
+ 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");
+ }
+
+ fm_preview_dir(info, next_path);
}
- 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");
- }
-
- fm_preview_dir(info, next_path);
- }
- draw_status_bar(term->windows[stat_bar_win_index], info->cwd,
- info->cur->items[info->cursor].permission);
-
- wrefresh(info->windows[FM_PANE_RIGHT]->win);
- wrefresh(info->windows[FM_PANE_LEFT]->win);
- wrefresh(term->windows[stat_bar_win_index]->win);
+ draw_status_bar(
+ term->windows[stat_bar_win_index], info->cwd,
+ info->cur->items[info->cursor].permission);
+ wrefresh(info->windows[FM_PANE_RIGHT]->win);
+ wrefresh(info->windows[FM_PANE_LEFT]->win);
+ wrefresh(term->windows[stat_bar_win_index]->win);
+ }
ch = getch();
handling_keys(ch, info);
}