From ce6a75eb806715a23bdd42831f8bf0e15cc7b18b Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Tue, 18 Apr 2023 00:28:21 -0700 Subject: [PATCH] Converts the ncurses test from wchar_t to regular char. --- sbf-cpp/sbf.cpp | 78 ++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/sbf-cpp/sbf.cpp b/sbf-cpp/sbf.cpp index 3a641e4..c05c29c 100644 --- a/sbf-cpp/sbf.cpp +++ b/sbf-cpp/sbf.cpp @@ -36,46 +36,46 @@ int set_double_border(WINDOW* screen) { } int main(int argc, char* argv[]) { - // setlocale(LC_ALL, ""); - // char buffer[255] = {0}; - // WINDOW* pWindow = nullptr; - // // Load ncurses and initialize stdscr. - // initscr(); - // pWindow = stdscr; - // // Enable raw mode to give us direct access to extra keys. - // raw(); - // // Disable echoing characters as they are typed. - // noecho(); - // // Enable keypad characters. (function keys, arrow keys, and numpad keys.) - // keypad(pWindow, true); - // // Remove the delay when pressing esc. - // set_escdelay(0); + setlocale(LC_ALL, ""); + char buffer[255] = {0}; + WINDOW* pWindow = nullptr; + // Load ncurses and initialize stdscr. + initscr(); + pWindow = stdscr; + // Enable raw mode to give us direct access to extra keys. + raw(); + // Disable echoing characters as they are typed. + noecho(); + // Enable keypad characters. (function keys, arrow keys, and numpad keys.) + keypad(pWindow, true); + // Remove the delay when pressing esc. + set_escdelay(0); - // int key = KEY_RESIZE; - // while(key != KEY_ESCAPE) { - // if (key == KEY_RESIZE) { - // // Clear the screen. - // werase(pWindow); - // // Draw a box around the window with default chars. - // set_double_border(pWindow); - // // Display the event - // mvwaddwstr(pWindow, 2, 2, "Resized"); - // // Get the window width and height. - // int width; - // int height; - // getmaxyx(pWindow, height, width); - // // Display the width and height. - // swprintf(buffer, sizeof(buffer), "width: %i, height: %i", width, height); - // mvwaddwstr(pWindow, 1, 2, buffer); - // } else { - // // Display the keycode of the key that was pressed in hex and octal. - // swprintf(buffer, sizeof(buffer), "0x%04X %04o pressed", key, key); - // mvwaddwstr(pWindow,2, 2, buffer); - // } - // wrefresh(pWindow); - // key = wgetch(pWindow); - // } - // endwin(); + int key = KEY_RESIZE; + while(key != KEY_ESCAPE) { + if (key == KEY_RESIZE) { + // Clear the screen. + werase(pWindow); + // Draw a box around the window with default chars. + set_double_border(pWindow); + // Display the event + mvwaddstr(pWindow, 2, 2, "Resized"); + // Get the window width and height. + int width; + int height; + getmaxyx(pWindow, height, width); + // Display the width and height. + snprintf(buffer, sizeof(buffer), "width: %i, height: %i", width, height); + mvwaddstr(pWindow, 1, 2, buffer); + } else { + // Display the keycode of the key that was pressed in hex and octal. + snprintf(buffer, sizeof(buffer), "0x%04X %04o pressed", key, key); + mvwaddstr(pWindow,2, 2, buffer); + } + wrefresh(pWindow); + key = wgetch(pWindow); + } + endwin(); return 0; }