db_bridge/console.cpp
changeset 19 933d86c1ff71
child 20 5fec678f931b
equal deleted inserted replaced
18:f3657061ec00 19:933d86c1ff71
       
     1 #include <console.h>
       
     2 
       
     3 int Console::getch ()
       
     4 {
       
     5     static int ch = -1, fd = 0;
       
     6     struct termios neu, alt;
       
     7 
       
     8     fd = fileno (stdin);
       
     9     tcgetattr (fd, &alt);
       
    10     neu = alt;
       
    11     neu.c_lflag &= ~(ICANON | ECHO);
       
    12     tcsetattr (fd, TCSANOW, &neu);
       
    13     ch = getchar ();
       
    14     tcsetattr (fd, TCSANOW, &alt);
       
    15     return ch;
       
    16 }
       
    17 
       
    18 void Console::getpass (std::string & password)
       
    19 {
       
    20     int i = 0;
       
    21     int c;
       
    22     char buffer[17];
       
    23 
       
    24     while ((c = getch ()) != '\n' && i < 17) {
       
    25         buffer[i++] = c;
       
    26         std::cout << "*";
       
    27     }
       
    28     buffer[i] = 0;
       
    29 
       
    30     password = std::string (buffer);
       
    31     std::cout << std::endl;
       
    32 }