From e28423b4387e3000b1b7095b83ed32491f3fc135 Mon Sep 17 00:00:00 2001 From: anon Date: Tue, 10 Dec 2024 20:39:01 +0100 Subject: [PATCH] Added 'C_C++/ncurses_text_subwin_overflow.c' --- C_C++/ncurses_text_subwin_overflow.c | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 C_C++/ncurses_text_subwin_overflow.c diff --git a/C_C++/ncurses_text_subwin_overflow.c b/C_C++/ncurses_text_subwin_overflow.c new file mode 100644 index 0000000..0fa61c0 --- /dev/null +++ b/C_C++/ncurses_text_subwin_overflow.c @@ -0,0 +1,48 @@ +// @BAKE gcc $@ -o $*.out $(pkg-config --libs ncurses) +#include +#include + +const char *long_msg = "The dull BONG of metal against a face followed by a pained ‘NYAAAH!’ tell you all you need to know! As Tzah-Tzie tumbles onto the dock like a bag of groceries, you give the air her head previously occupied a good SMACK with your hand and send a heavy, metal barrel cover clattering to the floor!"; + +int main() { + WINDOW *mainwin, *subwin; + + // Initialize ncurses + initscr(); + noecho(); + cbreak(); + + // Create the main window + int height = 20, width = 40, starty = 2, startx = 4; + mainwin = newwin(height, width, starty, startx); + + refresh(); + + box(mainwin, 0, 0); // Add a border to the main window + mvwprintw(mainwin, 0, 1, "Main Window"); + + // Create a subwindow: narrow but tall + int sub_height = height - 4, sub_width = 15; + int sub_starty = starty + 2, sub_startx = startx + 2; + subwin = derwin(mainwin, sub_height, sub_width, 2, 2); + box(subwin, 0, 0); // Add a border to the subwindow + mvwprintw(subwin, 0, 1, "Subwin"); + + // Print the message into the subwindow + mvwprintw(subwin, 1, 1, "%s", long_msg); + + // Refresh both windows + wrefresh(mainwin); + wrefresh(subwin); + refresh(); + + // Wait for input before closing + getch(); + + // Clean up and end ncurses + delwin(subwin); + delwin(mainwin); + endwin(); + + return 0; +}