diff --git a/db_bridge/console.cpp b/db_bridge/console.cpp --- a/db_bridge/console.cpp +++ b/db_bridge/console.cpp @@ -2,16 +2,29 @@ #include #ifdef WIN32 +#include #include + int Console::getch () { - return::getch (); + int pressed = 0; + int ch = -1; + + while (!pressed) { + if (kbhit ()) { + ch =::getch (); + pressed = 1; + } + Sleep (10); + } + return ch; } #else #include + int Console::getch () { - static int ch = -1, fd = 0; + int ch = -1, fd = 0; struct termios neu, alt; fd = fileno (stdin); @@ -31,12 +44,17 @@ int c; char buffer[17]; - while ((c = Console::getch ()) != '\n' && i < 17) { - buffer[i++] = c; - std::cout << "\b*"; + while (((c = Console::getch ()) != '\n') && i < 17) { + if (c != BS) { + buffer[i++] = c; + std::cout << "*"; + } else if (i > 0) { + i--; + std::cout << "\b \b"; + } } buffer[i] = 0; + std::cout << std::endl; password = std::string (buffer); - std::cout << std::endl; }