# HG changeset patch # User Markus Bröker # Date 1229187494 -3600 # Node ID 403742321c659b24155548052dae9711da001fdb # Parent 5fec678f931b3c2958457deba082b1c7dab20dfc console functions work fine under linux and not under windows committer: Markus Bröker 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; } diff --git a/db_bridge/include/console.h b/db_bridge/include/console.h --- a/db_bridge/include/console.h +++ b/db_bridge/include/console.h @@ -1,6 +1,12 @@ #ifndef CONSOLE_H #define CONSOLE_H +#ifdef WIN32 +#define BS 127 +#else +#define BS 127 +#endif + #include namespace Console {