db_bridge/console.cpp
changeset 20 5fec678f931b
parent 19 933d86c1ff71
child 21 403742321c65
equal deleted inserted replaced
19:933d86c1ff71 20:5fec678f931b
     1 #include <console.h>
     1 #include <console.h>
       
     2 #include <cstdio>
     2 
     3 
       
     4 #ifdef WIN32
       
     5 #include <conio.h>
       
     6 int Console::getch ()
       
     7 {
       
     8     return::getch ();
       
     9 }
       
    10 #else
       
    11 #include <termios.h>
     3 int Console::getch ()
    12 int Console::getch ()
     4 {
    13 {
     5     static int ch = -1, fd = 0;
    14     static int ch = -1, fd = 0;
     6     struct termios neu, alt;
    15     struct termios neu, alt;
     7 
    16 
    12     tcsetattr (fd, TCSANOW, &neu);
    21     tcsetattr (fd, TCSANOW, &neu);
    13     ch = getchar ();
    22     ch = getchar ();
    14     tcsetattr (fd, TCSANOW, &alt);
    23     tcsetattr (fd, TCSANOW, &alt);
    15     return ch;
    24     return ch;
    16 }
    25 }
       
    26 #endif
    17 
    27 
    18 void Console::getpass (std::string & password)
    28 void Console::getpass (std::string & password)
    19 {
    29 {
    20     int i = 0;
    30     int i = 0;
    21     int c;
    31     int c;
    22     char buffer[17];
    32     char buffer[17];
    23 
    33 
    24     while ((c = getch ()) != '\n' && i < 17) {
    34     while ((c = Console::getch ()) != '\n' && i < 17) {
    25         buffer[i++] = c;
    35         buffer[i++] = c;
    26         std::cout << "*";
    36         std::cout << "\b*";
    27     }
    37     }
    28     buffer[i] = 0;
    38     buffer[i] = 0;
    29 
    39 
    30     password = std::string (buffer);
    40     password = std::string (buffer);
    31     std::cout << std::endl;
    41     std::cout << std::endl;