From 37624e487833793b4fc6869500a968a74a810f81 Mon Sep 17 00:00:00 2001 From: PoliEcho Date: Mon, 14 Apr 2025 12:17:44 +0200 Subject: [PATCH] add more functions --- src/gameske_funkce.cpp | 32 +++++++++++++++++++++++++++++++- src/gameske_funkce.h | 4 +++- src/menu.cpp | 5 +++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/gameske_funkce.cpp b/src/gameske_funkce.cpp index 7348cd1..02321da 100644 --- a/src/gameske_funkce.cpp +++ b/src/gameske_funkce.cpp @@ -1,5 +1,6 @@ #include "gameske_funkce.h" #include +#include #include #include #include @@ -91,4 +92,33 @@ void print_in_middle(WINDOW* win, int starty, int startx, int width, mvwprintw(win, y, x, "%s", string); wattroff(win, color); refresh(); -} \ No newline at end of file +} + +void spawncmd() { + // Use a fixed-size array instead of dynamic allocation + char cmd[100] = {0}; // Initialize to prevent undefined behavior + + // Create command window with error checking + WINDOW* cmd_win = newwin(3, 40, LINES - 3, 0); + if (cmd_win == NULL) { + // Handle window creation failure + return; + } + + keypad(cmd_win, TRUE); + box(cmd_win, 0, 0); + mvwprintw(cmd_win, 1, 1, "Command: "); + wrefresh(cmd_win); + + // Use correct size (99 to leave room for null terminator) + wgetnstr(cmd_win, cmd, 99); + + mvprintw(LINES - 2, 0, "You Entered: %s", cmd); + refresh(); // Refresh the standard screen + + // Consider using a more interactive approach than sleep + napms(5000); // ncurses alternative to sleep + + // Clean up resources + delwin(cmd_win); +} diff --git a/src/gameske_funkce.h b/src/gameske_funkce.h index bf44cd6..5cbeef0 100644 --- a/src/gameske_funkce.h +++ b/src/gameske_funkce.h @@ -6,4 +6,6 @@ size_t spawn_menu(uint16_t begin_y, uint16_t begin_x, const char** choices, size_t n_choices); void print_in_middle(WINDOW* win, int starty, int startx, int width, - char* string, chtype color); \ No newline at end of file + char* string, chtype color); + +void spawncmd(); \ No newline at end of file diff --git a/src/menu.cpp b/src/menu.cpp index f969bd1..704c633 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -69,10 +69,11 @@ void menu() { menu_driver(my_menu, REQ_UP_ITEM); break; case 10: - mvprintw(LINES - 1, 0, "%lu", - spawn_menu(15, 45, choices2, ARRAY_SIZE(choices2))); + refresh(); break; + case ':': + spawncmd(); } wrefresh(my_menu_win); }