add cmd color

This commit is contained in:
PoliEcho 2025-04-14 12:41:23 +02:00
parent 2c3461b855
commit 4cc2b527d6

View File

@ -1,6 +1,7 @@
#include "gameske_funkce.h" #include "gameske_funkce.h"
#include <curses.h> #include <curses.h>
#include <menu.h> #include <menu.h>
#include <ncurses.h>
#include <unistd.h> #include <unistd.h>
#include <clocale> #include <clocale>
#include <cstddef> #include <cstddef>
@ -98,38 +99,60 @@ void print_in_middle(WINDOW* win, int starty, int startx, int width,
std::string spawncmd() { std::string spawncmd() {
char cmd[100] = {0}; char cmd[100] = {0};
int pos = 0;
int ch;
// Create command window
WINDOW* cmd_win = newwin(3, 40, LINES - 3, 0); WINDOW* cmd_win = newwin(3, 40, LINES - 3, 0);
if (cmd_win == NULL) { if (cmd_win == NULL)
return ""; return "";
}
// Setup window
keypad(cmd_win, TRUE); keypad(cmd_win, TRUE);
box(cmd_win, 0, 0); box(cmd_win, 0, 0);
mvwprintw(cmd_win, 1, 1, "Command: "); mvwprintw(cmd_win, 1, 1, "Command: ");
// Explicitly enable echo // Disable automatic echo, we'll handle it manually
echo(); noecho();
// Make cursor visible during input
curs_set(1); curs_set(1);
wrefresh(cmd_win); wrefresh(cmd_win);
// Get input with echo enabled wattron(cmd_win, COLOR_PAIR(COLOR_CYAN));
wgetnstr(cmd_win, cmd, 99);
// Display what was entered // Get input character by character
mvprintw(LINES - 2, 0, "You Entered: %s", cmd); while (pos < 99) {
refresh(); ch = wgetch(cmd_win);
// Disable echo and hide cursor when done if (ch == '\n' || ch == KEY_ENTER) {
noecho(); // Enter key pressed, end input
break;
} else if (ch == KEY_BACKSPACE || ch == 127) {
// Backspace key
if (pos > 0) {
pos--;
// Move cursor back and erase the character
wmove(cmd_win, 1, 10 + pos);
waddch(cmd_win, ' ');
wmove(cmd_win, 1, 10 + pos);
}
} else if (ch == KEY_DC) {
// Delete key - not implemented in this simple example
} else if (isprint(ch)) {
// Printable character
cmd[pos] = ch;
mvwaddch(cmd_win, 1, 10 + pos, ch); // Echo the character
pos++;
}
wrefresh(cmd_win);
}
wattroff(cmd_win, COLOR_PAIR(COLOR_CYAN));
cmd[pos] = '\0'; // Ensure null termination
// Restore echo state as needed
echo();
curs_set(0); curs_set(0);
napms(5000); wclear(cmd_win);
wrefresh(cmd_win);
delwin(cmd_win); delwin(cmd_win);
return std::string(cmd); return std::string(cmd);
} }