Handle sigwinch

This commit is contained in:
Night Kaly 2024-11-01 22:42:11 +00:00
parent 366fd6473e
commit 3d266f15d8
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM

18
ccc.c
View file

@ -21,6 +21,7 @@
#include "util.h" #include "util.h"
/* functions' definitions */ /* functions' definitions */
void handle_sigwinch();
void cleanup(); void cleanup();
void show_help(); void show_help();
int read_key(); int read_key();
@ -108,6 +109,16 @@ int main(int argc, char **argv)
if (!isatty(STDIN_FILENO)) if (!isatty(STDIN_FILENO))
die("ccc: No tty detected. ccc requires an interactive shell to run.\n"); 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, /* initialize screen, don't print special chars,
* make ctrl + c work, don't show cursor * make ctrl + c work, don't show cursor
* enable arrow keys */ * enable arrow keys */
@ -406,6 +417,13 @@ int main(int argc, char **argv)
return 0; return 0;
} }
void handle_sigwinch()
{
get_window_size(&rows, &cols);
half_width = cols / 2 + WINDOW_OFFSET;
list_files();
}
void cleanup() void cleanup()
{ {
if (argv_cp != NULL) if (argv_cp != NULL)