# HG changeset patch # User Markus Bröker # Date 1229187491 -3600 # Node ID 933d86c1ff714238c5017cac75bfb188d942b6b4 # Parent f3657061ec0073cca992c875edaf8c1793c3cdd1 namespace console added for console tools, password entry and other stuff committer: Markus Bröker diff --git a/db_bridge/console.cpp b/db_bridge/console.cpp new file mode 100644 --- /dev/null +++ b/db_bridge/console.cpp @@ -0,0 +1,32 @@ +#include + +int Console::getch () +{ + static int ch = -1, fd = 0; + struct termios neu, alt; + + fd = fileno (stdin); + tcgetattr (fd, &alt); + neu = alt; + neu.c_lflag &= ~(ICANON | ECHO); + tcsetattr (fd, TCSANOW, &neu); + ch = getchar (); + tcsetattr (fd, TCSANOW, &alt); + return ch; +} + +void Console::getpass (std::string & password) +{ + int i = 0; + int c; + char buffer[17]; + + while ((c = getch ()) != '\n' && i < 17) { + buffer[i++] = c; + std::cout << "*"; + } + buffer[i] = 0; + + password = std::string (buffer); + std::cout << std::endl; +} diff --git a/db_bridge/include/console.h b/db_bridge/include/console.h new file mode 100644 --- /dev/null +++ b/db_bridge/include/console.h @@ -0,0 +1,11 @@ +#ifndef CONSOLE_H +#define CONSOLE_H + +#include +#include + +namespace Console { + int getch (); + void getpass (std::string &); +}; +#endif