From 3d266f15d847523c9f8ec96815665a9ba4e0ba01 Mon Sep 17 00:00:00 2001 From: night0721 Date: Fri, 1 Nov 2024 22:42:11 +0000 Subject: [PATCH] Handle sigwinch --- ccc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ccc.c b/ccc.c index c3be5a9..626995e 100644 --- a/ccc.c +++ b/ccc.c @@ -21,6 +21,7 @@ #include "util.h" /* functions' definitions */ +void handle_sigwinch(); void cleanup(); void show_help(); int read_key(); @@ -108,6 +109,16 @@ int main(int argc, char **argv) if (!isatty(STDIN_FILENO)) die("ccc: No tty detected. ccc requires an interactive shell to run.\n"); + struct sigaction sa; + sa.sa_handler = handle_sigwinch; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + + if (sigaction(SIGWINCH, &sa, NULL) == -1) { + perror("sigaction"); + exit(1); + } + /* initialize screen, don't print special chars, * make ctrl + c work, don't show cursor * enable arrow keys */ @@ -406,6 +417,13 @@ int main(int argc, char **argv) return 0; } +void handle_sigwinch() +{ + get_window_size(&rows, &cols); + half_width = cols / 2 + WINDOW_OFFSET; + list_files(); +} + void cleanup() { if (argv_cp != NULL)