From 5237204f02531957226cb5812a3ec1992995f398 Mon Sep 17 00:00:00 2001 From: anon Date: Sun, 10 Mar 2024 15:57:36 +0100 Subject: [PATCH] Added ncurses_resize_test.c --- ncurses_resize_test.c | 114 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 ncurses_resize_test.c diff --git a/ncurses_resize_test.c b/ncurses_resize_test.c new file mode 100644 index 0000000..e5872a3 --- /dev/null +++ b/ncurses_resize_test.c @@ -0,0 +1,114 @@ +#include +#include + +void handle_winch(int sig) +{ + endwin(); + refresh(); + clear(); +} +int main() { + initscr(); + cbreak(); + noecho(); + curs_set(0); + + signal(SIGWINCH, handle_winch); + + while(true){ + mvprintw(LINES-2, 0, "Hello, world! %d:%d\n", LINES, COLS); + refresh(); + } + + endwin(); + return 0; +} +//#include +//#include +// +//void sigwinch_handler(int sig) { +// // Tell ncurses to update its internal screen size data +// endwin(); +// refresh(); +//} +// +//int main() { +// // Initialize ncurses +// initscr(); +// cbreak(); +// noecho(); +// curs_set(0); +// +// // Register the SIGWINCH signal handler +// signal(SIGWINCH, sigwinch_handler); +// +// // Set the initial screen color and print a message +// start_color(); +// init_pair(1, COLOR_BLUE, COLOR_TRANSPARENT); +// bkgd(COLOR_PAIR(1)); +// printw("Hello, world!\n"); +// +// // Wait for user input +// refresh(); +// getch(); +// +// // Resize the screen +// endwin(); +// refresh(); +// int new_rows, new_cols; +// getmaxyx(stdscr, new_rows, new_cols); +// resizeterm(new_rows, new_cols); +// +// // Update the screen color and print another message +// init_pair(2, COLOR_RED, COLOR_TRANSPARENT); +// bkgd(COLOR_PAIR(2)); +// printw("Goodbye!\n"); +// +// // Wait for user input +// refresh(); +// getch(); +// +// // Clean up and exit +// endwin(); +// return 0; +//} +//#include +//#include +// +//void sigwinch_handler(int sig) { +// // Resize the terminal to the new size +// endwin(); +// refresh(); +// resize_term(LINES, COLS); +//} +// +//int main() { +// // Initialize ncurses +// initscr(); +// cbreak(); +// noecho(); +// +// // Register the SIGWINCH signal handler +// signal(SIGWINCH, sigwinch_handler); +// +// // Print the initial size of the screen +// printw("Initial screen size: %d rows, %d columns\n", LINES, COLS); +// +// // Wait for user input +// refresh(); +// getch(); +// +// // Resize the screen +// resize_term(40, 80); +// +// // Print the new size of the screen +// printw("New screen size: %d rows, %d columns\n", LINES, COLS); +// +// // Wait for user input +// refresh(); +// getch(); +// +// // Clean up and exit +// endwin(); +// return 0; +//}