add cmd color
This commit is contained in:
parent
2c3461b855
commit
4cc2b527d6
@ -1,6 +1,7 @@
|
||||
#include "gameske_funkce.h"
|
||||
#include <curses.h>
|
||||
#include <menu.h>
|
||||
#include <ncurses.h>
|
||||
#include <unistd.h>
|
||||
#include <clocale>
|
||||
#include <cstddef>
|
||||
@ -98,38 +99,60 @@ void print_in_middle(WINDOW* win, int starty, int startx, int width,
|
||||
|
||||
std::string spawncmd() {
|
||||
char cmd[100] = {0};
|
||||
int pos = 0;
|
||||
int ch;
|
||||
|
||||
// Create command window
|
||||
WINDOW* cmd_win = newwin(3, 40, LINES - 3, 0);
|
||||
if (cmd_win == NULL) {
|
||||
if (cmd_win == NULL)
|
||||
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
|
||||
// Disable automatic echo, we'll handle it manually
|
||||
noecho();
|
||||
curs_set(1);
|
||||
|
||||
wrefresh(cmd_win);
|
||||
|
||||
// Get input with echo enabled
|
||||
wgetnstr(cmd_win, cmd, 99);
|
||||
wattron(cmd_win, COLOR_PAIR(COLOR_CYAN));
|
||||
|
||||
// Display what was entered
|
||||
mvprintw(LINES - 2, 0, "You Entered: %s", cmd);
|
||||
refresh();
|
||||
// Get input character by character
|
||||
while (pos < 99) {
|
||||
ch = wgetch(cmd_win);
|
||||
|
||||
// Disable echo and hide cursor when done
|
||||
noecho();
|
||||
if (ch == '\n' || ch == KEY_ENTER) {
|
||||
// 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);
|
||||
|
||||
napms(5000);
|
||||
wclear(cmd_win);
|
||||
wrefresh(cmd_win);
|
||||
delwin(cmd_win);
|
||||
return std::string(cmd);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user