2020-12-06 17:57:30 (UTC-03:00)
Marcel Rodrigues <marcelgmr@gmail.com>
term: get screen size
diff --git a/seqt.c b/seqt.c index 70b181d..17b3a8c 100644 --- a/seqt.c +++ b/seqt.c @@ -6,6 +6,7 @@ int ntracks; char map[MAPSIZE][RECSIZE]; unsigned char matrix[MAXINDEX][MAXTRACK][MAXVOICE]; +struct winsize term_size; void print_blank() @@ -114,7 +115,8 @@ main(int argc, char *argv[]) return 1; } fclose(fin); - setup_terminal(&term_prev); + setup_terminal(&term_prev, &term_size); + /* printf("%hux%hu\n", term_size.ws_col, term_size.ws_row); */ print_tracks(0, 10, 0, 3); running = 1; while (running) { diff --git a/seqt.h b/seqt.h index b02c796..2fe099c 100644 --- a/seqt.h +++ b/seqt.h @@ -2,6 +2,8 @@ #define SEQT_H #include <stdio.h> +#include <fcntl.h> +#include <sys/ioctl.h> #include <termios.h> /* ============================= Matrix ============================= */ @@ -54,7 +56,8 @@ int save_txt(FILE *fp); /* ============================ terminal =======]==================== */ -void setup_terminal(struct termios *term_prev); +extern struct winsize term_size; +void setup_terminal(struct termios *term_prev, struct winsize *term_size); void restore_terminal(struct termios *term_prev); /* ====================[=====+===== =====+=====]==================== */ diff --git a/term.c b/term.c index ba14605..7d573ed 100644 --- a/term.c +++ b/term.c @@ -1,7 +1,7 @@ #include "seqt.h" void -setup_terminal(struct termios *term_prev) +setup_terminal(struct termios *term_prev, struct winsize *term_size) { struct termios term_raw; @@ -13,6 +13,8 @@ setup_terminal(struct termios *term_prev) term_raw.c_cc[VMIN] = 1; term_raw.c_cc[VTIME] = 0; tcsetattr(0, TCSAFLUSH, &term_raw); + /* get terminal size */ + ioctl(0, TIOCGWINSZ, term_size); } void