From f232404480641d2aa46de8de183a3fdc31e75149 Mon Sep 17 00:00:00 2001 From: PoliEcho Date: Mon, 14 Apr 2025 12:21:16 +0200 Subject: [PATCH] add cmd --- src/gameske_funkce.cpp | 33 ++++++++++++++++++++++----------- src/gameske_funkce.h | 3 ++- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/gameske_funkce.cpp b/src/gameske_funkce.cpp index 02321da..c345d74 100644 --- a/src/gameske_funkce.cpp +++ b/src/gameske_funkce.cpp @@ -1,10 +1,12 @@ #include "gameske_funkce.h" +#include #include #include #include #include #include #include +#include size_t spawn_menu(uint16_t begin_y, uint16_t begin_x, const char** choices, size_t n_choices) { @@ -94,31 +96,40 @@ void print_in_middle(WINDOW* win, int starty, int startx, int width, refresh(); } -void spawncmd() { - // Use a fixed-size array instead of dynamic allocation - char cmd[100] = {0}; // Initialize to prevent undefined behavior +std::string spawncmd() { + char cmd[100] = {0}; - // Create command window with error checking + // Create command window WINDOW* cmd_win = newwin(3, 40, LINES - 3, 0); if (cmd_win == NULL) { - // Handle window creation failure - return; + return ""; } + // Setup window keypad(cmd_win, TRUE); box(cmd_win, 0, 0); mvwprintw(cmd_win, 1, 1, "Command: "); + + // Explicitly enable echo + echo(); + + // Make cursor visible during input + curs_set(1); + wrefresh(cmd_win); - // Use correct size (99 to leave room for null terminator) + // Get input with echo enabled wgetnstr(cmd_win, cmd, 99); + // Display what was entered mvprintw(LINES - 2, 0, "You Entered: %s", cmd); - refresh(); // Refresh the standard screen + refresh(); - // Consider using a more interactive approach than sleep - napms(5000); // ncurses alternative to sleep + // Disable echo and hide cursor when done + noecho(); + curs_set(0); - // Clean up resources + napms(5000); delwin(cmd_win); + return std::string(cmd); } diff --git a/src/gameske_funkce.h b/src/gameske_funkce.h index 5cbeef0..453a27e 100644 --- a/src/gameske_funkce.h +++ b/src/gameske_funkce.h @@ -1,4 +1,5 @@ #include +#include #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) @@ -8,4 +9,4 @@ size_t spawn_menu(uint16_t begin_y, uint16_t begin_x, const char** choices, void print_in_middle(WINDOW* win, int starty, int startx, int width, char* string, chtype color); -void spawncmd(); \ No newline at end of file +std::string spawncmd(); \ No newline at end of file