Exit program if window size is too small

This commit is contained in:
Night Kaly 2024-11-01 22:49:09 +00:00
parent 3d266f15d8
commit 4b16733d22
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM
2 changed files with 7 additions and 8 deletions

13
ccc.c
View file

@ -142,10 +142,8 @@ int main(int argc, char **argv)
getcwd(cwd, PATH_MAX); getcwd(cwd, PATH_MAX);
p_cwd = memalloc(PATH_MAX); p_cwd = memalloc(PATH_MAX);
p_cwd[0] = '\0'; p_cwd[0] = '\0';
get_window_size(&rows, &cols);
half_width = cols / 2 + WINDOW_OFFSET;
populate_files(cwd, 0, &files); populate_files(cwd, 0, &files);
handle_sigwinch();
if (to_open_file) { if (to_open_file) {
sel_file = arraylist_search(files, argv_cp, true); sel_file = arraylist_search(files, argv_cp, true);
@ -155,10 +153,7 @@ int main(int argc, char **argv)
int ch, ch2; int ch, ch2;
int run = 1; int run = 1;
while (run) { while (run) {
if (cols < 80 || rows < 24) {
cleanup();
die("ccc: Terminal size needs to be at least 80x24");
}
ch = read_key(); ch = read_key();
switch (ch) { switch (ch) {
/* quit */ /* quit */
@ -420,6 +415,10 @@ int main(int argc, char **argv)
void handle_sigwinch() void handle_sigwinch()
{ {
get_window_size(&rows, &cols); get_window_size(&rows, &cols);
if (cols < 80 || rows < 24) {
cleanup();
die("ccc: Terminal size needs to be at least 80x24");
}
half_width = cols / 2 + WINDOW_OFFSET; half_width = cols / 2 + WINDOW_OFFSET;
list_files(); list_files();
} }

View file

@ -19,7 +19,7 @@ In COLS:
0 will make them equal (at the center), 0 will make them equal (at the center),
15 will make files bigger 15 will make files bigger
-15 will make preview bigger */ -15 will make preview bigger */
#define WINDOW_OFFSET -65 #define WINDOW_OFFSET -30
/* Options */ /* Options */
#define SHOW_HIDDEN true /* show hidden files/dotfiles at startup */ #define SHOW_HIDDEN true /* show hidden files/dotfiles at startup */